Spire.PDF is a professional PDF library applied to creating, writing, editing, handling and reading PDF files without any external dependencies. Get free and professional technical support for Spire.PDF for .NET, Java, Android, C++, Python.

Tue Feb 28, 2023 7:50 am

Hi Dear,

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

johnhadikusumo
 
Posts: 4
Joined: Mon Feb 20, 2023 10:47 pm

Wed Mar 01, 2023 10:12 am

Hi,

Thanks for your inquiry.
Please try to adjust the position where you draw the page number, the position can be influenced by many factors, for example, the margins and page rotation. If your issue still exists after testing, please provide us with your document to help us work out a solution for you. You can send it to us via email (support@e-iceblue.com) or attach them here. Thanks for your assistance.

Sincerely,
Triste
E-iceblue support team
User avatar

Triste.Dai
 
Posts: 1000
Joined: Tue Nov 15, 2022 3:59 am

Return to Spire.PDF