Hello,
This is both a Generator and Merger question.
I am creating a document via the Generator that has section templates applied to multiple sections. What I am then trying to do is to merge this document (we will call it the "content") with an Introduction PDF and a Back Page PDF as shown below.
MERGE MERGE
Introduction (existing PDF) -> "Content" PDF (generated) -> Back Page PDF.
When I attempt to create a "MergeDocument" with my dynamically generated PDF to merge into the Introduction and Back Pages I lose the templates I have applied to the sections (basically a header and footer for each section). I could not figure out how to merge the document if it was not of type "MergeDocument". The Merger would not allow me to merge an existing PDF with a ceTe.DynamicPDF.Document object returned from my generator functions.
Any ideas how I can accomplish this task? I want to avoid saving my ceTe.DynamicPDF.Document PDF that is returned from my generator functions if at all possible, but I didn't see any overloaded methods for the MergeDocument to use this type of input.
Thank you for your time,
Matt L.
Template Header and Footer Missing!
Re: Template Header and Footer Missing!
Support · Mar 29, 2007Hello Matt,
Yes, the document object can not be merged with the MergeDocument object directly. You can merge a PdfDocument object to the merge document object. You will have to create a PdfDocument object from the document object. You can do this by drawing the PDF to a memory stream or a Byte array using the Draw method of the document which takes the memory stream or Byte array as parameters. You can create a PdfDocument using this memory stream or the Byte array. Following is the sample code for this.
document.draw(stream);
PdfDocument pdfDoc = new PdfDocument(stream);
mergeDocument.Append(pdfDoc);
Thanks,
ceTe Software Support Team.
Re: Template Header and Footer Missing!
Support · Mar 29, 2007Hello Matt,
A more efficient way of doing this would be to start with the Introduction (which is your existing PDF document) using the MergeDocument object. Since MergeDocument inherits from Document object, then append as many pages as you want to the existing MergeDocument object (pages you are generating using generator). Then at the end, append the back page of the PDF. This process will give more efficient results.
Thanks,
ceTe Software Support Team
Re: Template Header and Footer Missing!
Forum member · Mar 29, 2007Hmmm... I tried that yesterday and again today and it merges the documents just fine, however I lose my Header and Footer from the generated pages.
Basically I create an array of pages and loop through the pages and apply a section template to them. Then I assemble the pages into a single generated document and return it, then append it to the mergedocument and write it out.
Here is the code I am using:
// Create the Introduction document object
PdfDocument introductionPDF = new PdfDocument("c:\\inetpub\\wwwroot\\cchpportal\\ProviderDirectoryPDFs\\Introduction.pdf");
PdfDocument pharmacyPDF = new PdfDocument("c:\\inetpub\\wwwroot\\cchpportal\\ProviderDirectoryPDFs\\PharmacyDirectory.pdf");
// Create the document
ceTe.DynamicPDF.Document contentPDF = doc.CreateDocument();
// Create the merge document to use
MergeDocument mdPDF = new MergeDocument(introductionPDF); // Introduction pages
mdPDF.Append(contentPDF); // Dynamically generated pages
mdPDF.Append(pharmacyPDF); // Back pages
// Clear response object and draw this puppy to the web
Response.Clear();
Response.ClearHeaders();
mdPDF.DrawToWeb(this);
Response.End();
Any ideas?
Re: Template Header and Footer Missing!
Forum member · Mar 29, 2007For further clarification, here is the code I am using to apply my template to each page.
if (m_ProviderPages != null)
{
if (m_ProviderPages.Count > 0)
{
// Set section template (provider template)
pdf.Sections.Begin(GetTemplate("Provider"));
foreach (ceTe.DynamicPDF.Page provPage in m_ProviderPages)
{
provPage.ApplySectionTemplate = true;
pdf.Pages.Add(provPage);
}
}
}
Re: Template Header and Footer Missing!
Support · Mar 29, 2007Hello Matt,
I see that you are appending the Document object to the MergeDocument object. It is obsolete and not efficient method of doing. Below is sample code that would work for you:
PdfDocument introductionPDF = new PdfDocument("c:\\inetpub\\wwwroot\\cchpportal\\ProviderDirectoryPDFs\\Introduction.pdf");
PdfDocument pharmacyPDF = new PdfDocument("c:\\inetpub\\wwwroot\\cchpportal\\ProviderDirectoryPDFs\\PharmacyDirectory.pdf");
MergeDocument mdPDF = new MergeDocument(introductionPDF);
// Begin section and apply the template for the section
mdPDF.Sections.Begin(GetTemplate("Provider"));
Page page = new Page();
Label label = new Label("Hello World",100,100,100,100);
page.Elements.Add(label);
mdPDF.Pages.Add(page);
// Start another section without applying any template
mdPDF.Sections.Begin();
mdPDF.Append(pharmacyPDF);
mdPDF.DrawToWeb(this);
Response.End();
In the sample code I am adding label but you can add all your logic you are doing in the CreateDocument method in place of Label. That will be more efficient way of doing.
Thanks,
ceTe Software Support Team
Re: Template Header and Footer Missing!
Forum member · Mar 29, 2007Okay, I will take a look at that, thank you :)
Also, will this work if I have multiple sections and templates? I.E. the code I sent you for the "Provider" pages and their template is one of up to 5 possible sections I can have depending on certain criteria the user selects.
Re: Template Header and Footer Missing!
Forum member · Mar 29, 2007So it looks to me as though I need to create a MergeDocument and apply my section templates to it, then return it to my calling page and assemble it there, as opposed to creating a Document object and returning it... correct?
Re: Template Header and Footer Missing!
Support · Mar 29, 2007Hello,
Yes, you can start as many sections as you want and apply different templates to different sections of the PDF without any problem.
Thanks,
ceTe Software Support Team
Re: Template Header and Footer Missing!
Support · Mar 29, 2007Hello,
If you want to apply the same template across the entire document then you can just set the MergeDocument objects Template property to the global template and if you want to apply the template only to the dynamically created PDF pages then begin a section after the initial merge and apply that template for the section only.
You do not need to create the Document object and append it to the MergeDocument object at all.
Thanks,
ceTe Software Support Team
Re: Template Header and Footer Missing!
Forum member · Mar 29, 2007Wierd... it still doesn't show the templates for any section created. I have debugged it and it indeed shows that there is a section template applied to each page and has the correct content in the template but it just doesn't show up. I am really confused..
Re: Template Header and Footer Missing!
Forum member · Mar 29, 2007It may not be the best way to do it, as was stated above, but it works if I stream the generated document and then create a PdfDocument from the stream and append it to my MergeDocument.
Thank you for all of your help!!
Re: Template Header and Footer Missing!
Support · Mar 29, 2007Hello,
We did address few issues with applying templates to sections of the PDF. Can you please make sure that you are using the latest version of our product (i.e. Build 70322)? If you are using older version, I would strongly recommend you to download the latest version and replace the old DLL file with the new DLL file.
If you continue experiencing the same behavior then send over your code and static PDF files to our [^a|mailto:support@cete.com|Support Team^] and we can take a look into it further.
Thanks,
ceTe Software Support Team
Re: Template Header and Footer Missing!
Forum member · Mar 29, 2007I have server edition build 60419
Re: Template Header and Footer Missing!
Support · Mar 29, 2007Hello,
Please login to the Customer Area Customer Area
using your serial number and download the latest (Build 70322) DLL files. Replace your existing DLL file with the new one downloaded and then recompile your application. This may fix the problem you are experiencing when applying template to sections.
If getting the latest version does not resolve the problem, send us over your code and static PDF files to our [^a|mailto:support@cete.com|Support Team^].
Thanks,
ceTe Software Support Team
Re: Template Header and Footer Missing!
Forum member · Mar 29, 2007Thank you for your help, I have downloaded the new version and will test it as soon as I have time,
Matt L.