Free Support Forum -

Merging multiple PDFs to single PDF (PDFs generated from HTML)

I want to merge two documents which has Header and footer to a single pdf. Below is giving me pdfs with out header and footer and different page sizes.

PDFs are generated with html. can you let me know what is the issue with below code. ?

HtmlLoadOptions options = new HtmlLoadOptions();
options.PageInfo.Margin = new MarginInfo { Left = 15, Right = 15, Top = 150, Bottom = 15 };
options.PageInfo.Width = 1000;
options.PageInfo.Height = 800;

// Instantiate Document object
byte[] byteArray = Encoding.UTF8.GetBytes("Body of html page1

MemoryStream stream = new MemoryStream(byteArray);
Document pdfDocument1 = new Document(stream, options);

// Open the second document
byte[] byteArray2 = Encoding.UTF8.GetBytes("Body of html page2

Document pdfDocument2 = new Document(new MemoryStream(byteArray2), options);
pdfDocument2.PageMode = Aspose.Pdf.DOM.PageMode.FullScreen;

Aspose.Pdf.HeaderFooter header = new Aspose.Pdf.HeaderFooter();
Aspose.Pdf.HeaderFooter footer = new Aspose.Pdf.HeaderFooter();

var reportHeader = "

Test Header

Aspose.Pdf.HtmlFragment hh = new HtmlFragment(reportHeader);

var reportFooter = "This is footer";
Aspose.Pdf.HtmlFragment ff = new HtmlFragment(reportFooter);

foreach (Page page in pdfDocument1.Pages)
page.Header = header;
page.Footer = footer;
foreach (Page page in pdfDocument2.Pages)
page.Header = header;
page.Footer = footer;
// Save PDF file
pdfDocument1.Save(myDir + "htmltopdf.pdf");

Hi Raju,

for using our API’s.<o:p></o:p>

I have tested the scenario and I am able to reproduce the same problem. For the sake of correction, I have logged it in our issue tracking system as PDFNEWNET-38888. We will investigate this issue in details and will keep you updated on the status of a correction.

We apologize for your inconvenience.