We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpOther Libraries › howto write layers into a pdf file
Page Index Toggle Pages: 1
howto write layers into a pdf file (Read 1634 times)
howto write layers into a pdf file
Mar 10th, 2008, 10:19pm
 
is there a (simple) way to write objects into layer within a pdf ?

any hints ?
thanks
Floris
Re: howto write layers into a pdf file
Reply #1 - Jun 11th, 2009, 1:06am
 
i came just to the same question. ...did you find any answers yet?
Re: howto write layers into a pdf file
Reply #2 - Jun 11th, 2009, 8:05am
 
hack follows (shown as a per-sketch hack, build it as a library if you'd rather):

1.  browse thru the p5 libraries folder to find the source PGraphicsPDF.java
2.  copy that into your sketch folder as MyGraphicsPDF.java
3.  open the sketch, activate the MyGraphicsPDF.java tab
4.  delete the "package processing.pdf;" statement
5.  change the class name def and constructor from "P.." to "My.."
6.  add the following two functions at bottom of class:
 public void createAndBeginLayer(String name) {
   PdfLayer layer = new PdfLayer(name, writer);
   content.beginLayer(layer);
 }
 public void endLayer() {
   content.endLayer();
 }

When recording to pdf do something like this:
MyGraphicsPDF pdf;
pdf = (MyGraphicsPDF)beginRecord("MyGraphicsPDF", "out.pdf");

Then to draw stuff onto unique layers:

pdf.createAndBeginLayer("lines");
// draw some lines
pdf.endLayer();
pdf.createAndBeginLayer("circles");
// draw some circles
pdf.endLayer();
endRecord();

If you wanted to get fancier you could break apart createLayer() (returning a PdfLayer) and beginLayer(PdfLayer) so that you can interleave your drawing to various layers, but you'll also need a reference to the lowagie stuff in your sketch.

hth
Re: howto write layers into a pdf file
Reply #3 - Jun 11th, 2009, 8:59am
 
thank you dave! ...i'll check it
Page Index Toggle Pages: 1