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!

Debenu Quick PDF Library - PDF SDK Community Forum Homepage
Forum Home Forum Home > For Users of the Library > Sample Code
  New Posts New Posts RSS Feed - Drawing Page numbers onto PDF document
  FAQ FAQ  Forum Search   Register Register  Login Login

Drawing Page numbers onto PDF document

 Post Reply Post Reply
Author
Message
Ingo View Drop Down
Moderator Group
Moderator Group
Avatar

Joined: 29 Oct 05
Status: Offline
Points: 3100
Post Options Post Options   Thanks (0) Thanks(0)   Quote Ingo Quote  Post ReplyReply Direct Link To This Post Topic: Drawing Page numbers onto PDF document
    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;
        }
Back to Top
brettb View Drop Down
Beginner
Beginner


Joined: 07 May 14
Status: Offline
Points: 1
Post Options Post Options   Thanks (0) Thanks(0)   Quote brettb Quote  Post ReplyReply Direct Link To This Post Posted: 07 May 14 at 5:50AM
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
Back to Top
GMahler View Drop Down
Beginner
Beginner


Joined: 19 Dec 15
Location: Germany
Status: Offline
Points: 4
Post Options Post Options   Thanks (0) Thanks(0)   Quote GMahler Quote  Post ReplyReply Direct Link To This Post Posted: 06 Jan 16 at 2:57PM
Ingo, thank you to you and KerryWales! Your example was very helpful to me as well... Thumbs Up
Back to Top
 Post Reply Post Reply
  Share Topic   

Forum Jump Forum Permissions View Drop Down

Forum Software by Web Wiz Forums® version 11.01
Copyright ©2001-2014 Web Wiz Ltd.

Copyright © 2017 Debenu. Debenu Quick PDF Library is a PDF SDK. All rights reserved. AboutContactBlogSupportOnline Store