Convert Jsp To Pdf Itext

Greenhorn
posted 13 years ago
  • Optional 'thank-you' note:

I tried iText by first reading a PDF and then re-creating the PDF with the PDF version set 10 1.4 and conformance set to PDF-1A. I validated the generated PDF using an external tool but it gave some issues. Following is the snippet of the code.

  1. In this tutorial, we will write a standalong Java Class that will convert a JPG file into a PDF document. For illustration purposes, we will stamp / insert the JPG into the PDF file in this tutorial. Later on, we will provide a servlet example in iText that will accept a user uploaded image file from the server and convert that image into a PDF.
  2. Hello All, I am trying to convert images(jpg, tif) to pdf using iText. I have had some success in this by creating a simple jsp which perform the conversion, eventually the whole thing will be included in a servlet but the jsp makes early development simpler. The problem I have is that I don't have a direct url/uri to an actual image.
Hello All,
I am trying to convert images(jpg, tif) to pdf using iText. I have had some success in this by creating a simple jsp which perform the conversion, eventually the whole thing will be included in a servlet but the jsp makes early development simpler.
The problem I have is that I don't have a direct url/uri to an actual image. The images are stored in a third party EDM system and at present use their servlet to display them(in browser). I also only have their class file, no source.
I have put my jsp code below, I need to do something like

instead of

but all I get is a 'No such file or directory' error. However an 'a href' returns the image. Can anyone help me get the results from the servlet and create the pdf?

Thanks
Rancher
posted 13 years ago
  • Optional 'thank-you' note:
Welcome to JavaRanch.
The Image.getInstance(String) method expects a filename as parameter. Try the getInstance(URL) method instead; maybe something like ' Image.getInstance(new URL('http://www.server.com/servlet/MyImageServlet') '.
There's also a 'getInstance(byte[] imgb)' variant, to which you can pass the bytes that make up the image directly (if your code has access to those bytes, that is).
Greenhorn
posted 13 years ago
  • Optional 'thank-you' note:
Itext
I have been at the possibility of using the URL of the servlet, but no real luck so far. It is a step forwards though as now I can actually find the servlet, but just get more errors.
I have however managed to take a look at source of the servlet I'm trying to call. I think my errors are because the servlet is actually outputting the image to the browser.

Does that sound right?
Also, before this thread was moved there were 2 replies, now there is only one. Why was it removed?
Thanks
Rancher
posted 13 years ago
  • Optional 'thank-you' note:

I think my errors are because the servlet is actually outputting the image to the browser.


I wouldn't think so. If you use Image.getInstance(URL), then that opens it own HTTP connection to the servlet, and reads its output. But you might want to verify that what it receives from the servlet is really the complete image.

Also, before this thread was moved there were 2 replies, now there is only one. Why was it removed?


Convert Jsp To Pdf Itext I haven't seen any other answer, but whoever posted it might have had second thoughts, and deleted it himself.
[ July 04, 2007: Message edited by: Ulf Dittmer ]
Ranch Hand
posted 9 years ago
  • Optional 'thank-you' note:
Hi experts, I am trying to convert my jsp/html form to pdf once a button is clicked. how do I do that???
sometimes my jsp form has logo with the form , does that affect conversion
is there any program can do that for me , please help me urgently
thanks a lot
Rancher
posted 9 years ago
  • Optional 'thank-you' note:
You can use the iText library to create PDFs. If the HTML page consists of CSS-styled XHTML, then the FlyingSaucer library is also an option.
Ranch Hand
posted 9 years ago
  • Optional 'thank-you' note:

Ulf Dittmer wrote:You can use the iText library to create PDFs. If the HTML page consists of CSS-styled XHTML, then the FlyingSaucer library is also an option.


thanks for reply , I don't know how to use FlyingSaucer library , could you please just an example of it .
I have found three examples of conversion but still could work for me the programs , once I open the pdf file. what shall I do??
these are the links
http://www.java2s.com/Tutorial/Java/0419__PDF/ParsingHtml.htm
http://www.java2s.com/Tutorial/Java/0419__PDF/HtmlParserfromiText.htm
http://www.java2s.com/Tutorial/Java/0419__PDF/ParsingHtmlSnippets.htm
and aonther example is below

I have error here :
Pdf pdfDocument.add(new Paragraph(org.apache.commons.io.FileUtils.readFileToString(file)));
error is :
readFileToString(java.io.File,java.lang.String) in org.apache.commons.io.FileUtils cannot be applied to (java.io.File)
what is the solution ?? , I am using commons-io-2.0.1.jar for it. But still error available.
thanks a lot
Rancher
posted 9 years ago
  • Optional 'thank-you' note:

I don't know how to use FlyingSaucer library , could you please just an example of it .

Tomtom maps central and eastern europe download music


Convert Jsp To Pdf Itext

Convert Jsp To Pdf Using Itext

Your first stop for information should always be the home page. The FlyingSaucer site links to a couple of introductory articles, and has a user guide available for download.

error is : readFileToString(java.io.File,java.lang.String) in org.apache.commons.io.FileUtils cannot be applied to (java.io.File)


Not sure what's happening, the code compiles fine for me when linked against iText 2.1.7 and Commons IO 2.0.1 (after fixing the missing import of the Rectangle class)
Ranch Hand
posted 9 years ago

Convert Jsp File To Pdf

  • Optional 'thank-you' note:
Thanks Ulf Dittmer
I got my problem I was useing two common jars together the new and the old one , so removing the old solve the problem , but I discoved that the pdf file is only the source
code of my html page. That is not what I am looking for , Basically I am trying to generate pdf file once use clicks a print button. User will fill form first on page , then when user
clicks print , all user information will be inserted in pdf as form so it can be printed then .what shall I do !!!
Rancher
posted 9 years ago
  • Optional 'thank-you' note:

what shall I do !!!


Convert Jsp Page To Pdf Using Itext

Please restrict yourself to single punctuation signs; it's sufficient. What's more, question are ended with question marks, not exclamation marks.
You can submit the form to the server, create the PDF there using iText, and then either a) stream the PDF as response back to the client, or b) store it on the server and include a link to it in the response page.