I’m using the PDF::Writer plugin and have got everything that i wanted
working except for one thing: I have sections that i don’t want to
split over a page. I tried a couple of ways of dealing with this, each
of which has problems. Can anyone help?
Save page number and y position. Render the section, then test new
page against old. If we’re on a new page, jump back to the saved
position, insert a page break, then jump to the end. PROBLEM: there
doesn’t seem to be a way to move the current position to a different
page - only to different places on the same page.
This seems more sensible: Create the section, but don’t render it to
the page - render it to some temporary place in memory - a virtual page,
effectively (storing the virtual position first and afterwards to get
the size of the section). If the section size is more than the distance
from the position on the real page to the margin, put a page break on
the real page. Then render to the real page - either by copying the
contents of the virtual page or by re-rendering that section from
scratch. PROBLEM: I can’t work out how to do this. doh.
Can anyone help, either with these approaches or a better way?
I’m a dumbass…for approach 2, i just need to make a new PDF::Writer
object and test my section size on that. What would be nicer though, is
instead of redoing everything on my real pdf after testing it on the
temp one, i could just copy the contents across. Does anyone know a way
to do that?
I’m a dumbass…for approach 2, i just need to make a new PDF::Writer
object and test my section size on that. What would be nicer though, is
instead of redoing everything on my real pdf after testing it on the
temp one, i could just copy the contents across. Does anyone know a way
to do that?
thanks
max
Hey man, this is what I did. If you can extend PDF::Writer that class or
just open that class up, then you can add this function. If the markup
comes out horrible, look at gist:224821 · GitHub
On Tue, Nov 3, 2009 at 1:17 PM, Marnen Laibow-Koser [email protected]
wrote:
Max W. wrote:
Thanks a lot for that.
I’ve actually switched to using acts_as_flying_saucer for pdf generation
it does very good conversion from html to pdf, so no more
hand-building as was the case with pdf writer.
I didn’t know there was a Flying Saucer plugin. I’ll have to look at it
– I really like Prawn, but doing my PDF files in HTML would be nice.
Yeah, if you want easy HTML to PDF, Flying Saucer is definitely the way
to go.
Prawn is more for if you want absolute control over how your document
is rendered.