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.

Thu Apr 23, 2020 10:38 am

I want to add text in footer of my PDF.

I have used following code to write text in my PDF.

string path= @"C:\test.pdf";
PdfDocument doc = new PdfDocument();
doc.LoadFromFile(path);

PdfPageBase page = doc.Pages[0];
float x= page.Size.Width ;
float y = page.Size.Height;
PdfTrueTypeFont font = new PdfTrueTypeFont(new Font("Calibri", 10f,FontStyle.Bold));
String ReviewedText = "REVIEWED AND ACCEPTED ON " + DateTime.Today.ToShortDateString();
doc.Pages[0].Canvas.DrawString(ReviewedText, font, PdfBrushes.Red, x-175 , y - 35, format);
doc.SaveToFile(path);

After executing the code when I check the PDF I found that the text is written upside down at the top of the page.
Kindly suggest the solution to write text in the footer of PDF.
Thanks in advance.

dipti515
 
Posts: 8
Joined: Thu Apr 23, 2020 10:23 am

Fri Apr 24, 2020 2:47 am

Hello,

Thanks for your inquiry.
I tested your code with the latest Spire.PDF Pack(Hot Fix) Version:6.4.11, but found the footer was correctly added to the bottom of the page. To help us investigate your issue more accurately, please provide your input file along with your expected output for our reference. You could upload here or send them to us([email protected]) via email.

Besides, on how to add footer to an existing PDF, you could refer to this article: Add Footer to Existing PDF in C#, VB.NET.

Sincerely,
Rachel
E-iceblue support team
User avatar

rachel.lei
 
Posts: 1571
Joined: Tue Jul 09, 2019 2:22 am

Fri Apr 24, 2020 11:51 am

I had mailed the PDF on [email protected].
Kindly check.

Thanks and Regards
Dipti K

dipti515
 
Posts: 8
Joined: Thu Apr 23, 2020 10:23 am

Sun Apr 26, 2020 2:04 am

Hello,

Thanks for your sharing.
After further investigate, I found that the page of your file has been rotated 180 degrees, so using your code, text would be written upside down at the top of the page. To achieve the effect you want, please refer to the following modified code. If there is any question, please feel free to write back.
Code: Select all
    string path = "Y Strainer - Sungove.pdf";
    PdfDocument doc = new PdfDocument();
    doc.LoadFromFile(path);

    PdfPageBase page = doc.Pages[0];
    float x = page.Size.Width;
    float y = page.Size.Height;
    PdfTrueTypeFont font = new PdfTrueTypeFont(new Font("Calibri", 10f, FontStyle.Bold));
    String ReviewedText = "REVIEWED AND ACCEPTED ON " + DateTime.Today.ToShortDateString();
    if (page.Rotation == PdfPageRotateAngle.RotateAngle180)
    {
        x = 25;
        y = 25;
        SizeF size = font.MeasureString(ReviewedText);
        page.Canvas.TranslateTransform(size.Width + 50, 50);
        page.Canvas.RotateTransform(180);
        page.Canvas.DrawString(ReviewedText, font, PdfBrushes.Red, x, y);
    }
    else
    {
        page.Canvas.DrawString(ReviewedText, font, PdfBrushes.Red, x - 175, y - 35);
    }         
    doc.SaveToFile("out.pdf");


Sincerely,
Rachel
E-iceblue support team
User avatar

rachel.lei
 
Posts: 1571
Joined: Tue Jul 09, 2019 2:22 am

Return to Spire.PDF

cron