Page Numbers

Page Numbers

Forum member · Feb 23, 2007
MyDocument.Append(strExportFile1, MergeOptions.All) MyDocument.Outlines.Add(File1, New ZoomDestination(pcount + 1, PageZoom.FitPage)) I use this code. How do I add page nos to this.

Re: Page Numbers

Forum member · Feb 23, 2007
Just to clarify more here is the code... Dim MyDocument As MergeDocument Dim options As MergeOptions = New MergeOptions(False) If firstFile = 1 Then pcount = MyDocument.Pages.Count If report_id = 91 Then MyDocument.Template.Elements.Add(New PageNumberingLabel( _ "%%PR%%%%SP%% of %%ST%%", 300, 980, 512, 12, Font.Helvetica, _ 12, TextAlign.Center)) MyDocument.Sections.Begin(NumberingStyle.Numeric) End If MyDocument.Append(strExportFile1, MergeOptions.All) MyDocument.Outlines.Add(File1, New ZoomDestination(pcount + 1, PageZoom.FitPage)) Else firstFile = 1 MyDocument = New MergeDocument(strExportFile1, MergeOptions.All) MyDocument.Outlines.Add(File1, New ZoomDestination(1, PageZoom.FitPage)) End If Basically it first adds the cover page in the else part then next time around it goes and merge the remaining document. This works correctly be creating a single pdf document with bookmarks. Part that is not working is the part where it inserts the page nos. Also Mydocument is declare globally.

Re: Page Numbers

Support · Feb 23, 2007
There are two major flaws in your provided logic. First, you are adding the Template (containing the PageNumberingLabel) to your MyDocument object which is actually adding that Template to every page in that document regardless of any sections that you may have defined. You need to instead start a section of the document and then add the Template (containing the PageNumberingLabel) only to that section (and not the entire document). With simplified logic here is an example of what you will really need to do: Dim MyDocument As MergeDocument = New MergeDocument() MyDocument.Append(MapPath("../PDFs/DocumentA.pdf")) Dim MyTemplate As Template = New Template() MyTemplate.Elements.Add(New PageNumberingLabel("%%SP%% of %%ST%%", 0, 0, 100, 12)) MyDocument.Sections.Begin(MyTemplate) MyDocument.Append(MapPath("../PDFs/DocumentA.pdf")) MyDocument.DrawToWeb() So you see you will create your document and append any pages you don't want to have the page numbers, then create a template, populate that template and add that template to a new section. Then any pages you append at that point will contain the provided template. You can actually create as many sections as you would like within a document by following this same procedure. The second problem with your code is that the placement of your PageNumberingLabel is likely not in a visible location on your page (unless you have a very large page). For now just use some very obvious values (maybe 0, 0, 100, 12 for the X, Y, Width and Height respectively) just to see if it is appearing. The problem was that you were specifying a Y value of 300 and a width of 512 with a center justification so your label was being centered between 300 and 812 which maybe extending beyond the right side of your page. Anyway just make sure you are using appropriate values in the PageNumberingLabel constructor. Thanks, ceTe Software Support Team

Re: Page Numbers

Forum member · Feb 26, 2007
I used your code. Thanks. But I don't still see the page no's. Where should they be on the page

Re: Page Numbers

Support · Feb 26, 2007
Hello, For the above x, y dimensions of the PageNumberingLabel the page numbers will be visible at the top left corner of the page. But the page numbers are not visible for all the pages of the output document, it will be visible to the section where the template is added. Thanks, ceTe Software Support Team.

Re: Page Numbers

Forum member · Feb 26, 2007
I have a logo in that corner. How can I get at the right hand bottom corner

Re: Page Numbers

Support · Feb 26, 2007
Hello, In order to get the page numbers at bottom right corner you will have to set the corresponding x, y coordinates. For example you can set x,y to page width-100, and page height-50 respectively. It depends on your page size. You can know the exact coordinates by placing a LayoutGrid page element on the page also. Thanks, ceTe Software Support Team.

Re: Page Numbers

Forum member · Feb 26, 2007
My paper size is 8 1/2 X 11. Portriat. I am still not able to see the page nos

Re: Page Numbers

Support · Feb 26, 2007
An 8 1/2 X 11 page is 612 points X 792 points (72 points per inch). Next you need to take into account the margins. By default the margins are set to 50 all the way around the page (top, bottom, left and right). So you now know that the amount of space you will be working with is 512 (page width - left margin - right margin) by 692 (page height - top margin - bottom margin). So now you know that the top left corner of the page (inside the margins) is at 0, 0 and the bottom right corner of the page (inside the margins) is at 512, 692. So the rest of the calculation can easily be done by you depending on where you want the label to appear. If you want the label at about the bottom of the page you know the Y coordinate should be around 692 and if you want the label towards the right side of the page (depending on the width of your label) you may place it at about 470 for the X coordinate. And this is the way that the X, Y point coordinates work for the entire API. Thanks, ceTe Software Support Team

Re: Page Numbers

Forum member · Feb 26, 2007
This is my modifed code I am still not seeing the page nos. If firstFile = 1 Then pcount = MyDocument.Pages.Count If report_id = 91 Then Dim MyTemplate As Template = New Template MyTemplate.Elements.Add(New PageNumberingLabel("%%SP%% of %%ST%%", 470, 692, 100, 12)) MyDocument.Sections.Begin(MyTemplate) MyDocument.Append(MapPath(strExportFile1)) Else MyDocument.Append(strExportFile1, MergeOptions.All) End If MyDocument.Outlines.Add(File1, New ZoomDestination(pcount + 1, PageZoom.FitPage)) Else firstFile = 1 MyDocument = New MergeDocument(strExportFile1, MergeOptions.All) MyDocument.Outlines.Add(File1, New ZoomDestination(1, PageZoom.FitPage)) End If

Re: Page Numbers

Support · Feb 26, 2007
Please go through your code and make sure that your logic is correct (i.e. are you making it into the correct If statements when you should be). If you logic seems correct then maybe try to place the PageNumberingLabel directly to the page (without the template) just to make sure that the label is appearing and appearing in the correct place. Your x and Y coordinates look to be about correct for the bottom right corner of an 8 1/2 x 11 page that I tested here. Other than that there has to be something simple that you are overlooking in your code. Thanks, ceTe Software Support Team

Re: Page Numbers

Forum member · Feb 27, 2007
Thanks for all your help. You are right it wasn't executing that part of the code. Once I fixed it It works. Thanks again

Re: Page Numbers

Forum member · Apr 18, 2007
I have another issue related to the same. The pages that are merged are either Landscape or Potrait. How can I do this to have page no location calculated at runtime on page size. MyTemplate.Elements.Add(New PageNumberingLabel("%%SP%% of %%ST%%", 300, 750, 100, 10)) i.e how do I select 300 and 750 depending on the page size. this setting works fine for Potrait but doesn't work fine for landscape.

Re: Page Numbers

Support · Apr 18, 2007
Hello, You will have to write some logic to check the width and height of the page and then check if width is greater than height. If width is greater, then the page is landscape and you can set the X and Y coordinate of the page numbering label accordingly and vice versa. Thanks, ceTe Software Support Team

Re: Page Numbers

Forum member · Apr 18, 2007
ok here is my code how do I do the calculation of the Mydocument papersize in this code MyTemplate.Elements.Add(New PageNumberingLabel("%%SP%% of %%ST%%", 300, 750, 100, 10)) MyDocument.Sections.Begin(MyTemplate) MyDocument.Append(<filename>, MergeOptions.All)

Re: Page Numbers

Support · Apr 19, 2007
Hello, You can get the height and width of an existing page by using the Height and Width properties of the Dimensions class. Following is the sample code to get the height and width of a page. float height = MyDocument.Pages[1].Dimensions.Height; float width = MyDocument.Pages[1].Dimensions.Width; You can compare this width and height to know whether the page is in portrait or landscape. If the width is more then it is said to be in landscape. According to this you can set the X, Y for the page numbering label. Thanks, ceTe Software Support Team.

Re: Page Numbers

Forum member · Apr 23, 2007
the numbering template is added before the document is merged. ie something like this MyTemplate.Elements.Add(New PageNumberingLabel("%%SP%% of %%ST%%", xpos, ypos, 100, 10)) MyDocument.Sections.Begin(MyTemplate) MyDocument.Append(strExportFile1, MergeOptions.All) how would I know the dimentions before I merge?

Re: Page Numbers

Support · Apr 24, 2007
Hello, You will have to create a PdfDocument object of the PDF you are going to append to know the dimensions of the pages before appending. You can use this PdfDocument object in the Append method as a parameter. Following is the sample code for this. PdfDocument pdfDoc = new PdfDocument(@"C:\Temp\DocA.pdf"); float h = pdfDoc.Pages[0].GetDimensions().Height; float w = pdfDoc.Pages[0].GetDimensions().Width; You can use this PdfDoc object to append with the main document. MyDocument.Append(pdfDoc, MergeOptions.All) Thanks, ceTe Software Support Team.

Re: Page Numbers

Forum member · Apr 24, 2007
how do I apply the numbering template. Because it is done at the begining. MyTemplate.Elements.Add(New PageNumberingLabel("%%SP%% of %%ST%%", xpos, ypos, 100, 10)) MyDocument.Sections.Begin(MyTemplate)

Re: Page Numbers

Support · Apr 24, 2007
Hello, You will have to know the dimensions of the page which you are adding to the main PDF before creating the PageNumberingLabel. In your case it would be better if you add the page numbering label without using the template. You will have to keep track of the page number you currently on and the number of pages you are appending to the main PDF. Loop through the pages you added newly to the main document and add the page numbering label to each page and here you can reset the x and y of the page numbering label depending on the dimensions of the pages. Thanks, ceTe Software Support Team.

Re: Page Numbers

Forum member · May 1, 2007
I have gone to circles to place a page no without a template. Could you please give me an example with code that shows how to merge 2 documents. One landscape and one potrait and place the page nos at bottom center.

Re: Page Numbers

Support · May 1, 2007
Hello, Following is the sample code that shows how to add page numbering label to the bottom center of the output PDF document: MergeDocument document = new MergeDocument(); document.Pages.Add(new Page(PageSize.A4, PageOrientation.Portrait,.54f)); document.Pages.Add(new Page(PageSize.A4, PageOrientation.Landscape,.54f)); for( int i = 0; i< document.Pages.Count; i++) { AnchorGroup group = new AnchorGroup(document.Pages[i].Dimensions.Width, 12, Align.Center, VAlign.Bottom); group.AnchorTo = AnchorTo.Margins; PageNumberingLabel label = new PageNumberingLabel("%%CP%% of %%TP%%", 0, 0, document.Pages[i].Dimensions.Width, 12, Font.Helvetica, 12, TextAlign.Center ); group.Add(label); document.Pages[i].Elements.Add(group); } document.DrawToWeb("Test.pdf"); Thanks, ceTe Software Support Team

Re: Page Numbers

Forum member · May 1, 2007
thanks. do you have a example in VB.net I am using vb and not C#

Re: Page Numbers

Support · May 1, 2007
Hello, Here is the VB.NET version of the code: Dim MyDocument As MergeDocument = New MergeDocument MyDocument.Pages.Add(New Page(PageSize.A4, PageOrientation.Portrait, 0.54D)) MyDocument.Pages.Add(New Page(PageSize.A4, PageOrientation.Landscape, 0.54D)) Dim i As Integer For i = 0 To MyDocument.Pages.Count - 1 Step i + 1 Dim MyGroup As AnchorGroup = New AnchorGroup(MyDocument.Pages(i).Dimensions.Width, 12, Align.Center, VAlign.Bottom) MyGroup.AnchorTo = AnchorTo.Margins Dim MyLabel As PageNumberingLabel = New PageNumberingLabel("%%CP%% of %%TP%%", 0, 0, MyDocument.Pages(i).Dimensions.Width, 12, Font.Helvetica, 12, TextAlign.Center) MyGroup.Add(MyLabel) MyDocument.Pages(i).Elements.Add(MyGroup) Next MyDocument.DrawToWeb("Test.pdf") Thanks, ceTe Software Support Team

Re: Page Numbers

Forum member · May 1, 2007
Thanks a lot how can I give space between the page label and bottom margin. The label is very close to the bottom margin

Re: Page Numbers

Support · May 1, 2007
Hello, Remove the margins that are specified in the constructor when adding the new page and let it use the default margins. For e.g.: MyDocument.Pages.Add(New Page(PageSize.A4, PageOrientation.Portrait)) Thanks, ceTe Software Support Team

Re: Page Numbers

Forum member · May 1, 2007
I don't have any margins set this is my code MyDocument.Append(pdfDoc, MergeOptions.All) MyDocument = New MergeDocument options.PageAnnotations = True MyDocument.Append(pdfDoc, MergeOptions.All) pcount = MyDocument.Pages.Count MyDocument.Outlines.Add(File1, New ZoomDestination(pcount + 1, PageZoom.FitPage)) pdfDoc = New PdfDocument("c:\tcomreports\trade_summary132.pdf") MyDocument.Append(pdfDoc, MergeOptions.All) For i = 0 To MyDocument.Pages.Count - 1 Dim group = New AnchorGroup(MyDocument.Pages(i).Dimensions.Width, 12, Align.Center, VAlign.Bottom) group.AnchorTo = AnchorTo.Margins 'MyGroup.Add(New AnchorGroup(MyDocument.Pages(i).Dimensions.Width, 12, Align.Center, VAlign.Bottom)) label = New PageNumberingLabel("%%CP%% of %%TP%%", 0, 0, MyDocument.Pages(i).Dimensions.Width, 12, Font.Helvetica, 12, TextAlign.Center) group.Add(label) MyDocument.Pages(i).Elements.Add(group) Next

Re: Page Numbers

Support · May 1, 2007
Hello, We will have to look at the PDF file you are merging. Can you please send it over to our [^a|mailto:support@cete.com|Support Team^] and they can take a look at it? Thanks, ceTe Software Support Team

Re: Page Numbers

Forum member · May 1, 2007
I just emailed the files to support team

Re: Page Numbers

Support · May 1, 2007
The reason you are seeing the page numbering label (part of the anchor group) at the very bottom of the page is because there are no margins set on the documents that you are merging in. Therefore anchoring to the edge or anchoring to the Margins yields the same result. If you want to anchor to a certain margin then you should set the margins to that value first (for each page) and then the anchor group will anchor on that value. You may want to try some code like this: Dim MyDocument As MergeDocument = New MergeDocument("C:\temp\132.pdf") MyDocument.Append("C:\temp\32.pdf") Dim i As Integer For i = 0 To MyDocument.Pages.Count - 1 MyDocument.Pages(i).Dimensions.SetMargins(27) Next Dim MyTemplate As Template = New Template() Dim MyGroup = New AnchorGroup(100, 12, Align.Center, VAlign.Bottom) MyGroup.AnchorTo = AnchorTo.Margins MyGroup.Add(New PageNumberingLabel("%%CP%% of %%TP%%", 0, 0, 100, 12, Font.Helvetica, 12, TextAlign.Center)) MyTemplate.Elements.Add(MyGroup) MyDocument.Template = MyTemplate MyDocument.DrawToWeb("MergePDFs.pdf") Visible = False Thanks, ceTe Software Support Team

Re: Page Numbers

Forum member · May 2, 2007
Thanks for all your help. That worked.