Print Page | Close Window

Drawing Page numbers onto PDF document

Printed From: Debenu Quick PDF Library - PDF SDK Community Forum
Category: For Users of the Library
Forum Name: General Discussion
Forum Description: Discussion board for Debenu Quick PDF Library and Debenu PDF Viewer SDK
URL: http://www.quickpdf.org/forum/forum_posts.asp?TID=2492
Printed Date: 26 Nov 24 at 8:59AM
Software Version: Web Wiz Forums 11.01 - http://www.webwizforums.com


Topic: Drawing Page numbers onto PDF document
Posted By: kerrywales
Subject: Drawing Page numbers onto PDF document
Date 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;
        }




Replies:
Posted By: kerrywales
Date 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.


Posted By: kerrywales
Date 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.......


Posted By: kerrywales
Date 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;
        }



Posted By: Ingo
Date 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




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