Add page number to pdf  SOLVED

PDF-XChange Editor SDK for Developers

Moderators: Daniel - PDF-XChange, PDF-XChange Support, Vasyl - PDF-XChange, Chris - PDF-XChange, Sean - PDF-XChange, Paul - PDF-XChange, Ivan - Tracker Software, Stefan - PDF-XChange

Forum rules
DO NOT post your license/serial key, or your activation code - these forums, and all posts within, are public and we will be forced to immediately deactivate your license.

When experiencing some errors, use the IAUX_Inst::FormatHRESULT method to see their description and include it in your post along with the error code.
kyo
User
Posts: 130
Joined: Mon Oct 31, 2016 11:58 am

Add page number to pdf

Post by kyo »

Dear All,
I have a requirement that I need to add page number to the header or footer.
I have already searched in the forum and the online help ,but only find the operation id "op.document.pageNumbering" which seems to be what I need.

Below is my sample code using operation id "op.document.pageNumbering",which runs well but does not have any impact on the pdf file at all.

Code: Select all

   private void AddPageNumbering(PDFXEdit.IPXV_Document Doc, PDFXEdit.PXV_Inst Inst)
        {
            int nID = Inst.Str2ID("op.document.pageNumbering", false);
            PDFXEdit.IOperation op = Inst.CreateOp(nID);

            PDFXEdit.ICabNode input = op.Params.Root["Input"];
            input.v = Doc.CoreDoc;
            PDFXEdit.ICabNode options = op.Params.Root["Options"];
            options["ForceLoadFromOptions"].v = true;
            PDFXEdit.ICabNode PDFRangeItems = options["PDFRangeItems"];
            PDFXEdit.ICabNode item = PDFRangeItems.Add();
            item["StartPage"].v = 1;
            item["Style"].v = 1;//decimal
            item["StartNum"].v = 2;

            op.Do();


        }
Is there something wrong with this method? or this method can not implement my requirement at all ,and i should use other methods.

I hope you can help me.I would like to emphasize once more that I need to add the page number to the header(leftheader/centerheader/rightheader) or the footer(leftfooter/centerfooter/rightfooter)

Any help would be appreciated.
Look forward to your reply.
Thanks in advance.
kyo
User
Posts: 130
Joined: Mon Oct 31, 2016 11:58 am

Re: Add page number to pdf

Post by kyo »

Now, I find an interface IPXC_HeaderAndFooterParams which is likely to implement my requirment.

If yes,can you give me some sample code about how to set the page number format .
Sasha - PDF-XChange
User
Posts: 5522
Joined: Fri Nov 21, 2014 8:27 am

Re: Add page number to pdf

Post by Sasha - PDF-XChange »

Hello kyo,

Sure, but please use the search first - here's my results:
https://forum.pdf-xchange.com/ ... oterParams

Cheers,
Alex
Subscribe at:
https://www.youtube.com/channel/UC-TwAMNi1haxJ1FX3LvB4CQ
kyo
User
Posts: 130
Joined: Mon Oct 31, 2016 11:58 am

Re: Add page number to pdf

Post by kyo »

I have read the sample code you suggest.The sample code only demonstrate how to add static text for footer/header that is not what I want.I want to add page number ,which vary every page to pdf.

Can you give me some sample code that demonstrate how to add page number to pdf including setting the page number format,start page ,end page etc?
Sasha - PDF-XChange
User
Posts: 5522
Joined: Fri Nov 21, 2014 8:27 am

Re: Add page number to pdf

Post by Sasha - PDF-XChange »

You mean you want to add the page label? Have you tried using the Document\Number Pages... feature in the end-user Editor - is this what you want?

Cheers,
Alex
Subscribe at:
https://www.youtube.com/channel/UC-TwAMNi1haxJ1FX3LvB4CQ
kyo
User
Posts: 130
Joined: Mon Oct 31, 2016 11:58 am

Re: Add page number to pdf

Post by kyo »

Hello,
Yes,what I want is something like the Bates number.And the page number is different from bates number.
I want the page number always starting with 1,but the bates number may not.

Do you get my requirement?
For example,I want to add page number to every page at the header/footer as a label with the format( e.g. 1 of 10) .

Can I do this by setting some property of IPXC_HeaderAndFooterParams?
kyo
User
Posts: 130
Joined: Mon Oct 31, 2016 11:58 am

Re: Add page number to pdf

Post by kyo »

You mean you want to add the page label? Have you tried using the Document\Number Pages... feature in the end-user Editor - is this what you want?
Before I ask for help here,I have ever used the the funciton Document\Number Pages that is not what I want.Because ,actually it does not add the page number to the phisical pdf file, and it just add them to the navigation of thumbnail as a logcal page number.
Sasha - PDF-XChange
User
Posts: 5522
Joined: Fri Nov 21, 2014 8:27 am

Re: Add page number to pdf

Post by Sasha - PDF-XChange »

Hello kyo,

Well you can set the text of the headers or footers as <<1 of n>> (as the End-User Editor does) and then this macro will be interpreted as the page numeration.

Cheers,
Alex
Subscribe at:
https://www.youtube.com/channel/UC-TwAMNi1haxJ1FX3LvB4CQ
kyo
User
Posts: 130
Joined: Mon Oct 31, 2016 11:58 am

Re: Add page number to pdf

Post by kyo »

Hello,
I have done what you told me,but I encounter some issues.And I have uploaded some screenshots to demonstrate the issues.
Here is my sample code:

Code: Select all

PDFXEdit.IPXC_Document doc = pdfCtl.Doc.CoreDoc;
            PDFXEdit.IPXC_Inst Inst = (PDFXEdit.IPXC_Inst)pdfCtl.Inst.GetExtension("PXC");

            PDFXEdit.IAUX_Inst aInst = (PDFXEdit.IAUX_Inst)Inst.GetExtension("AUX");
            PDFXEdit.IBitSet bs = aInst.CreateBitSet(doc.Pages.Count);

            PDFXEdit.IPXC_HeaderAndFooterParams wp = Inst.CreateHeaderAndFooterParams();
            bs.Set(0, 4);

            wp.FontSize = 32;

            wp.LeftHeaderText = "<<1 of n>>";
            wp.RightHeaderText = "";
            wp.CenterHeaderText = "";

            wp.LeftFooterText = "";
            wp.RightFooterText = "";
            wp.CenterFooterText = "";

            wp.FillColor = aInst.CreateColor(PDFXEdit.ColorType.ColorType_RGB);
            wp.FillColor.SetRGB(0, 0, 0);

            wp.BottomMargin = 50;
            wp.LeftMargin = 5;
            wp.RightMargin = 5;
            wp.TopMargin = 5;

            doc.PlaceHeadersAndFooters(bs, wp);
The issue is that I set the text of Header/Footer to "<<1 of n>>" as the End-User Editor does,but the text "<<1 of n>>" is not interperted as page numeration at all.In contrast,this work fine with End-User Editor.

Another similar issue,when I set the text of Header/Footer to "<<Bates Number#3#1>>" as the End-User Editor does,although the text "<<Bates Number#3#1>>" is interpreted,every page has the same page numberation(e.g. 001) that is not reasonable.

Is this a bug or something wrong with my sample code? I hope you can try my sample code,and give me your result.
I look forward to your quick reply.
Thanks in advance.
You do not have the required permissions to view the files attached to this post.
Sasha - PDF-XChange
User
Posts: 5522
Joined: Fri Nov 21, 2014 8:27 am

Re: Add page number to pdf  SOLVED

Post by Sasha - PDF-XChange »

Subscribe at:
https://www.youtube.com/channel/UC-TwAMNi1haxJ1FX3LvB4CQ
kyo
User
Posts: 130
Joined: Mon Oct 31, 2016 11:58 am

Re: Add page number to pdf

Post by kyo »

Yes,It is fine now.
I do as you told me,and now I can add page number and bates number as I want.
Thank you very much.
Sasha - PDF-XChange
User
Posts: 5522
Joined: Fri Nov 21, 2014 8:27 am

Re: Add page number to pdf

Post by Sasha - PDF-XChange »

:)
Subscribe at:
https://www.youtube.com/channel/UC-TwAMNi1haxJ1FX3LvB4CQ