Title: printing multiple page svg image.

To whomever is concerned,


I’ve written a transcoder similar to the PrintTranscoder, except instead of printing a single page, it breaks the image (vertically) into multiple pages and prints each one in turn.  It only handles one image and the transcode method is only called once,  before print is called.

So I have an SVG file such as:

<svg  xmlns="&ns_svg;" xmlns:xlink="&ns_xlink;" xmlns:a="http://ns.adobe.com/AdobeSVGViewerExtensions/3.0/"

     width="574" height="2400" x="0" y="0" viewBox="0 0 574 2400">

   

        <g id="Page1">

       

        </g>

        <g id="Page2" transform="translate(0, 800)">

            …

        </g>

        <g id="Page3" transform="translate(0, 1600)">

           …

        </g>

</svg>

Each <g> element contains more or less the same graphics with slightly different data.

The relevant code in the Printable.print method of the transcoder is:

        double d = pageFormat.getImageableWidth() / pageWidth; // pageWidth=574

        double d1 = pageFormat.getImageableHeight() / pageHeight; // pageHeight=800

        /**

         * We are translating the image to the correct coordinates for the page.  This

         * includes moving the y coordinate up for each page already printed, so the

         * printable area will only contain the current page.  We also take into consideration

         * the margins of the page (specified by pageFormat.getImageableX() for the horizontal margin

         * and pageFormat.getImageableY() for the vertical margin).

         *

         * Here is each piece explained:

         * pageFormat.getImageableX():  Moves the starting X coordinate to the start of the

         *      horizontal margin.

         *

         * (-(pageHeight) * pageIndex):  Calculates the Y coordinate for the page.  That is it

         * calcuates where to put the top of the image so the correct page is in the printable area.

         *

         * (pageFormat.getImageableY()+4):  The vertical margin adjusted.  I'm not sure why this margin needs adjusting...

         *

         * ((pageIndex * 2) + 1)):  The number of margins to consider so far.  There are too veritcal margins per page

         *      (top and bottom).  Plus the top margin of the current page.

         */

        graphics2d.translate(pageFormat.getImageableX() , (-(pageHeight) * pageIndex) + ((pageFormat.getImageableY()+4) * ((pageIndex * 2) + 1)));

        graphics2d.scale(d, d1);

        //

        // Delegate rendering to painter

        //

        try{

            LOG.debug("Painting");

            root.paint(graphics2d);

            LOG.debug("Done painting");

        }

        catch(Exception e){

            LOG.error(e);

            throw new PrinterException("Failed to draw image.  Error: " + e);

        }


My question is on the code “(pageFormat.getImageableY()+4)” (which is part of the translate method call).

Without the 4, the pages drift upwards, so that the 3rd page starts above the top margin (and that part of the image isn’t printed).  Why is this?  Am I missing something?

Thanks,

Tom

Reply via email to