Do you own a Debenu Quick PDF Library version 7, 8, 9, 10, 11, 12, 13 or iSEDQuickPDF license? Upgrade to Debenu Quick PDF Library 14 today!
Drawing Page numbers onto PDF document |
Post Reply |
Author | |
Ingo
Moderator Group Joined: 29 Oct 05 Status: Offline Points: 3524 |
Post Options
Thanks(0)
Posted: 18 Jan 13 at 5:52PM |
A sample using/doing pagenumbering with QuickPDF made by our user KerryWales:
public bool RenumberPages(string filename, int startNumber, string outfile, int position, double xOffset, double yOffset) { //offset in points 1/72 of inch //always measurement to nearest edge //position // 0 = bottom left // 1 = top left // 2 = top right // 3 = bottom right bool result = false; int pageNo = startNumber; double xPos; double yPos; try { DebenuPDFLibraryLoadFromFile(InstanceID, filename, ""); int id = DebenuPDFLibraryAddStandardFont(InstanceID, 4); DebenuPDFLibrarySelectFont(InstanceID, id); DebenuPDFLibrarySetTextSize(InstanceID, 12); for (int i = 1; i <= DebenuPDFLibraryPageCount(InstanceID); i++) { DebenuPDFLibrarySelectPage(InstanceID, i); DebenuPDFLibrarySetOrigin(InstanceID, 1); DebenuPDFLibrarySetMeasurementUnits(InstanceID, 0); DebenuPDFLibraryNormalizePage(InstanceID, 1); double pw = DebenuPDFLibraryPageWidth(InstanceID); double ph = DebenuPDFLibraryPageHeight(InstanceID); //calc x & y based on where page number wanted switch (position) { case 0: xPos = xOffset; yPos = ph - yOffset; break; case 1: xPos = xOffset; yPos = yOffset; break; case 2: xPos = pw - xOffset; yPos = yOffset; break; default: xPos = pw - xOffset; yPos = ph - yOffset; break; } DebenuPDFLibraryDrawText(InstanceID, xPos, yPos, "[" + pageNo++.ToString() + "]"); } DebenuPDFLibrarySaveToFile(InstanceID, outfile); result = true; } catch { }; return result; } |
|
brettb
Beginner Joined: 07 May 14 Status: Offline Points: 1 |
Post Options
Thanks(0)
|
Thanks - most helpful. Here is a similar version for VBA in case others need it.
' In a module or class Dim qp As DebenuPDFLibraryAX1014.PDFLibrary 'A sample using/doing pagenumbering with QuickPDF made by our user KerryWales: 'offset in points 1/72 of inch 'always measurement to nearest edge 'position ' 0 = bottom left ' 1 = top left ' 2 = top right ' 3 = bottom right Private Sub RenumberPages(filename As String, startNumber As Long, outfile As String, position As Long, xOffset As Double, yOffset As Double) Dim pw As Double, ph As Double Dim pageNo As Long Dim xPos As Double Dim yPos As Double Dim fontID As Long Dim retval As Long Dim i As Long pageNo = startNumber retval = qp.LoadFromFile(filename, "") fontID = qp.AddStandardFont(4) Call qp.SelectFont(fontID) qp.SetTextSize (8) For i = pageNo To qp.PageCount() + pageNo - 1 qp.SelectPage (i) qp.SetOrigin (1) qp.SetMeasurementUnits (0) qp.NormalizePage (1) pw = qp.PageWidth() ph = qp.PageHeight() 'calc x & y based on where page number wanted Select Case (position) Case 0: xPos = xOffset yPos = ph - yOffset Case 1: xPos = xOffset yPos = yOffset Case 2: xPos = pw - xOffset yPos = yOffset Case Else: xPos = pw - xOffset yPos = ph - yOffset End Select qp.SetTransparency (50) Call qp.DrawBox(xPos - 10, yPos - 15, 100, 20, 1) ' 1= fill qp.SetTransparency (0) retval = qp.DrawText(xPos, yPos, "[Credit Page " & Format(i, "000") & "]") If Not retval Then ' error or warning... End If Next retval = qp.SaveToFile(outfile) If Not retval Then ' error or warning... End If End Sub |
|
GMahler
Beginner Joined: 19 Dec 15 Location: Germany Status: Offline Points: 4 |
Post Options
Thanks(0)
|
Ingo, thank you to you and KerryWales! Your example was very helpful to me as well...
|
|
Post Reply | |
Tweet
|
Forum Jump | Forum Permissions You cannot post new topics in this forum You cannot reply to topics in this forum You cannot delete your posts in this forum You cannot edit your posts in this forum You cannot create polls in this forum You cannot vote in polls in this forum |
Copyright © 2017 Debenu. Debenu Quick PDF Library is a PDF SDK. All rights reserved. About — Contact — Blog — Support — Online Store