Hi Guys :-)
This is more a question for SVG afficionados, but at this point i'll take
any assistance !
I am trying to plumb bits together instead of re-inventing wheels.
My task is to generate thumbnail images from pdf documents.
To this end I have tried both JPedal and Snowbound.
Each has drawbacks (either financial or performance).
So, I have looked at the SVG world.
STEP 1:
I found a (commercial) product , pdfgo, which will convert a PDF to a valid
SVG xml document.
STEP 2a:
I then piped this xml doc thru to Batik.
I used code snippets like this for creating an internal SVGDocument.
It appears to be successful (I can at least read some key elements such as
doc width and height)
<quote>
SVGDocument outDoc = null;
String parser = XMLResourceDescriptor.getXMLParserClassName();
SAXSVGDocumentFactory f = new SAXSVGDocumentFactory(parser);
try {
outDoc = f.createSVGDocument(null, is);
} catch (Exception e) {
throw new IllegalArgumentException
(e.getMessage());
}
return((SVGDocument)outDoc);
</quote>
STEP 2b:
I looked thru Batik for a thumbnail api but could not find one.
Then, i looked at the ThumbnailDialog class in the Squiggle-App and saw a
snippet which builds a suitable AffineTransform.
I ended up with the code below; you'll see some *strong* similarity to the
batik codebase :-)
You'll notice also that i have left in commented-calls which batik the
ThumbnailDialog class makes.
As soon as i hit the JGVTComponent class, I stopped delving deeper.
Our functionality is a server-side event, so no on-screen images (hence the
potential difficulty with the batik-squiggle code reuse).
And, I am not particularly 2D or SVG savvy.
As i followed the batik code i could see that there are custom event
dispatchers and listeners for a lot of the threaded repainting, so rather
than try to skin this cat, i thought the authors (esp) might be able to help
out :-)
The point i guess is that we have no (backing or thumbnail) image canvas in
our own scope, so.....??
Any soultions or pointers you could offer would be most appreciated :-))
<quote>
protected BufferedImage updateThumbnailRenderingTransform(SVGDocument
svgDocument)
{
if (svgDocument != null)
{
//some thumbnail props i hold internally
ThumbnailProperties tprops = getThumbnailProperties();
Dimension dim = new Dimension(tprops.getWidth(),
tprops.getHeight());
SVGSVGElement root = svgDocument.getRootElement();
AffineTransform Tx = ViewBox.getViewTransform(null, root, dim.width,
dim.height);
if (Tx.isIdentity())
{
String width =
svgDocument.getDocumentElement().getAttribute(SVGConstants.SVG_WIDTH_ATTRIBU
TE);
String height =
svgDocument.getDocumentElement().getAttribute(SVGConstants.SVG_HEIGHT_ATTRIB
UTE);
double sx = dim.width / Integer.parseInt(width);
double sy = dim.height / Integer.parseInt(height);
double s = Math.min(sx, sy);
Tx = AffineTransform.getScaleInstance(s, s);
return(getImage(dim, Tx));
}
// svgThumbnailCanvas.setRenderingTransform(Tx);
// overlay.synchronizeAreaOfInterest();
}
return(null);
}
private BufferedImage getImage(Dimension dim, AffineTransform
paintingTransform)
{
AffineTransform invert = null;
try
{
invert = paintingTransform.createInverse();
}
catch (NoninvertibleTransformException e)
{
log.error(e.getMessage());
}
BufferedImage image = new BufferedImage(dim.width, dim.height,
BufferedImage.TYPE_BYTE_BINARY);
Graphics2D g2d = image.createGraphics();
if (image != null)
{
if (paintingTransform != null)
{
g2d.transform(paintingTransform);
}
g2d.drawRenderedImage(image, null);
// Iterator it = overlays.iterator();
// while (it.hasNext()) {
// ((Overlay)it.next()).paint(g);
// }
}
return(image);
}
</quote>
Best Regards & mtia
Julian Salerno
Amcor iSpek Project
CAUTION - This message may contain privileged and confidential information intended
only for the use of the addressee named above. If you are not the intended recipient
of this message you are hereby notified that any use, dissemination, distribution or
reproduction of this message is prohibited. If you have received this message in error
please notify AMCOR immediately. Any views expressed in this message are those of the
individual sender and may not necessarily reflect the views of AMCOR.
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]