You are viewing a plain text version of this content. The canonical link for it is here.
Posted to batik-users@xmlgraphics.apache.org by André Santos <aa...@gmail.com> on 2005/12/27 19:42:06 UTC

Problem when printing SVG

Hello,

I started using SVG and Batik only a few days ago, so this is all very
new stuff to me. I managed to work through the very basics of Batik to
display and manipulate SVGs using JSVGCanvas (what a great component!)
, but now I'm stuck in printing and the Transcoder API.

I first tried using the code found in Squiggle to print, but it took
an awful long time and was too resource-hungry. Besides that, it
cropped the lower-left corner of the image.

When I was browsing the list archives I found the following code,
which uses the Java printing API:

PrinterJob printerJob = PrinterJob.getPrinterJob();
PageFormat pageFormat = printerJob.defaultPage();
PrintTranscoder prm = new PrintTranscoder();
TranscoderInput ti = new TranscoderInput(svgCanvas.getSVGDocument());
prm.transcode(ti, null);

if (printerJob.printDialog()) {
   printerJob.setPrintable(prm, pageFormat);
   try {
      printerJob.print();
   } catch (Exception e) {
      System.out.println(e.getMessage());
   }
}

This code runs much quicker and also consumes much less resources than
the one from Squiggle, but unfurtunately it produces the same cropping
problem (although it crops only the left side of the image). It also
looks like it doesn't respect the page orientation defined in the
PrintOptions page. So, is there a "right" way of printing using Batik?
Or a preferred way, maybe?

I found several messages from people reporting the same sort of
problems, but none giving actual solutions to them. I realize I should
probably take some time to learn the inner workings of the Transcoder
API, but I would really appreciate some help from people who have
already been there.

BTW, I'm using Batik 1.6 (binary dist), JDK 1.4.2_08, Win2k SP4.

Many thanks in advance for any ideas,

Andre

---------------------------------------------------------------------
To unsubscribe, e-mail: batik-users-unsubscribe@xmlgraphics.apache.org
For additional commands, e-mail: batik-users-help@xmlgraphics.apache.org


Re: Problem when printing SVG

Posted by th...@kodak.com.
André Ávila <as...@nextech.com.br> wrote on 12/30/2005 09:27:37 AM:

> > > TranscoderInput ti = new 
TranscoderInput(svgCanvas.getSVGDocument());
> >
> >    This is bad, this will break your SVGCanvas display if your
> > document is in any way dynamic.
> 
> I don't plan to support dynamic documents at this time, so this should 
not
> be a problem. However I'd like to know what's the alternative way to do 
it
> as to leave that possibility opened. Could you point me any directions?

   You would either have to clone the document or borrow code from
the transcoders and use the GVT tree from the Canvas directly.

> I didn't have a good impression of PDFTranscoder. The output looks 
great,
> but it seems to increase the memory usage of Batik by an unacceptable
> amount. It actually looks like there's a leak, since the used memory 
keeps
> rising all the time. When I removed it from my distribution, memory 
usage
> became much more sensible. Do other people have the same experience?

   Well if you can reproduce the memory leak I'd be interested in looking 
at it...


---------------------------------------------------------------------
To unsubscribe, e-mail: batik-users-unsubscribe@xmlgraphics.apache.org
For additional commands, e-mail: batik-users-help@xmlgraphics.apache.org


Re: Problem when printing SVG

Posted by André Ávila <as...@nextech.com.br>.
Hello Thomas, and thank you for your time.

First of all I feel I should apologize to the list for posting from
different addresses. I was having problems posting with my Gmail account, so
I had to subscribe again with another address. Sorry for the annoyance.


> > TranscoderInput ti = new TranscoderInput(svgCanvas.getSVGDocument());
>
>    This is bad, this will break your SVGCanvas display if your
> document is in any way dynamic.

I don't plan to support dynamic documents at this time, so this should not
be a problem. However I'd like to know what's the alternative way to do it
as to leave that possibility opened. Could you point me any directions?

>    There were some fixes to the handling of margins since the Batik
> 1.6 release.  So I would suggest grabbing the latest sources and
> testing with that.

Indeed, the latest SVN solved the problem. Thank you very much for your
great work.

As a side note, I'd like to point that cropping problems still exist when
printing to PDF using PDF995 driver under certain conditions (the exact
conditions I was testing on, by Murphy's Law), but this is probably too
specific to deserve any attention from you guys. Anyway, it is most likely
an issue with their driver than with your code, so don't bother.

> > So, is there a "right" way of printing using Batik?
> > Or a preferred way, maybe?
>
>   The print transcoder would be it, but I don't know how widely
> used it is.  I think a lot of people generate PDF and then let people
> print that if they want...

I didn't have a good impression of PDFTranscoder. The output looks great,
but it seems to increase the memory usage of Batik by an unacceptable
amount. It actually looks like there's a leak, since the used memory keeps
rising all the time. When I removed it from my distribution, memory usage
became much more sensible. Do other people have the same experience?

Again, thank you very much for your interest. Your help has been invaluable.

Best regards,

André


---------------------------------------------------------------------
To unsubscribe, e-mail: batik-users-unsubscribe@xmlgraphics.apache.org
For additional commands, e-mail: batik-users-help@xmlgraphics.apache.org


Re: Problem when printing SVG

Posted by th...@kodak.com.
Hi André

André Santos <aa...@gmail.com> wrote on 12/27/2005 01:42:06 PM:

> When I was browsing the list archives I found the following code,
> which uses the Java printing API:
> 
> TranscoderInput ti = new TranscoderInput(svgCanvas.getSVGDocument());

   This is bad, this will break your SVGCanvas display if your
document is in any way dynamic.

> This code runs much quicker and also consumes much less resources than
> the one from Squiggle, but unfortunately it produces the same cropping
> problem (although it crops only the left side of the image).

   There were some fixes to the handling of margins since the Batik
1.6 release.  So I would suggest grabbing the latest sources and 
testing with that.

> So, is there a "right" way of printing using Batik?
> Or a preferred way, maybe?

  The print transcoder would be it, but I don't know how widely
used it is.  I think a lot of people generate PDF and then let people
print that if they want...


---------------------------------------------------------------------
To unsubscribe, e-mail: batik-users-unsubscribe@xmlgraphics.apache.org
For additional commands, e-mail: batik-users-help@xmlgraphics.apache.org