xmlgraphics-batik-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bugzi...@apache.org
Subject DO NOT REPLY [Bug 51105] New: Generating PDF using iText and PrintTranscoder ignores translucent shapes
Date Fri, 22 Apr 2011 10:22:01 GMT
https://issues.apache.org/bugzilla/show_bug.cgi?id=51105

           Summary: Generating PDF using iText and PrintTranscoder ignores
                    translucent shapes
           Product: Batik
           Version: 1.6
          Platform: PC
            Status: NEW
          Severity: major
          Priority: P2
         Component: GVT
        AssignedTo: batik-dev@xmlgraphics.apache.org
        ReportedBy: jan.krakora.cz@gmail.com


I have a JPanel containing a graph (it's the JFreeChart's ChartPanel). It
contains few bars, lines, texts, and also translucent rounded rectangles. 
I need to insert this graph into PDF report generated by Eclipse BIRT. So I
have to transform my graf into an SVG image and put it into the BIRT.

It's done by this Batik code:

        DOMImplementation domImpl =
GenericDOMImplementation.getDOMImplementation();
        Document document =
domImpl.createDocument("http://www.w3.org/2000/svg", "svg", null);

        // Create an instance of the SVG Graphic
        SVGGraphics2D svgGraphic = new SVGGraphics2D(document);

        // draw the chart in the SVG generator
        Rectangle2D bounds = new Rectangle(100, 500);
        chart.draw(svgGraphic, bounds);

        // Write svg file
        ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
        Writer out = new OutputStreamWriter(outputStream, "UTF-8");
        svgGraphic.stream(out, true /* use css styles */);
        outputStream.flush();
        outputStream.close();
        byte[] svgData = outputStream.toByteArray();

So I have the SVG in form of byte array. Ok, now I give this array to the
Eclipse BIRT Framework. I did some investigation and I found that BIRT uses 
the code below to insert an svg image into PDF report(of course it's a bit
adapted for this bug report and to enable me to provide some results):

        byte[] svgData = ... viz the code above
        File fileName = new File("C:\\bad.pdf");

    OutputStream out = new BufferedOutputStream(new
FileOutputStream(fileName));

    com.lowagie.text.Rectangle pagesize = new com.lowagie.text.Rectangle(1000,
500);
    com.lowagie.text.Document document = new
com.lowagie.text.Document(pagesize, 50, 50, 50, 50);
    PdfWriter writer = PdfWriter.getInstance(document, out);
    document.open();

    PdfContentByte contentByte = writer.getDirectContent();
    PdfTemplate template = contentByte.createTemplate(1000, 500);
    Graphics2D g2D = template.createGraphics(1000, 500);

    PrintTranscoder transcoder = new PrintTranscoder();
    transcoder.transcode(new TranscoderInput(new ByteArrayInputStream(data)),
null);
    PageFormat pg = new PageFormat();
    Paper p = new Paper();
    p.setSize(1000, 500);
    p.setImageableArea(0, 0, 1000, 500);
    pg.setPaper(p);
    transcoder.print(g2D, pg, 0);
    g2D.dispose();
    contentByte.addTemplate(template, 0, 0);

    document.close();
    out.close();

The resulting PDF really contains my graph, but it absolutely ignores
translucent shapes as you can see in the attached file "bad.pdf".
So I did "my way" PDF generation directly with the iText:

        File fileName = new File("C:\\good.pdf");
        OutputStream out = new BufferedOutputStream(new
FileOutputStream(file));

        com.lowagie.text.Rectangle pagesize = new
com.lowagie.text.Rectangle(1000, 500);
        com.lowagie.text.Document document = com.lowagie.text.new
Document(pagesize, 50, 50, 50, 50);

    PdfWriter writer = PdfWriter.getInstance(document, out);
    document.open();
    PdfContentByte cb = writer.getDirectContent();
    PdfTemplate tp = cb.createTemplate(1000, 500);
    Graphics2D g2 = tp.createGraphics(1000, 500, new DefaultFontMapper());
    Rectangle2D r2D = new Rectangle2D.Double(0, 0, 1000, 500);
    chart.draw(g2, r2D);
    g2.dispose();
    cb.addTemplate(tp, 0, 0);

    document.close();
        out.close();

As you can see I the part with the PrintTranscoder is skipped and graph is
drawn directly to the PDF using iText's Graphics implementation. 
See the attached file "good.pdf". The result is perfect. I thought that the
generated SVG can be broken, but saving it as SVG file and 
opening it in the GIMP for example give me good results. So the problem must be
somewhere in the PrintTranscoder.

-- 
Configure bugmail: https://issues.apache.org/bugzilla/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the assignee for the bug.

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


Mime
View raw message