I have a process where I perform the following steps:
1. Create a new blank PDF Document
2. Add a cover page to that document (with various labels)
3. Add a blank page for duplex printing so first page doesn't appear on the back of the cover page.
4. Write that file to a PDF using the .Draw method
5. Create a new MergeDocument from that file using a filestream
6. Using that MergeDocument, I loop through repeatedly and merge in other existing PDFs using the .Append method.
7. After merging in the PDF in step #6, I look to see if the appended PDF had an odd number of pages. If so, I add a new blank page, once again so that the next appended doc doesn't start on the back of an existing doc (duplex printing). Basically, so all merged PDFs start on the front of their own page and not the back of another PDF.
PROBLEM: In this process, I'm applying a PageNumberingLabel via a Document Template so that each page has Page X of Y on the bottom. Everything works as expected, except the blank pages that I add in step #7 do not get the PageNumberlingLabel. Only the imported/appended existing PDFs get the PageNumberingLabel.
Here is my existing code:
//Create Base Document
_document = new ceTe.DynamicPDF.Document();
//Create Cover page
ceTe.DynamicPDF.Page page = new ceTe.DynamicPDF.Page(PageSize.Letter, PageOrientation.Landscape, 54.0f);
//Add cover page to base document
_document.Pages.Add(page);
//Add blank page for back of cover page (duplex printing)
ceTe.DynamicPDF.Page blankpage = new ceTe.DynamicPDF.Page(PageSize.Letter, PageOrientation.Landscape, 54.0f);
_document.Pages.Add(blankpage);
//Write out the new file
_document.Draw(fileName);
//Create filestream of PDF just created
FileStream fs = new FileStream(fileName, FileMode.Open);
byte[] contents = new byte[fs.Length];
fs.Read(contents, 0, (int)fs.Length);
fs.Close();
//Create PDFDocument Object from Filestream
ceTe.DynamicPDF.Merger.PdfDocument pdf = new ceTe.DynamicPDF.Merger.PdfDocument(contents);
//Create a Merge Doc
_mergeDoc = new MergeDocument();
//Create Template for page numbering
Template documentTemplate = new Template();
PageNumberingLabel pageNumberingLabel = new PageNumberingLabel("Page %%CP%% of %%TP%%", 650, 578, 100, 18, ceTe.DynamicPDF.Font.Helvetica, 8, ceTe.DynamicPDF.TextAlign.Right, RgbColor.Black);
pageNumberingLabel.PageOffset = -2;
documentTemplate.Elements.Add(pageNumberingLabel);
_mergeDoc.StampTemplate = documentTemplate;
_mergeDoc.Sections.Begin(documentTemplate);
//Add filestream PDF Document to Merge Doc
_mergeDoc.Append(pdf);
//Don't put page numbering on first two pages (cover page)
_mergeDoc.Pages[0].ApplyDocumentTemplate = false;
_mergeDoc.Pages[1].ApplyDocumentTemplate = false;
//Append existing PDFs to Merge Doc; this is actually part of a loop that occurs over and over
ceTe.DynamicPDF.Merger.PdfDocument x = new PdfDocument("c:\x.pdf");
_mergeDoc.Append(x);
//If pagecount is an odd number, add a page for duplex printing
if ((docPageCount & 1) == 1)
{
ceTe.DynamicPDF.Page blankpage = new ceTe.DynamicPDF.Page(PageSize.Letter, PageOrientation.Landscape, 54.0f);
_mergeDoc.Pages.Add(blankpage); <--This page doesn't have the PageNumberingLabel on it
}
PageNumberingLabel not showing up on all pages
Re: PageNumberingLabel not showing up on all pages
Support · Apr 17, 2007Hello,
The likely reason you are not seeing the PageNumberinglabel on the added pages is because you are adding the Page with landscape orientation. So its height and width will be 612 points x 792 points respectively. In the page constructor, you are setting the page margins to be 54 points, so all four sides will have those margins. You are adding the PageNumberinglabel with X coordinate 650 which is way beyond the height of the page and that’s the reason you are not seeing it.
Thanks,
ceTe Software Support Team
Re: PageNumberingLabel not showing up on all pages
Forum member · Apr 17, 2007Thanks. Changing the default margin from 54 to 5 seemed to solve the problem.