I found some documentation on how to do this with the library that Processing uses to handle PDF functionality. I need access to the PGraphicsPDF.document element, but it is a protected element.
import processing.pdf.*;
class myPDF extends PGraphicsPDF {
com.lowagie.text.Document getDocument(){
return document;
}
}
void setup(){
myPDF p = createGraphics(100,100,PDF);
}
So I try to extend the PGraphicsPDF class and add a method to get access to the element. I don't have enough java experience to tackle this issue. Any ideas?
No, I still need to modify the Processing source code to access the element, and the libraries used in that example are from 2007 and are no longer the same.
PGraphicsPDF is a bit more extensible than at the time, so perhaps you can make a sub-class of it to add this functionality. I did that in the past to get the PDF result in memory (not on disk), to send it as a byte array to a server. The first hack was complex, it became trivial later.
That was just the results of my trying all different parameters for background and fill and stroke prior to adding the paragraph(anchor) to the document. I do specify the Color of the Anchor (0,0,255) at the end of the Anchor constructor.
I presume Processing is changing all the text into shapes, and rendering them directly to the document as if they were any other type of graphical element.
Processing just relies on the capability of iText of transforming Java2D calls to PDF code... So it just draw on an iText implementation of Java2D's Graphics2D instead of drawing on a pure Java2D's Graphics2D.
Answers
I found some documentation on how to do this with the library that Processing uses to handle PDF functionality. I need access to the PGraphicsPDF.document element, but it is a protected element.
So I try to extend the PGraphicsPDF class and add a method to get access to the element. I don't have enough java experience to tackle this issue. Any ideas?
Hi! Does this help? http://toxi.co.uk/blog/2007/08/creating-weblinks-in-pdf-with-itext.htm
No, I still need to modify the Processing source code to access the element, and the libraries used in that example are from 2007 and are no longer the same.
PGraphicsPDF is a bit more extensible than at the time, so perhaps you can make a sub-class of it to add this functionality. I did that in the past to get the PDF result in memory (not on disk), to send it as a byte array to a server. The first hack was complex, it became trivial later.
PhilLho, your example was exactly what I was looking for.
pdfTest.pde:
myPDF.java
This creates a PDF file, and the text (with link!!) is added, but the text is not visible unless I highlight it. It's super weird.
I think the p.fill(0) is Processing specific and might not be used by the Document. You might need to set the color of the Anchor the iText way.
Ah, also, you draw black text on black background?
That was just the results of my trying all different parameters for background and fill and stroke prior to adding the paragraph(anchor) to the document. I do specify the
Color
of the Anchor (0,0,255) at the end of theAnchor
constructor.I presume Processing is changing all the text into shapes, and rendering them directly to the document as if they were any other type of graphical element.
It worked when I removed the Processing's background() and fill() calls...
font1 isn't really necessary, mostly here for experimentation.
For the life of me, I can't find the lines of code that actually do the heavy lifting for drawing shapes in PDF mode.
Where would I find this?
Processing just relies on the capability of iText of transforming Java2D calls to PDF code... So it just draw on an iText implementation of Java2D's Graphics2D instead of drawing on a pure Java2D's Graphics2D.