Your achievements

Level 1

0% to

Level 2

Tip /
Sign in

Sign in to Community

to gain points, level up, and earn exciting badges like the new
Bedrock Mission!

Learn more

View all

Sign in to view all badges

SOLVED

How to add footer per page in GeneratePDFService htmlFileToPdf

Avatar

Level 2

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;

1 Accepted Solution

Avatar

Correct answer by
Employee Advisor

@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.

 

View solution in original post

7 Replies

Avatar

Employee Advisor

@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.

Avatar

Level 2

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.

Avatar

Employee Advisor

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?

Avatar

Correct answer by
Employee Advisor

@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.

 

Avatar

Level 2

I need a way using com.adobe.pdfg as this is my use case, the webpage is dynamically built

Avatar

Employee Advisor

@jonathand935543 

As mentioned previously, PDFG internally uses Acrobat (Web Capture service) for conversion, and the settings for header/footer are exposed via Acrobat configurations. 

If there is a gap in understanding of the use case, feel free to reach out to us via a support ticket and we can connect over a quick call to discuss further.