How to add footer per page in GeneratePDFService htmlFileToPdf | Community
Skip to main content
Level 2
May 31, 2022
Solved

How to add footer per page in GeneratePDFService htmlFileToPdf

  • May 31, 2022
  • 1 reply
  • 12356 views

How to add footer per page in GeneratePDFService htmlFileToPdf

 

I have a long html file that results into a multi page pdf file, I would like to put a footer per page, is there something I can add to this to make that happen?

 

This is my code:

 

BundleContext bundleContext = FrameworkUtil.getBundle(this.getClass()).getBundleContext();
ServiceReference < ? > serviceRef = bundleContext.getServiceReference(GeneratePDFService.class.getName());
GeneratePDFService pdfService = (GeneratePDFService) bundleContext.getService(serviceRef);
XMPMeta xmpData = new XMPMeta();
xmpData.

// temporary files names
String randomAlphaNum = randomAlphaNumeric(7);
String tempHTMLFileName = randomAlphaNum + "convert.html";

// Create zip file of the HTML as the pdf service only accepts zip file
StringBuilder sb = new StringBuilder();
sb.append(htmlText);

ByteArrayOutputStream zipbaos = new ByteArrayOutputStream();
ZipOutputStream zipper = new ZipOutputStream(zipbaos);

ZipEntry e = new ZipEntry(tempHTMLFileName);
zipper.putNextEntry(e);
zipper.write(htmlText.getBytes(StandardCharsets.UTF_8));
zipper.closeEntry();
zipper.close();

// Create Document to convert from zip file bytearray
java.io.InputStream docIS = new ByteArrayInputStream(zipbaos.toByteArray());
com.adobe.aemfd.docmanager.Document uploadedDocument = new com.adobe.aemfd.docmanager.Document(docIS);

// For HTML to PDF conversion using HTML File jsp version:
com.adobe.pdfg.result.HtmlToPdfResult result = pdfServiceice.htmlFileToPdf(uploadedDocument, null, null, null, null);

 

com.adobe.aemfd.docmanager.Document convertedDoc = result.getCreatedDocument();
convertedDoc.setMaxInlineSize(1000000000);

zipbaos.flush();
zipbaos.close();

// return pdf document
return convertedDoc;

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
Best answer by Pulkit_Jain_

How do I do that?


@jonathand935543

PDFG Web Capture uses Acrobat for the conversion and to enable the header and footer, you need to follow the below-mentioned steps on Acrobat installed on the Forms server.

1. File > Create > Create PDF from any format.
2. Select "Web Page" and then advanced settings.
3. The Web Page Conversion Settings dialog displays.
4. Tick "Place headers and footers on a new page".

 

Let me know in case you're stuck.

 

1 reply

Pulkit_Jain_
Adobe Employee
Adobe Employee
May 31, 2022

@jonathand935543 

I think the configuration for headers and footers needs to be set on the Acrobat (Web Capture service) instead of the PDFG service.

There is an option “Place Headers And Footers On New Page” as mentioned in https://helpx.adobe.com/acrobat/using/converting-web-pages-pdf.html. By default, you'll see the web page title in the header and the URL/path in the footer.

Hope this helps.

Level 2
May 31, 2022

Sorry what I am doing is combining different experience fragments based on tags to combine them in one html then convert that html to pdf. I don't think I can use that. As it is not actually a web page I am converting.

Pulkit_Jain_
Adobe Employee
Adobe Employee
May 31, 2022

I don't think that input documents should be a concern as you're able to convert this HTML page into a PDF. Can you try to update the Acrobat settings on the Forms server to enable the header/footer and check if that serves the purpose?