Hi,
How can I change my code to get a footer that says Page n of total. e.g. Page 1 of 3.
I can't seem to move my last paragraph to the bottom. Unless there is a better way.
Thanks,
Ward
Code:
private void Generate_PDF_Files(int number_of_pages, string output_folder, int sequence_number)
{
string pdf_file_name = string.Format(@"{0}\PDFTest_{1}.pdf", output_folder, sequence_number.ToString("0000"));
Encoding.RegisterProvider(CodePagesEncodingProvider.Instance);
var enc1252 = Encoding.GetEncoding(1252);
// Create a MigraDoc document
Document document = new Document();
// Add a section to the document
Section section = document.AddSection();
for (int page_number=1;page_number<=number_of_pages;page_number++)
{
section.AddPageBreak();
// Add a paragraph to the section
MigraDoc.DocumentObjectModel.Paragraph paragraph = section.AddParagraph();
string message = string.Format("Filename: {0}", System.IO.Path.GetFileName(pdf_file_name));
paragraph.AddFormattedText(message, TextFormat.Bold);
section.AddParagraph();
//MigraDoc.DocumentObjectModel.Shapes.Image img1 = section.AddImage(image_file_path);
//img1.LockAspectRatio = true;
//img1.Width = Unit.FromPoint(500);
//img1.Height = Unit.FromPoint(300);
section.AddParagraph();
//MigraDoc.DocumentObjectModel.Shapes.Image img2 = section.AddImage(image_file_path);
//img2.LockAspectRatio = true;
//img2.Width = Unit.FromPoint(500);
//img2.Height = Unit.FromPoint(300);
paragraph = section.AddParagraph();
paragraph.Format.Alignment = ParagraphAlignment.Center;
message = string.Format("Page {0} of {1}", page_number, number_of_pages);
paragraph.AddFormattedText(message, TextFormat.Bold);
}
const bool unicode = false;
const PdfFontEmbedding embedding = PdfFontEmbedding.Always;
PdfDocumentRenderer pdfRenderer = new PdfDocumentRenderer(unicode, embedding);
pdfRenderer.Document = document;
pdfRenderer.RenderDocument();
pdfRenderer.PdfDocument.Save(pdf_file_name);
}