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 > General Discussion
  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
kerrywales View Drop Down
Beginner
Beginner


Joined: 06 Oct 10
Status: Offline
Points: 5
Post Options Post Options   Thanks (0) Thanks(0)   Quote kerrywales Quote  Post ReplyReply Direct Link To This Post Topic: Drawing Page numbers onto PDF document
    Posted: 18 Jan 13 at 1:04PM
Hi,
I am using DebenuPDFLibraryDLL0911 with c# in vs2010. I have a wrapper class to manipulate documents as I need to including Merging pdf's. All is well.

I decided that it would be good to OVERLAY my own page numbers onto the merged document. I created a function in my class (shown at end).

My problem is that I obviously don't understand the positioning mechanism

My test document is a merge between an A4 landscape PDF and an A4 portrait PDF.
I would like the page number to be 1.5" from the bottom and 1.5" from the right of each page.

I first presumed that working in points I would use the value 108 and deduct that from the page width & page height. Setting the measurements to points so that they are all in the same measurement system.

No errors but no page numbers on the document.

Playing around I noted that using the value 470 I do get page numbers on the document BUT
not in the position I expected to see them. Their approxiamate positions are:
on the landscape pages 4.7cm from left 9.4 cm from bottom
on the portrait pages 11.4 cm from left 6.6 cm from bottom

Can someone explain/tell me what fact(s) I am obviously missing.

Thanks




/////////// My code to add page numbers
public bool RenumberPages(string filename, int startNumber, string outfile)
        {
            bool result = false;
            int pageNo = startNumber;
            try
            {
                DebenuPDFLibraryLoadFromFile(InstanceID, filename, "");

                int id = DebenuPDFLibraryAddStandardFont(InstanceID, 4);
                for (int i = 1; i <= DebenuPDFLibraryPageCount(InstanceID); i++)
                {
                    DebenuPDFLibrarySelectPage(InstanceID, i);
                    DebenuPDFLibraryNormalizePage(InstanceID, 0);

                    DebenuPDFLibrarySetOrigin(InstanceID, 0);
                    DebenuPDFLibrarySetMeasurementUnits(InstanceID,0);

                    DebenuPDFLibrarySelectFont(InstanceID, id);
                    DebenuPDFLibrarySetTextSize(InstanceID, 12);
                   
                    double ph = DebenuPDFLibraryPageWidth(InstanceID);
                    double pw = DebenuPDFLibraryPageHeight(InstanceID);

                    DebenuPDFLibraryDrawText(InstanceID, pw - 470, ph - 470, "[" + pageNo++.ToString() + "]");
                }
                DebenuPDFLibrarySaveToFile(InstanceID, outfile);
                result = true;
            }
            catch { };
       
            return result;
        }

Back to Top
kerrywales View Drop Down
Beginner
Beginner


Joined: 06 Oct 10
Status: Offline
Points: 5
Post Options Post Options   Thanks (0) Thanks(0)   Quote kerrywales Quote  Post ReplyReply Direct Link To This Post Posted: 18 Jan 13 at 1:27PM
OK there is a mistake in the set origin. Should set it from top left if I am subtracting from the page height. Things are still in the wrong place though.
Back to Top
kerrywales View Drop Down
Beginner
Beginner


Joined: 06 Oct 10
Status: Offline
Points: 5
Post Options Post Options   Thanks (0) Thanks(0)   Quote kerrywales Quote  Post ReplyReply Direct Link To This Post Posted: 18 Jan 13 at 1:36PM
Also I claim prat of the year award. Does help if PageWidth is assigned to my pw variable and PageHeight to my ph.
It may still be wrong but at least its logical now.

I'm blaming the snow and making me cold.......
Back to Top
kerrywales View Drop Down
Beginner
Beginner


Joined: 06 Oct 10
Status: Offline
Points: 5
Post Options Post Options   Thanks (0) Thanks(0)   Quote kerrywales Quote  Post ReplyReply Direct Link To This Post Posted: 18 Jan 13 at 2:19PM
My apologies for posting without thinking straight. Well two cups of tea and a 20 minute break means that I am thinking again and just for completeness this is my function in my wrapper class:

As well as giving a starting page number I wanted to set the position of the where the page number was to be printed for that document

So nothing wrong with what I was doing really. Just needed to get brain into gear.


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
Ingo View Drop Down
Moderator Group
Moderator Group
Avatar

Joined: 29 Oct 05
Status: Offline
Points: 3524
Post Options Post Options   Thanks (0) Thanks(0)   Quote Ingo Quote  Post ReplyReply Direct Link To This Post Posted: 18 Jan 13 at 5:53PM
Hi Kerry!

Thanks for the sample.
I've posted it in the samples-section, too ;-)

Cheers and welcome here,
Ingo

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