I need to write a String object "plain text" to a pdf file from a java program, does java or spring have any built-in libraries that can do the job.if not what are the best choice external libraries?
I know I can use FileOutputStream
to write data to a file but is there any option that can format the data in pdf and write it to the file, like .setContentType("application/pdf")
of the HttpServletResponse
thanks in advance
Asked
Active
Viewed 2,997 times
-2

monim
- 3,427
- 3
- 23
- 36
-
I am not sure how to do it, but a hint is that you will have to convert it from plain text to a binary (or semi-binary) format since pdf's are not plain text. You have to find an algorithm or formula that does that, and without a library you will have to provide that. When conversion to (semi)binary is done, you can write that text to the file. – Pphoenix Jun 03 '14 at 07:49
-
1What does "write a string" mean? You cannot "just" write any old text into a PDF file without breaking it. – Jongware Jun 03 '14 at 08:23
-
1[A minimal pdf](http://brendanzagaeski.appspot.com/0004.html) and the [PDF Specification](http://www.adobe.com/devnet/pdf/pdf_reference.html). This should get you started. – Ocaso Protal Jun 03 '14 at 08:30
1 Answers
0
If you need to edit/update a PDF document and you dont want to use any libraries, then you will have to implement the PDF specs yourself. http://en.wikipedia.org/wiki/Portable_Document_Format
However, doesn't look very simple. So I would recommend not to reinvent the wheel and to use libraries like iText.
Regarding the mime type, yes it is application/pdf
. More details here Proper MIME media type for PDF files