Convertor HTML to PDF : add header section

Hi,


I would like add an HEADER SECTION .

The convertor html to the pdf work fine :

String basePath = C:/temp/;
HtmlLoadOptions htmloptions = new HtmlLoadOptions(basePath);
Document doc = new Document(dataDir+ Input.html, htmloptions);
doc.Save(dataDir+ HTMLToPDF_out.pdf);


But how can I add a header and a footer on all pages of pdf ?

Thank’s

Thomas





Hi Thomas,


Thanks for contacting support.

Once you have performed the HTML conversion to PDF format, please follow the instructions specified over

Hi Thomas,


Thanks for your inquiry. You can add header/footer to PDF document as following. Hopefully it will help you to accomplish the task.

HtmlLoadOptions options = new HtmlLoadOptions();<o:p></o:p>

options.PageInfo.Margin = new Aspose.Pdf.MarginInfo { Left = 40, Right = 40, Top = 30, Bottom = 20 };

// Instantiate Document object

Document doc = new Document("test.html", options);

MemoryStream ms = new MemoryStream();

doc.Save(ms);

doc = new Document(ms);

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

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

FileStream fs = new FileStream(myDir + "logo.png", FileMode.Open, FileAccess.Read);

Aspose.Pdf.Image image1 = new Aspose.Pdf.Image();

image1.FixWidth = 50;

image1.FixHeight = 50;

//Add the image into paragraphs collection of the section

header.Paragraphs.Add(image1);

//Set the ImageStream to a MemoryStream object

image1.ImageStream = fs;

//Add footer text

Aspose.Pdf.Text.TextFragment fTxt = new Aspose.Pdf.Text.TextFragment("$p / $P ");

fTxt.TextState.Font = FontRepository.FindFont("Arial");

fTxt.TextState.FontSize = 16;

fTxt.HorizontalAlignment = Aspose.Pdf.HorizontalAlignment.Right;

footer.Paragraphs.Add(fTxt);

foreach (Aspose.Pdf.Page page in doc.Pages)

{

page.Header = header;

page.Footer = footer;

}

// Save PDF file

doc.Save("htmltopdf.pdf");


Please feel free to contact us for any further assistance.

Best Regards,

Yes !! Perfect !


Thank you

Best regards,

Hi Thomas,


Thanks for your feedback. It is good to know that you have managed to accomplish your requirements.

Please keep using our API and feel free to contact us for any further assistance.

Best Regards,