• Visitors can check out the Forum FAQ by clicking this link. You have to register before you can post: click the REGISTER link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below. View our Forum Privacy Policy.
  • Want to receive the latest contracting news and advice straight to your inbox? Sign up to the ContractorUK newsletter here. Every sign up will also be entered into a draw to WIN £100 Amazon vouchers!

HTML to PDF java lib

Collapse
X
  •  
  • Filter
  • Time
  • Show
Clear All
new posts

    HTML to PDF java lib

    I have to do a print friendly PDF for a set of dynamic HTML pages. Have done this in the past but not for many years so I am out the loop.

    I am wanting to trap the request, pick up the HTML from the DB, pass it to a library which will sort out wrapping and such like then push the created PDF down the reponse pipe to a pop up.

    Anyone know of anything that will handle this? Does not have to be anything fancy, cheap and easy are the watchwords on this job (just like my tarts).

    Cheers

    #2
    Apache FOP ?

    Will need a bit of work converting HTML to a suitable input format for the FOP processor :-

    HowTo/HtmlToPdf - Xmlgraphics-fop Wiki

    Comment


      #3
      HTML to PDF

      Originally posted by minestrone View Post
      I have to do a print friendly PDF for a set of dynamic HTML pages. Have done this in the past but not for many years so I am out the loop.

      I am wanting to trap the request, pick up the HTML from the DB, pass it to a library which will sort out wrapping and such like then push the created PDF down the reponse pipe to a pop up.

      Anyone know of anything that will handle this? Does not have to be anything fancy, cheap and easy are the watchwords on this job (just like my tarts).

      Cheers
      You can convert HTML to PDF using the web service DocRaptor.com. They can also convert xml to excel, though I'm not sure that'll be useful for you. They have a bunch of examples in various languages that you might be able to use.

      Comment


        #4
        Originally posted by minestrone View Post
        I have to do a print friendly PDF for a set of dynamic HTML pages. Have done this in the past but not for many years so I am out the loop.

        I am wanting to trap the request, pick up the HTML from the DB, pass it to a library which will sort out wrapping and such like then push the created PDF down the reponse pipe to a pop up.

        Anyone know of anything that will handle this? Does not have to be anything fancy, cheap and easy are the watchwords on this job (just like my tarts).

        Cheers
        itextpdf is the tool I always seem to end up with for doing this stuff. The commercial rates are high tho if you need to give it to others (LGPL licence).

        The other option is pd4ml which is 100 euros or so.
        merely at clientco for the entertainment

        Comment


          #5
          The OP seems to be ignoring all these helpful suggestions, perhaps we shouldn't bother next time

          Comment


            #6
            I have been running around all week, 14 hour days just now. This was going to be a saturday job.

            I'm going to try the apache fop first off, i seem to remeber using that round about 2003. I have used jtidy so it seems a resonable fit, and I don't want to pay. The transform does not do tables but I can live with that.

            Comment


              #7
              Actually I text looks pretty alright, might give that a whirl today.

              Comment


                #8
                Eventually got round to getting a test harness working with iText using the XMLworker add on.

                And if I post it here from clientCo I can pick it up tonight and stick it into Plan B

                Cheers

                Code:
                import java.io.ByteArrayInputStream;
                import java.io.ByteArrayOutputStream;
                import java.io.IOException;
                import java.io.InputStream;
                
                import com.itextpdf.text.Document;
                import com.itextpdf.text.DocumentException;
                import com.itextpdf.text.pdf.PdfWriter;
                import com.itextpdf.tool.xml.XMLWorkerHelper;
                
                /**
                 * 
                 * @author XXXX
                 *
                 */
                public class Test {
                
                	/**
                	 * 
                	 * @param args
                	 * @throws IOException
                	 * @throws DocumentException
                	 */
                	public static void main(String[] args) throws IOException,
                			DocumentException {
                
                		Document document = new Document();
                		ByteArrayOutputStream baos = new ByteArrayOutputStream();
                		PdfWriter writer = PdfWriter.getInstance(document, baos);
                
                		document.open();
                
                		String text = new String( "<html><head></head><body>" +
                				                  "<h1>Title</h1><p>Paragraph</p>" +
                				                  "</body></html>");
                
                		InputStream inputHtmlAsStream = new ByteArrayInputStream(text
                				.getBytes("UTF-8"));
                
                		XMLWorkerHelper.getInstance().parseXHtml(writer, document,
                				inputHtmlAsStream, null);
                
                		document.close();
                
                
                		System.out.println(baos.toString());
                
                	}
                }

                Comment

                Working...
                X