HI folks
we are trying to create a Servlet using Component and ask is to generate PDF from HTML File using following code but it is throwing an exception
com.adobe.pdfg.exception.ConversionException: ALC-PDG-080-019-Input file File.zip does not contain the index html file.
The HTML file I am using is basic one and converting to aemfd doc before passing to conversion method.
Pl help share inputs where things are wrong
AEM 6.5.8 OSGI AEM Forms on Linux
@component(service = Servlet.class, property = { Constants.SERVICE_DESCRIPTION + "=Testing Report Generation","sling.servlet.paths=" + "/bin/test-automation-report",})
public class HTMLtoPDFServlet extends SlingSafeMethodsServlet {
@Reference
GeneratePDFService pdfGenService ;
protected void doGet(final SlingHttpServletRequest request, final SlingHttpServletResponse response)
throws ServletException, IOException {
String inputFileName = "C://Users//manu.gupta//Downloads//testing//Test-Automation.html";
InputStream is = new FileInputStream(inputFileName);
Document returnDoc = new com.adobe.aemfd.docmanager.Document(is);
String securitySettings = "No Security";
String fileTypeSettings = "Standard";
com.adobe.pdfg.result.HtmlToPdfResult result;
try {
result = pdfGenService.htmlFileToPdf(returnDoc, securitySettings, fileTypeSettings, null, null);
//Get the newly created document
com.adobe.aemfd.docmanager.Document createdDocument = result.getCreatedDocument();
}
catch (ConversionException | InvalidParameterException | FileFormatNotSupportedException e) {
e.printStackTrace();
}
}
}
Solved! Go to Solution.
Views
Replies
Total Likes
the code to convert html to pdf is as follows
com.adobe.pdfg.result.HtmlToPdfResult htmpToPDFResult = null;
try {
htmpToPDFResult = generatePdfService.htmlFileToPdf(zippedFile,"Standard","No Security",null,null);
} catch (ConversionException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (InvalidParameterException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (FileFormatNotSupportedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
//com.adobe.pdfg.result.ExportPDFResult exportPDFResult = pdfgService.exportPDF2(pdfDocument,"abc.pdf","RTF",null);
return htmpToPDFResult.getCreatedDocument();
Based on the error msg, the API takes the HTML input file as zipped so if you change the input stream as below:
FileInputStream is = new FileInputStream("C://Users//manu.gupta//Downloads//testing//File.zip");
and Test-Automation.html placed in this zip then it should work as expected.
You need to put it in a document variable and use setAttribute so it knows it's a single file and not a zip.
Document htmlDoc = new Document(htmlContent.getBytes()); htmlDoc.setAttribute("file", "Test-Automation.html");
Hope this helps!
Thanks this helped and I am able to progress, but i am struck by another road block of some issue. HTML is very basic one with just p tag and some text. But still throwing error.
String inputFileName = "C://Users//manu.gupta//Downloads//testing//Test-Automation-font.zip"; FileInputStream is = new FileInputStream(inputFileName); Document returnDoc = new com.adobe.aemfd.docmanager.Document(is); returnDoc.setAttribute("file", "Test-Automation-font.html"); String securitySettings = "No Security"; String fileTypeSettings = "Standard"; com.adobe.pdfg.result.HtmlToPdfResult result; try { result = pdfGenService.htmlFileToPdf(returnDoc,fileTypeSettings, securitySettings , null, null); com.adobe.aemfd.docmanager.Document createdDocument = result.getCreatedDocument();
Log trace
15.03.2022 14:14:06.253 *INFO* [[0:0:0:0:0:0:0:1] [1647333846252] GET /bin/test-automation-report HTTP/1.1] convertHTMLToPDF taking input
15.03.2022 14:14:06.254 *INFO* [[0:0:0:0:0:0:0:1] [1647333846252] GET /bin/test-automation-report HTTP/1.1] file setting set
15.03.2022 14:14:06.254 *INFO* [[0:0:0:0:0:0:0:1] [1647333846252] GET /bin/test-automation-report HTTP/1.1] com.adobe.pdfg.joboptions.parser.JOParser ALC-PDG-001-000-
Job ID for the submitted htmlFileToPDF job =533e57-fe9e23-2db900-7aafb3-e1dd66-eafe6f
15.03.2022 14:14:06.289 *INFO* [[0:0:0:0:0:0:0:1] [1647333846252] GET /bin/test-automation-report HTTP/1.1] com.adobe.pdfg.joboptions.parser.JOParser ALC-PDG-001-000-Trying the primary conversion via WEBKIT
15.03.2022 14:14:06.289 *INFO* [[0:0:0:0:0:0:0:1] [1647333846252] GET /bin/test-automation-report HTTP/1.1] com.adobe.pdfg.joboptions.parser.JOParser ALC-PDG-001-024-file:/C:/Users/manu.gupta/aemlocal/aem65/crx-quickstart/temp/datamanager/pdfg-manu.gupta/53/3e57-fe9e23-2db900-7aafb3-e1dd66-eafe6f/unzip/Test-Automation-font.html: Time Job Submitted: 3/15/22 2:14 PM for job = 533e57-fe9e23-2db900-7aafb3-e1dd66-eafe6f
15.03.2022 14:14:06.289 *INFO* [[0:0:0:0:0:0:0:1] [1647333846252] GET /bin/test-automation-report HTTP/1.1] com.adobe.pdfg.joboptions.parser.JOParser ALC-PDG-001-016-file:/C:/Users/manu.gupta/aemlocal/aem65/crx-quickstart/temp/datamanager/pdfg-manu.gupta/53/3e57-fe9e23-2db900-7aafb3-e1dd66-eafe6f/unzip/Test-Automation-font.html: Job Type: HTML to PDF
15.03.2022 14:14:06.292 *INFO* [[0:0:0:0:0:0:0:1] [1647333846252] GET /bin/test-automation-report HTTP/1.1] com.adobe.service.ConnectionFactoryManagerPeerImpl Service: HtmlToPdfSvc resource: ProcessResource@7a79c3b7(name=HTML2PDFConverter.exe,pid=14236) applying queue wait adjustment of 0s to timeout of transaction: org.apache.geronimo.transaction.manager.TransactionImpl@13583bc9. Supplied timeout: 300s, Effective timeout: 300s.
15.03.2022 14:14:06.292 *INFO* [[0:0:0:0:0:0:0:1] [1647333846252] GET /bin/test-automation-report HTTP/1.1] com.adobe.service.ConnectionFactoryManagerPeerImpl Service: HtmlToPdfSvc successfully scheduled an interrupt for transaction: org.apache.geronimo.transaction.manager.TransactionImpl@13583bc9 after 300s.
15.03.2022 14:14:06.294 *INFO* [[0:0:0:0:0:0:0:1] [1647333846252] GET /bin/test-automation-report HTTP/1.1] jacorb.orb.giop ClientConnectionManager: found ClientGIOPConnection to 10.98.181.199:57269 (5645a1fb)
15.03.2022 14:14:06.300 *INFO* [[0:0:0:0:0:0:0:1] [1647333846252] GET /bin/test-automation-report HTTP/1.1] com.adobe.pdfg.joboptions.parser.JOParser ALC-PDG-001-028-file:/C:/Users/manu.gupta/aemlocal/aem65/crx-quickstart/temp/datamanager/pdfg-manu.gupta/53/3e57-fe9e23-2db900-7aafb3-e1dd66-eafe6f/unzip/Test-Automation-font.html: Job Completion Status: Failed
15.03.2022 14:14:06.300 *INFO* [[0:0:0:0:0:0:0:1] [1647333846252] GET /bin/test-automation-report HTTP/1.1] com.adobe.pdfg.joboptions.parser.JOParser ALC-PDG-001-025-file:/C:/Users/manu.gupta/aemlocal/aem65/crx-quickstart/temp/datamanager/pdfg-manu.gupta/53/3e57-fe9e23-2db900-7aafb3-e1dd66-eafe6f/unzip/Test-Automation-font.html: Time Job Completed: 3/15/22 2:14 PM for job = 533e57-fe9e23-2db900-7aafb3-e1dd66-eafe6f
15.03.2022 14:14:06.300 *INFO* [[0:0:0:0:0:0:0:1] [1647333846252] GET /bin/test-automation-report HTTP/1.1] com.adobe.pdfg.joboptions.parser.JOParser ALC-PDG-001-030-file:/C:/Users/manu.gupta/aemlocal/aem65/crx-quickstart/temp/datamanager/pdfg-manu.gupta/53/3e57-fe9e23-2db900-7aafb3-e1dd66-eafe6f/unzip/Test-Automation-font.html: Waiting time in queue: -1,647,333,846,289 ms for job = 533e57-fe9e23-2db900-7aafb3-e1dd66-eafe6f
15.03.2022 14:14:06.300 *INFO* [[0:0:0:0:0:0:0:1] [1647333846252] GET /bin/test-automation-report HTTP/1.1] com.adobe.pdfg.joboptions.parser.JOParser ALC-PDG-001-026-file:/C:/Users/manu.gupta/aemlocal/aem65/crx-quickstart/temp/datamanager/pdfg-manu.gupta/53/3e57-fe9e23-2db900-7aafb3-e1dd66-eafe6f/unzip/Test-Automation-font.html: Time of Job Execution: 1,647,333,846,300 ms for job = 533e57-fe9e23-2db900-7aafb3-e1dd66-eafe6f
15.03.2022 14:14:06.301 *INFO* [[0:0:0:0:0:0:0:1] [1647333846252] GET /bin/test-automation-report HTTP/1.1] com.adobe.pdfg.joboptions.parser.JOParser ALC-PDG-001-000-Conversion failed : ALC-PDG-015-057-The system cannot locate fonts because they are unavailable or missing. Please submit your file again or contact your system administrator.
15.03.2022 14:14:06.301 *INFO* [[0:0:0:0:0:0:0:1] [1647333846252] GET /bin/test-automation-report HTTP/1.1] com.adobe.pdfg.joboptions.parser.JOParser ALC-PDG-001-000-Trying the secondary route conversion as fallback: WEB_CAPTURE
15.03.2022 14:14:06.310 *INFO* [[0:0:0:0:0:0:0:1] [1647333846252] GET /bin/test-automation-report HTTP/1.1] com.adobe.pdfg.joboptions.parser.JOParser ALC-PDG-001-024-file:/C:/Users/manu.gupta/aemlocal/aem65/crx-quickstart/temp/datamanager/pdfg-manu.gupta/53/3e57-fe9e23-2db900-7aafb3-e1dd66-eafe6f/unzip/Test-Automation-font.html: Time Job Submitted: 3/15/22 2:14 PM for job = 533e57-fe9e23-2db900-7aafb3-e1dd66-eafe6f
15.03.2022 14:14:06.310 *INFO* [[0:0:0:0:0:0:0:1] [1647333846252] GET /bin/test-automation-report HTTP/1.1] com.adobe.pdfg.joboptions.parser.JOParser ALC-PDG-001-016-file:/C:/Users/manu.gupta/aemlocal/aem65/crx-quickstart/temp/datamanager/pdfg-manu.gupta/53/3e57-fe9e23-2db900-7aafb3-e1dd66-eafe6f/unzip/Test-Automation-font.html: Job Type: Convert to PDF
15.03.2022 14:14:06.313 *INFO* [[0:0:0:0:0:0:0:1] [1647333846252] GET /bin/test-automation-report HTTP/1.1] com.adobe.pdfg.joboptions.parser.JOParser ALC-PDG-001-022-file:/C:/Users/manu.gupta/aemlocal/aem65/crx-quickstart/temp/datamanager/pdfg-manu.gupta/53/3e57-fe9e23-2db900-7aafb3-e1dd66-eafe6f/unzip/Test-Automation-font.html: Security Settings Used: No Security
15.03.2022 14:14:06.314 *INFO* [[0:0:0:0:0:0:0:1] [1647333846252] GET /bin/test-automation-report HTTP/1.1] com.adobe.pdfg.joboptions.parser.JOParser ALC-PDG-001-023-file:/C:/Users/manu.gupta/aemlocal/aem65/crx-quickstart/temp/datamanager/pdfg-manu.gupta/53/3e57-fe9e23-2db900-7aafb3-e1dd66-eafe6f/unzip/Test-Automation-font.html: FileType Settings Used: Standard
15.03.2022 14:14:06.316 *INFO* [[0:0:0:0:0:0:0:1] [1647333846252] GET /bin/test-automation-report HTTP/1.1] com.adobe.pdfg.joboptions.parser.JOParser ALC-PDG-001-028-file:/C:/Users/manu.gupta/aemlocal/aem65/crx-quickstart/temp/datamanager/pdfg-manu.gupta/53/3e57-fe9e23-2db900-7aafb3-e1dd66-eafe6f/unzip/Test-Automation-font.html: Job Completion Status: Failed
15.03.2022 14:14:06.316 *INFO* [[0:0:0:0:0:0:0:1] [1647333846252] GET /bin/test-automation-report HTTP/1.1] com.adobe.pdfg.joboptions.parser.JOParser ALC-PDG-001-025-file:/C:/Users/manu.gupta/aemlocal/aem65/crx-quickstart/temp/datamanager/pdfg-manu.gupta/53/3e57-fe9e23-2db900-7aafb3-e1dd66-eafe6f/unzip/Test-Automation-font.html: Time Job Completed: 3/15/22 2:14 PM for job = 533e57-fe9e23-2db900-7aafb3-e1dd66-eafe6f
15.03.2022 14:14:06.316 *INFO* [[0:0:0:0:0:0:0:1] [1647333846252] GET /bin/test-automation-report HTTP/1.1] com.adobe.pdfg.joboptions.parser.JOParser ALC-PDG-001-030-file:/C:/Users/manu.gupta/aemlocal/aem65/crx-quickstart/temp/datamanager/pdfg-manu.gupta/53/3e57-fe9e23-2db900-7aafb3-e1dd66-eafe6f/unzip/Test-Automation-font.html: Waiting time in queue: 0 ms for job = 533e57-fe9e23-2db900-7aafb3-e1dd66-eafe6f
15.03.2022 14:14:06.317 *INFO* [[0:0:0:0:0:0:0:1] [1647333846252] GET /bin/test-automation-report HTTP/1.1] com.adobe.pdfg.joboptions.parser.JOParser ALC-PDG-001-026-file:/C:/Users/manu.gupta/aemlocal/aem65/crx-quickstart/temp/datamanager/pdfg-manu.gupta/53/3e57-fe9e23-2db900-7aafb3-e1dd66-eafe6f/unzip/Test-Automation-font.html: Time of Job Execution: 8 ms for job = 533e57-fe9e23-2db900-7aafb3-e1dd66-eafe6f
15.03.2022 14:14:06.317 *ERROR* [[0:0:0:0:0:0:0:1] [1647333846252] GET /bin/test-automation-report HTTP/1.1] com.adobe.pdfg.joboptions.parser.JOParser ALC-PDG-001-000-ALC-PDG-001-000-Conversion of the input file failed because of an exception.
ALC-PDG-015-057-The system cannot locate fonts because they are unavailable or missing. Please submit your file again or contact your system administrator.
15.03.2022 14:14:06.325 *ERROR* [[0:0:0:0:0:0:0:1] [1647333846252] GET /bin/test-automation-report HTTP/1.1] Error OCCURRED: ALC-PDG-001-000-Conversion of the input file failed because of an exception.
ALC-PDG-015-057-The system cannot locate fonts because they are unavailable or missing. Please submit your file again or contact your system administrator.
Standard Error
Seems to be an issue with PDFG Font configs on this system.
Please review all the relevant configs (search for Unix/Font/HTML2PDF) mentioned here[0] as the PDFG service is very stringent with the pre-requisites for the HTML2PDF API.
the code to convert html to pdf is as follows
com.adobe.pdfg.result.HtmlToPdfResult htmpToPDFResult = null;
try {
htmpToPDFResult = generatePdfService.htmlFileToPdf(zippedFile,"Standard","No Security",null,null);
} catch (ConversionException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (InvalidParameterException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (FileFormatNotSupportedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
//com.adobe.pdfg.result.ExportPDFResult exportPDFResult = pdfgService.exportPDF2(pdfDocument,"abc.pdf","RTF",null);
return htmpToPDFResult.getCreatedDocument();
you will need to create a zipped file and put your html file in the zip file. I think the html file needs to be named index.html as shown in this image
Views
Likes
Replies