Saving a PDF of a particular size without recording and without endRaw() ?
in
Core Library Questions
•
2 years ago
A few days ago I asked a question about creating PDFs without recording them (
http://forum.processing.org/topic/problem-creating-with-pdfs-behind-the-scenes )
Thanks to someone here, that problem was solved but I can't quite figure out how to create a PDF of a particular size, manipulate it, and then save it again.
What I can do is this :
This works to create a pdf, draw on it and save it to disk. But using beginRaw this way doesn't allow me to set the size / resolution of the pdf file.
Alternatively I can do this :
But there must be another way of achieving this if you aren't using the beginRaw / endRaw methods.
cheers
phil
Update :
I should mention. If I just try to do a
pdf.save("fileName.pdf");
after the pdf.endDraw() I get the following exception :
Clearly, something in Processing's PDF library knows how to write a PDF file. But it seems that that knowledge hasn't been incorporated into the PGraphicsPDF class.
Thanks to someone here, that problem was solved but I can't quite figure out how to create a PDF of a particular size, manipulate it, and then save it again.
What I can do is this :
- PGraphicsPDF pdf;
- pdf = (PGraphicsPDF)beginRaw(PDF, "find.pdf");
- pdf.beginDraw();
- // do some stuff with pdf as the graphics canvas
- pdf.endDraw();
- endRaw();
This works to create a pdf, draw on it and save it to disk. But using beginRaw this way doesn't allow me to set the size / resolution of the pdf file.
Alternatively I can do this :
- PGraphicsPDF pdf;
- pdf = (PGraphicsPDF)createGraphics(paper_x, paper_y, PDF, "find.pdf");
- pdf.beginDraw();
- // do some stuff with pdf as the graphics canvas
- pdf.endDraw();
But there must be another way of achieving this if you aren't using the beginRaw / endRaw methods.
cheers
phil
Update :
I should mention. If I just try to do a
pdf.save("fileName.pdf");
after the pdf.endDraw() I get the following exception :
- java.lang.RuntimeException: No save() for PGraphicsPDF
- at processing.pdf.PGraphicsPDF.nope(Unknown Source)
- at processing.pdf.PGraphicsPDF.save(Unknown Source)
Clearly, something in Processing's PDF library knows how to write a PDF file. But it seems that that knowledge hasn't been incorporated into the PGraphicsPDF class.
1