0

It used to be, and remains, possible for one's program to output (encapsulated) postscript by simply writing some lines in a text file. To draw an 'x' one might for instance write

%!PS
%%BoundingBox: 0 0 100 100
newpath 100 0 moveto 0 100 lineto stroke
newpath 0 0 moveto 100 100 lineto stroke
showpage

Is there an equivalent method to output pdf?

Edit

Please do suggest an inelegant, regular, or luxurious way to output pdf.

An inelegant method would be one that still passes by eps. A regular one would be one that parallels the eps text file above. A luxurious method would be a comfortable API/library.

Edit2

A "regular" solution is platform neutral, but a solution in neither the first nor the third categories is. So let me clarify that I am looking for a solution using Java on android.

Calaf
  • 10,113
  • 15
  • 57
  • 120
  • "Is there an equivalent method" - How equivalent? You can obviously write a pdf file if you know the syntax. Are you looking for a simpler format that can be converted to pdf? – mbeckish May 03 '13 at 14:30
  • 3
    PDF format is here - http://wwwimages.adobe.com/www.adobe.com/content/dam/Adobe/en/devnet/pdf/pdfs/pdf_reference_1-7.pdf – Roger Rowland May 03 '13 at 14:40
  • My Debian system has `epstopdf` from the `texlive-extra-utils` package. Some versions of `pstopdf`/`ps2pdf` would probably work as well. – twalberg May 03 '13 at 14:42
  • @twalberg Using epstopdf is not very elegant (as I mention in the modified question). Are you aware whether it is at least possible to do the conversion without a shell escape? Is it for instance possible to use epstopdf through an API? – Calaf May 03 '13 at 14:54
  • @RogerRowland Thanks for the pointer. Somehow I never saw blue/red/green books on pdf, even though the postscript ones were on everyone's bookshelf. – Calaf May 03 '13 at 14:57
  • I always use libharu. http://libharu.org/ – Nova Entropy May 03 '13 at 15:26
  • @mbeckish It's probably excessive to give up on a native application for this one feature. I was hoping that a good language-agnostic solution might exist, but I see that that is asking too much. I am modifying the question to make it platform specific. – Calaf May 03 '13 at 15:30
  • @mbeckish If you're interested in a good solution using C++, see the answer I just added to the first question you cited (http://stackoverflow.com/a/16363006/704972). – Calaf May 03 '13 at 15:58
  • @mbeckish I had seen the second link you cite and was disappointed by the answers over the course of the question's 3-years lifetime. Only now it's clear that reverse-engineering the pdf format is not necessary. Roger Rowland's answer appears to be the best. – Calaf May 03 '13 at 16:05
  • @RogerRowland Please move your comment to be an answer. – Calaf May 03 '13 at 16:07
  • @RogerRowland When you write that answer I would propose you point to the copy of ISO 32000-1 instead of the PDF reference. After all that is the actual standard... http://www.adobe.com/devnet/acrobat/pdfs/PDF32000_2008.pdf – mkl May 03 '13 at 17:03
  • possible duplicate of [Structure of a PDF file?](http://stackoverflow.com/q/88582/21727) – mbeckish May 03 '13 at 17:09
  • Ok, answer posted - thanks all for the comments... – Roger Rowland May 03 '13 at 19:20

3 Answers3

1

As discussed in the copious comments on your question, the ISO 32000-1 standard for the PDF file format can be found here. (Thanks to @mkl for the updated link).

It may not be trivial, but it would certainly be possible to create PDF files from scratch by using the most appropriate parts of this document for your application.

Roger Rowland
  • 25,885
  • 11
  • 72
  • 113
0

Well if I understood you correctly i might have done something similar in one of my Android applications.

I implemented a domain specific language for interactive questionnaires which results are extracted in pdf format. For the pdf creation I used the iText open source library. So, you can create a dsl and an api, between your dsl and a pdf creation and manipulation library, like iText. However, I don't know if you are interested in a ready solution or to develop something from scratch, so I am not sure if this helps.

You can find the code here github with some more details for the dsl(like the syntax etc.).

And here is the demo app in google play.

  • Aside from the question I ask here, I am also looking for a design that makes it possible not to duplicate the code -- in other words, a design that lets me draw either on Android's canvas or on the pdf "canvas" with the same set of instructions. This is not just laziness, but also helps with maintenance, etc. A design that produces some kind of intermediate dsl is not hard. The hard part is making sure that the rendering remains interactive when the output is Android's canvas. – Calaf May 03 '13 at 17:45
0

PDF is not a simple text format, so it is not that simple. But it should not be difficult to integrate a Java PDF library in your app, see iText, for example.

devconsole
  • 7,875
  • 1
  • 34
  • 42