Print Page | Close Window

add page numbers to existing PDF

Printed From: Debenu Quick PDF Library - PDF SDK Community Forum
Category: For Users of the Library
Forum Name: I need help - I can help
Forum Description: Problems and solutions while programming with the Debenu Quick PDF Library and Debenu PDF Viewer SDK
URL: http://www.quickpdf.org/forum/forum_posts.asp?TID=2096
Printed Date: 30 Jan 26 at 9:10AM
Software Version: Web Wiz Forums 11.01 - http://www.webwizforums.com


Topic: add page numbers to existing PDF
Posted By: jon_bondy
Subject: add page numbers to existing PDF
Date Posted: 10 Jan 12 at 10:16PM
The documentation for this product is simply amazing, but I find myself unable to do the simple things!  I want to open an existing PDF and write page numbers on each page.  Is there an example showing how to access the pages in a PDF after it is opened?

Thank you!
 
Jon



Replies:
Posted By: Ingo
Date Posted: 10 Jan 12 at 10:54PM
Hi Jon!

Use the search function on the top right:
http://www.quickpdf.org/forum/delete-object_topic2025_post8611.html?KW=page+numbers#8611
Check the draw-functionalities in the online reference.
There's not a ready made function doing this.
Check the page dimensions.
Check the length of your page number string.
Don't forget to use SetOrigin.
Do some calculations where start drawing.
Set font, height,  colour ...
Paint the top or bottom area in white to
hide older/other numbers you don't want.
Draw your page number strings on each page.
This is the sample you can change with less efforts
for your needs:
http://www.quickpdflibrary.com/faq/how-to-add-a-header-comprising-of-a-logo-and-a-passed-text-to-each-page-of-an-exi.php - http://www.quickpdflibrary.com/faq/how-to-add-a-header-comprising-of-a-logo-and-a-passed-text-to-each-page-of-an-exi.php

Cheers and welcome here,
Ingo


Posted By: AndrewC
Date Posted: 11 Jan 12 at 10:42AM
Here is some simple C# code that will add page numbers to each page.  To do this properly you should follow some of Ingo's advice as well.

You can also check the "Quick PDF Library 8 Developer Guide.pdf" file that is installed with QuickPDF.  This has lots of sample code examples.

Another option to learn is to read through the FAQ at  http://www.quickpdflibrary.com/faq/index.php - http://www.quickpdflibrary.com/faq/index.php

QP.LoadFromFile("file.pdf");
int id = QP.AddStandardFont(4);
for (int i=1;i<=QP.PageCount();i++)
{
  QP.SelectPage(i);
  QP.NormalizePage(0);

  QP.SetOrigin(1);

  QP.SelectFont(id);
  QP.SetTextSize(12);

  double ph = QP.PageWidth();
  double pw = QP.PaheHeight();

  QP.DrawText(pw - 30, ph - 20, "Page" +  i.ToString();
}

QP.SaveToFile("newfile.pdf");


Posted By: jon_bondy
Date Posted: 11 Jan 12 at 12:33PM
Andrew - Exactly what I was looking for!

Would it also work if the fonts were selected and sized outside of the loop, or must this be done on a per-page basis?  In my code I set the text and fill colors, but those changes never took affect: everything appears in black.


Posted By: AndrewC
Date Posted: 11 Jan 12 at 1:13PM
I believe you need to do this for each page with the drawing commands.

SetTextColor(1,0,0);   //  will set the text color to red.   NOTE : Each colour component has a range of 0.0 to 1.0   and not 0 to 255 like many other libraries.

Andrew.


Posted By: edvoigt
Date Posted: 11 Jan 12 at 1:48PM
Hi,

Andrew is right. If you don't want that your pagenumber is drawn with the last on the page used font, size and color, you should set it inside the loop.

I see no easy way, to embrace the old content of the pages with SaveState and LoadState to prevent your settings for changes.

Werner



Print Page | Close Window

Forum Software by Web Wiz Forums® version 11.01 - http://www.webwizforums.com
Copyright ©2001-2014 Web Wiz Ltd. - http://www.webwiz.co.uk