TedYoung has asked for the wisdom of the Perl Monks concerning the following question:

Hello Fellow Monks,

I have a system in Java that tranforms XML documents into SVG, and prints them (to a card printer). The Java SVG rendering/printing library Batik has had very little advancement over the last four years (I am not complaining, I haven't contributed myself! ;-> ) and I am starting to want newer SVG features (like text wrapping). Also, Batik seems to have problems with newer versions of Java.

So I want to convert this over to Perl, because I heard rumors that Image::Magick will rasterize SVG. Now, I will test that tomorrow morning when I get back to work. They only thing really holding me up is a way to print the rasterized image to the card printer (which uses a windows print driver).

Now, you want to go mad? Try searching for how to print in perl (or perl printing) on Google. Thanks to our keyword print and the notion of printing to a browser/file, this is a tedious task.

I have found some PerlMonk nodes suggesting the easiest way to print a file in Windows is with system "print foo.jpg". That would require me to associate a particular image file with something that would do a good job printing. Worse, I need to raster two images, one for the front and one for the back of the card (duplex printing, which the driver supports -- I just have to send it two "pages").

This is a Windows only thing and I have complete control over the env. But I would like to be able to wrap the final product in PAR. I am definately open to a Win32::OLE solution. I have also looked at Win32::Printer but felt like it was a little too low-level (though it may be the best choice). Alternatively, should I consider converting the image data to some standard, which I could dump directly to the printer? What would that standard be? Can you open a ethernet printer port using open?

Update: To take a step back for a second, I really don't need to rasterize the SVG. In fact, it would improve my print quality if the text was sent to the printer as TrueType. So, if anyone knows of a way to print the SVG more directly, I am interested in that too.

Thanks for the help!

Ted Young

($$<<$$=>$$<=>$$<=$$>>$$) always returns 1. :-)

Replies are listed 'Best First'.
Re: Printing in Duplex on Windows
by albert (Monk) on Jun 08, 2006 at 02:43 UTC
    To rasterize SVG, I've used Image::LibRSVG in the past. This module may not support all the features you would like to see. Also, I'm not sure if LibRSVG compiles on Windows.

    I hope this might be helpful in some small way, even though it might not solve your problem in the end.

    -albert

Re: Printing in Duplex on Windows
by bigmacbear (Monk) on Jun 09, 2006 at 00:03 UTC

    Alternatively, should I consider converting the image data to some standard, which I could dump directly to the printer? What would that standard be? Can you open a ethernet printer port using open?

    I have had good luck taking .ps files off my Unix systems and running them through a batch file which just copies them to the device:

    @echo off rem This batch file is used to send pre-formatted PostScript documents rem to the printer \\SERVER\PRINTER. It is intended to be used as the rem "print" option for .ps files. copy %1 \\SERVER\PRINTER

    It occurs to me that if some module exists to create PostScript output (or whatever language your printer understands) from the images you are rendering, that you could just open the UNC name of the printer as a file and write directly to it.

Re: Printing in Duplex on Windows
by digger (Friar) on Jun 09, 2006 at 00:27 UTC

    My first questions would be what kind of printer are you using, and how is it connected? This will effect the kinds of solutions available to you.

    bigmacbear had a great idea, but I wasn't able to find any software to convert svg to postscript. Based on what I read, converting SVG to PS is problematic because of issues like transparency. And if Ted doesn't have a postscript capable printer, the postscript solution won't work.

    You could try converting the SVG to PDF using something like Altsoft XML2PDF, a $49 utility with a command line processor to make a pdf. Then you can use a system call to Acrobat to print the file.

    You can solve the duplexing issue by creating another instance of your printer with the default set to duplex. When you print, make sure you are printing to this special instance of the printer, and your job will be duplexed.

    Gotta run to hang out with the kids a little bit. If I can provide more info later, I will

    Quick Update: You can check out this page PlanetPDF to see the command line options for printing from Acrobat.

    digger