4 Replies Latest reply on Aug 5, 2010 7:45 AM by RobRZDZ

    htmlFileToPDF only works with a ZIP file

    RobRZDZ

      Hello everybody.

       

      I'm writing a simple Java program with Eclipse as to test the htmlFileToPDF API call.

       

      According to the docs, this API ""Creates a PDF document from an input HTML file or a ZIP file containing HTML files and/or Image files. For ZIP files, this method searches the ZIP contents for the index.html file. It then uses the index.html as the document root."

       

      So I created a simple Java program (mostly taken from http://help.adobe.com/en_US/livecycle/9.0/programLC/help/000213.html#1548718 - Converting HTML content to a PDF document using the Java API) but it only seems to work when the inputDocument is a ZIP file which contains the index.html file.

       

      As an examples, considering the following lines:

       

              FileInputStream is = new FileInputStream("C:\\index.html");
           Document inHTML = new Document(is);
           HtmlToPdfResult result = pdfGenClient.htmlFileToPDF(
                inHTML,
                ...
                ...
           );

       

      With the above example, when the class executes I got the following exception:

       

           ALC-PDG-080-019-Input file File.zip does not contain the index html file

       

      If I change the first line to read

       

              FileInputStream is = new FileInputStream("C:\\test.zip");

       

      and the test.zip file does contain the index.tml file, everything works as expected.

       

      What am I missing?

       

      Thanks,

      Rob

        • 1. Re: htmlFileToPDF only works with a ZIP file
          Jasmin Charbonneau Level 4

          Use  htmlToPDF instead of htmlFileToPDF.

           

          Jasmin

          • 2. Re: htmlFileToPDF only works with a ZIP file
            RobRZDZ Level 1

            Hi Jasmin!

             

            First of all, thank you for your reply.

             

            Well, far from me from being a nitpicker but isnt's htmlToPDF supposed to perform an HTML -> PDF conversion of an URL?

             

            According to the docs, htmlToPDF "creates a PDF document from an HTML file located at a given URL"; the input parameter inputURL is the URL of the HTML page you want to convert.

             

            OK, even files on a filesystem can be can be accessed as URLs but is there something wrong with the htmlFileToPDF API?

             

            I'm new to LCES2 so I might be wrong but, from the docs, I thought htmlFileToPDF was well suited for what I was trying to achieve; or perhaps the doc for this API has to be amended?

             

            Thanks,

            Rob

            • 3. Re: htmlFileToPDF only works with a ZIP file
              Jasmin Charbonneau Level 4

              I though you wanted to create it from a URL sorry. I just glanced through the post.

               

              The documentation is fine. htmlFileToPDF can convert html content.

               

              The trick is you need to put it in a document variable (com.adobe.idp.Document) and set a property to a temporary  name so it knows it's a single file and not a zip.

               

              Document htmlDoc = new Document(htmlContent.getBytes());
              htmlDoc.setAttribute("file", "Temp.html");

               

              Jasmin

              1 person found this helpful
              • 4. Re: htmlFileToPDF only works with a ZIP file
                RobRZDZ Level 1

                Hi Jasmin.

                 

                No need to apologize and thanks for your help.

                 

                I'm pretty new with LCES2 APIs so I did not pay enough attention to the setAttibute() method; by following your example, everything now works as expected.

                 

                Thanks,

                Rob