r3wp [groups: 83 posts: 189283]
  • Home
  • Script library
  • AltME Archive
  • Mailing list
  • Articles Index
  • Site search
 

World: r3wp

[PDF-Maker] discuss Gabriele's pdf-maker

Graham
3-Apr-2006
[65]
I'd hate to have to redraw this in the plot dialect just to stick 
a few points on it.
Gabriele
3-Apr-2006
[66]
it is possible, but not trivial; you don't actually need to change 
the pdf file, just append to it; however you need to parse it to 
do this correctly.
Graham
3-Apr-2006
[67]
So, given such a pdf, all I have to do is figure out where to put 
the 0, 0 and the scale, and try plotting to it?
Gabriele
3-Apr-2006
[68x8]
well, basically updating a pdf works this way:
the reader looks at the end of the file (except for linearized format, 
but this should not worry you right now) for the xref
the xref contains the location in the file of any pdf object (such 
as pages, fonts, and so on)
the xref might just be an update to an older xref present earlier 
in the file
in this case, it only contains references to changed objects, and 
to the old xref
each object has an id and a generation number; the generation number 
must be incremented when you update the object, that is when you 
append a new object to the file that should actually replace the 
old
so if page 1 has id 123 (for e.g.) and generation 1, you can append 
an object with id 123 and generation 2 to replace the original page 
object that comes earlier in the file
you need to provide a new xref for this new object and referring 
to the old xref
Graham
3-Apr-2006
[76]
And this is not trivial?
Gabriele
3-Apr-2006
[77x3]
so what you need to do is: 1) determine what objects need to be replaced 
2) append their replacements to the file 3) append new xref
it depends on the source pdf file
because you need to parse it to figure out what objects need to be 
updated and how
Graham
3-Apr-2006
[80]
this one contains a lot of binary
Gabriele
3-Apr-2006
[81]
stream objects are usually compressed; so you may need to decompress 
them too
Graham
3-Apr-2006
[82x2]
So, this is what is done by programs that annotate pdfs?
Or, is that different?
Gabriele
3-Apr-2006
[84x2]
if you are lucky and the source pdf has a simple structure, and all 
your source pdfs have the same structure, then this might be very 
easy
yes, except that annotations are separate objects so it's somewhat 
easier
Graham
3-Apr-2006
[86]
And this is all automated in pdf-maker2 ?  :)
Gabriele
3-Apr-2006
[87x5]
nope :P and won't be for pdf maker 2 either. but you can use the 
code in the pdf maker to generate the objects and the xref
(the xref generator in the pdf maker only works for the main xref 
of the file, not the change xrefs, but it should be easy to change 
it to generate a change xref)
change xrefs are actually easy to generate because you don't have 
to list "free" objects
the PDF Reference book from Adobe is all you need to do this
depending on how much you need to parse the original file, you may 
need to just read a few pages, or learn the whole spec
Graham
3-Apr-2006
[92]
Would it be easier to convert the pdf to postscript and then add 
the necessary ps commands??
Gabriele
3-Apr-2006
[93x2]
probably yes.
since ps doesn't have a structure like this
Graham
3-Apr-2006
[95x2]
I might have a go that way then.
now, all I have to do is learn a bit of PS :)
Gabriele
3-Apr-2006
[97]
it depends a lot on your source files. it may be easier with pdf 
if you don't need to parse much, otherwise if you need to you could 
need to implement decompression and so on.
Graham
3-Apr-2006
[98x2]
presumably pdf2ps does the decompression
I wonder if pdf2ps also extracts out protected pdf text ?
Gabriele
3-Apr-2006
[100]
i never tried. in principle it could.
Graham
3-Apr-2006
[101x5]
finally located ftp://ftp.foolabs.com/pub/xpdf/xpdf-3.01pl2-win32.zip
which is xpdf,and contains pdftops.exe
I converted my pdf to postscript.  So, perhaps all I need to do is 
to insert my PS commands before the "showpage" near the end of the 
ps file, and recompile back to pdf ?
That worked sort of.
I got my "Hello World" at the bottom of the page, bottom left.  But 
the pdf which was originally one page, now has a second blank page.
Which makes me wonder if we shouldn't have a ps-maker dialect.
Thør
4-Apr-2006
[106]
.
Graham
5-Apr-2006
[107]
Having done a few graphs now in postscript, and it seems fairly easy 
to do .. make be those expert in dialects could look at constructing 
a postscript dialect.  This makes for great output, and potentially 
seems easier to do than creating pdfs.
Henrik
5-Apr-2006
[108x3]
easier? I thought pdf was a simpler subset of pdf?
sorry, subset of postscript
btw. on the compression issue, is it possible to decompress pdf streams 
inside rebol if they are properly massaged? I thought of building 
template pdf files, where you could search/replace the text inside 
those streams to make new pdfs
Gabriele
5-Apr-2006
[111]
henrik, ps is definitely easier to emit. too bad windows has no support 
for it out of the box.
Henrik
5-Apr-2006
[112x3]
interesting
I've always wanted to build a postscript emitter for REBOL. This 
would solve many problems in the printing area.
it would be cool if you could take a DRAW block and convert that 
to postscript