I am using FreeSpirePDF 8.6.0 on my sample project. I am trying to edit existing pdf file and update its pagination and then save changes into different file.
But it seems doesn't work. There was no error, nor the pagination i intended to add successfully added.
Here is my code.
- Code: Select all
using System;
using System.Drawing;
using Spire.Pdf;
using Spire.Pdf.AutomaticFields;
using Spire.Pdf.Graphics;
namespace ConsoleApp1
{
class Program
{
static void Main(string[] args)
{
PdfDocument pdf = new PdfDocument();
pdf.LoadFromFile(@"c:\sample.pdf");
PdfTrueTypeFont font = new PdfTrueTypeFont(new Font("Arial", 10f, FontStyle.Regular), true);
PdfPageNumberField pageNumber = new PdfPageNumberField();
PdfPageCountField pageCount = new PdfPageCountField();
PdfCompositeField compositeField = new PdfCompositeField(font, PdfBrushes.Black, "Page {0} of {1}", pageNumber, pageCount);
compositeField.StringFormat = new PdfStringFormat(PdfTextAlignment.Left, PdfVerticalAlignment.Top);
for (int i = 0; i < pdf.Pages.Count; i++)
{
compositeField.Draw(pdf.Pages[i].Canvas, pdf.Pages[i].Size.Width / 2 - 20, pdf.Pages[i].Size.Height - pdf.PageSettings.Margins.Bottom);
}
pdf.SaveToFile(@"c:\result.pdf");
}
}
}
regards,
John