Re: Making Links in PDF



On 18.02.2009 11:54:04 useratnab wrote:
>
> Hey Jeremias,
>
> thanks for looking on it.
> My intension is to add some internal links from one page to another like it
> is done with pdfmarks in ps-files. I'm drawing some "shapes" on a JPanel and
> these are painted onto the PDFDocumentGraphics2D. Now there should be a
> frame around the shape, where a user can click on it to get redirected onto
> another page in the pdf where there is a detailed view of that shape.
>
> Somehow
> pdf2D.addLink(rect, Tx, "/FitR", 1);
>
> won't work either.

Yeah, it should be something like :
pdf2D.addLink(rect, Tx, "0 0 595 842", 1);

The four values make up the window for /FitR (which is implicit).

Here's a complete example I wrote to test this:

File outputFile = new File("D:/out.pdf");
OutputStream out = new java.io.FileOutputStream(outputFile);
out = new java.io.BufferedOutputStream(out);
try {
PDFDocumentGraphics2D g2d = new PDFDocumentGraphics2D();
g2d.setDeviceDPI(PDFDocumentGraphics2D.NORMAL_PDF_RESOLUTION);
g2d.setGraphicContext(new GraphicContext());
Dimension pageSize = new Dimension(595, 842); //A4
g2d.setupDocument(out, pageSize.width, pageSize.height);

AffineTransform pdfInitialTransform = new AffineTransform(
1, 0, 0, -1, 0, pageSize.height);

g2d.translate(20, 20);

Rectangle rect = new Rectangle(20, 20, 40, 50);
g2d.setColor(Color.BLUE);
g2d.fill(rect);

AffineTransform tx = new AffineTransform(pdfInitialTransform);
Rectangle2D targetRect = rect;

//Works:
//g2d.addLink(targetRect, tx, "http://www.apache.org";,
PDFLink.EXTERNAL);
//Doesn't work
//g2d.addLink(targetRect, tx, "[/XYZ 0 0 null]", PDFLink.INTERNAL);
//Works:
g2d.addLink(targetRect, tx, "0 0 595 842", PDFLink.INTERNAL);


g2d.finish();
} finally {
IOUtils.closeQuietly(out);
}


> Thanks Tim
>
>
>
> Jeremias Maerki-2 wrote:
> >
> > Finally got to look into that. Two things:
> >
> > 1. There was a bug in PDFFactory that caused the bug you mention. I've
> > just fixed that: http://svn.apache.org/viewvc?rev=744690&view=rev
> > But that only really fixes part of a problem with SVG #svgView(viewBox())
> > functionality (as mentioned in the commit message). For reference, the
> > SVG test case to reproduce the problem can be found here:
> > http://svn.apache.org/repos/asf/xmlgraphics/batik/trunk/samples/tests/spec/linking/linkingViewBox.svg
> >
> > 2. But you seem to want to use PDFDocumentGraphics2D outside an SVG
> > context. Looking at the code I don't think that was foreseen. The code
> > covers only the functionality required by above-mentioned #svgView stuff,
> > either external links or the viewBox() method (FitR in PDF). Things like
> > /XYZ cannot be done using PDFGraphics2D.addLink at the moment. For that,
> > the code would have to be refactored.
> >
> > If you pass "0 0 10 10" (or other 4 integers representing arguments to
> > the /FitR function) as "dest" parameter into addLink(), it should work.
> > But specifying the function itself will lead to errors in Acrobat Reader.
> >
> > Patches to improve that (and above SVG problem) are welcome.
> >
> > On 13.02.2009 12:05:17 useratnab wrote:
> >>
> >> Hello,
> >>
> >> I get an "Exception in thread "AWT-EventQueue-0"
> >> java.lang.IllegalArgumentException: Cannot reference this object. It
> >> doesn't
> >> have an object number"
> >>
> >> Is there somehting wrong with using "addLink"?
> >>
> >> <pre>
> >> PDFDocumentGraphics2D pdf2D;
> >> AffineTransform Tx = new AffineTransform( 1, 0, 0, 1, 0, 0);
> >>
> >> Rectangle2D rect = new Rectangle2D.Double ();
> >> rect.setRect (20., 20., 100., 50.);
> >>
> >> // 0 --> other files
> >> // 1 --> another pos in same file
> >> // 2 --> URL
> >> pdf2D.addLink(rect, Tx, "[/XYZ 0 0 null]", 1);
> >> </pre>
> >>
> >> Thank you
> >> Tim
> >> --
> >> View this message in context:
> >> http://www.nabble.com/Making-Links-in-PDF-tp21994320p21994320.html
> >> Sent from the FOP - Users mailing list archive at Nabble.com.
> >>
> >
> >
> >
> > Jeremias Maerki
> >
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: fop-users-unsubscribe@xxxxxxxxxxxxxxxxxxxxxx
> > For additional commands, e-mail: fop-users-help@xxxxxxxxxxxxxxxxxxxxxx
> >
> >
> >
>
> --
> View this message in context:
> http://www.nabble.com/Making-Links-in-PDF-tp21994320p22076342.html
> Sent from the FOP - Users mailing list archive at Nabble.com.
>
>




Jeremias Maerki


---------------------------------------------------------------------
To unsubscribe, e-mail: fop-users-unsubscribe@xxxxxxxxxxxxxxxxxxxxxx
For additional commands, e-mail: fop-users-help@xxxxxxxxxxxxxxxxxxxxxx



Privacy