Forum Bugs

Issue in rendering graph

sujithbabu
Hi
I have an issue in rendering bar graph from Prince. I have attached a very basic HTML definition with the SVG chart and the Prince generated PDF. Please see that the graph attached is not rendering correctly.

Thanks in Advance
Sujith Babu
EnvestNet
  1. prince-svg.pdf24.0 kB
    PDF
  2. prince-svg.xml19.5 kB
    XML
mikeday
That's strange, it renders fine here. Which operating system are you running Prince on?
sujithbabu
Windows 7 Enterprise
mikeday
Does it still fail if you try rendering the document exactly as is from the command-line, eg.
> prince prince-svg.xml

without applying any other CSS style sheets, or specifying any other command-line options?
sujithbabu
No. PFA png image
  1. FromCommand-Line.png19.6 kB
mikeday
So in what situation does it fail?
sujithbabu
When i generated it from my solution. But please note that i got the correct image when I change the y axis point from 476 to 250. PFA diff
  1. Change.png56.4 kB
mikeday
This doesn't seem to have any effect for me. Can you make it fail from the command-line? How is your solution different, are you applying additional style sheets? Are you using one of the server wrappers?
sujithbabu
Hi Mike,

I am not using any other style for rendering this xml. But the issue is there only when I am using "prince-svg_1.xml" (xml attached). The chart is rendering correctly when I use "revised-prince-svg.xml".

Code using to render
private byte[] writeToPrincePDF(String xml, String url, coreBarCode barCode) throws Exception
{
xml = readFileAsString("D:/Projects/UMPDev/workspace/ump/openwrap/secure/prince-svg_1.xml");
// Resolve the base URL
String baseURL = (isHttps) ? "https://" : "http://";
if (coreCommon.isDevelopment()) {
baseURL = baseURL + "localhost";
} else {
baseURL = baseURL + serverName;
}

Prince prince = new Prince("prince.exe", new PrinceEventHandler());
prince.setHTML(true);
prince.setBaseURL(baseURL);

StringBuffer exceptionMessage = new StringBuffer();

int dumpDebugLevel = (exceptionMessage.length() > 0 ? coreCommon.DEBUG_LEVEL_ERROR : coreCommon.DEBUG_LEVEL_INFO);
coreCommon.debugDumpContent(xml, "pdf", ".xml", exceptionMessage, dumpDebugLevel);

// Render the PDF to a byte array
ByteArrayInputStream xmlin = new ByteArrayInputStream(xml.getBytes());
ByteArrayOutputStream out = new ByteArrayOutputStream();
prince.convert(xmlin, out);

return out.toByteArray();
}

From my observation of comparing the 2 xml what I understood is as follows:
NB: Please correct me if I am wrong here :-)

The original SVG/XML ("prince-svg_1.xml") includes instructions to draw several lines along the Y axis from point 244 to 476. Since the chart area only extends along the Y axis to point 280, the lines to point 476 extend far beyond the area we want to draw

Thanks,
Sujith
  1. prince-svg_1.xml19.5 kB
    Issue in rendering
  2. revised-prince-svg.xml19.5 kB
    Chart rendering correctly
mikeday
First thing is you may not want to call setHTML(true), as this is not an HTML document, it is an SVG document, and should be parsed as XML. I would suggest calling prince.setInputType("xml") to ensure that it is handled as an XML document.
sujithbabu
Yes..Now I got it correctly. Thanks fo you input Mike

Sujith
sujithbabu
Hi Mike,

One more question here

We do use the generator in an HTML environment, so I am not sure whether your suggestion would help.
The sample files I had attached were files I had manually created to try to simplify the problem for submission in the forum.

PFA txt file (which basically is a html page) we use to genrate PDF. Here we are setting "prince.setHTML(true);".

Attached PDF genrated from this file which have issues in chart.

Thanks in advance,
Sujith
  1. PDF_genrated_issue.pdf24.5 kB
    PDF generated with issue
  2. Test_html.txt21.6 kB
    File
mikeday
Okay, nesting SVG directly inside HTML will not work unless you use the new HTML5 parser, which can be enabled by calling prince.setInputType("html5") instead of prince.setHTML(true). Or you can upgrade to Prince 9.0, just released this afternoon, which uses the HTML5 parser by default. :)
sujithbabu
Also please note that when I generate the PDF from IE, I was able to render PDF correctly (The chart was rendering prefectly in IE). The issue in chart, I attached in my last mail is when generated from Chrome.
sujithbabu
Thank Mike for your reply. I tried generating PDF with the suggested change. But agin I got one issue while generating from chrome. There is a white space in chart when I generated from Chrome. PFA "diff.png". You can find portion marked in red (white space)
  1. diff.png84.5 kB
    Diff in IE and Chrome
mikeday
Do you have the source files generated from IE and from Chrome? It looks like a viewBox issue, but it is hard to diagnose without seeing the source.
sujithbabu
Hi Mike,

PFA txt file used to generate the PDF. Attached PDF generated from IE and Chrome.
One thing which i notice is in IE browser the chart is rendering as <img src (we are not rendering the chart as SVG); while in chrome it's as svg.
  1. PDF_Chrome.pdf28.8 kB
  2. PDF_IE9.pdf38.5 kB
  3. pdf_Chrome.txt23.8 kB
  4. pdf_IE9.txt18.2 kB

Edited by sujithbabu

sujithbabu
The issue occurs only when we render the chart in SVG format. For IE browsers we are not rendering the chart as SVG and hence the issue is not there.

Edited by sujithbabu

mikeday
I don't have the style sheets, but when I convert pdf_Chrome.txt to PDF with Prince 9.0 I get the PDF file below, which looks fine.
  1. chrome.pdf32.0 kB
sujithbabu
Hi Mike,

I was on leave for the last 2 days. Will update you once I generate the PDF in pince 9.0
sujithbabu
Mike,

It works for pince 9.0. But I got a different issue here. "style defined with rgb" is rendering as html in pince 9.0
Attached : html used and PDF generated using 8.1 and 9.0. Note that PDF generated using 9.0 is not rendering correctly
Note that the issue is there in Prince 8.1, if we use InputType as “html5”

Code used:
    private byte[] writeToPrincePDF(String xml, String url, coreBarCode barCode) throws Exception
    {
        // Resolve the base URL
        String baseURL = (isHttps) ? "https://" : "http://";
        if (coreCommon.isDevelopment()) {
            baseURL = baseURL + "localhost";
        } else {
            baseURL = baseURL + serverName;
        }

        Prince prince = new Prince("prince.exe", new PrinceEventHandler());
        prince.setHTML(true);
        prince.setBaseURL(baseURL);

        StringBuffer exceptionMessage = new StringBuffer();

        int dumpDebugLevel = (exceptionMessage.length() > 0 ? coreCommon.DEBUG_LEVEL_ERROR : coreCommon.DEBUG_LEVEL_INFO);
        coreCommon.debugDumpContent(xml, "pdf", ".xml", exceptionMessage, dumpDebugLevel);

        // Render the PDF to a byte array
        ByteArrayInputStream xmlin = new ByteArrayInputStream(xml.getBytes());
        ByteArrayOutputStream out = new ByteArrayOutputStream();
        prince.convert(xmlin, out);

        return out.toByteArray();
    }
 
  1. pdf.html8.4 kB
    Html Used
  2. prince8.1_wokingfine.pdf27.8 kB
  3. prince9.0_issue.pdf28.2 kB

Edited by mikeday

mikeday
It looks like the missing semicolon after the character references is tripping up the new HTML5 parser, we will investigate this issue. In the meantime, the best solution is to add semicolons, eg. like this:
&#x25cf;
sujithbabu
Thanks Mike. I will try this.
But please investigate If the issue can be resolved in prince 9.0. (as this issue is not there in older version, even we are not giving semi colons)

Thanks In Advance
Sujith
mikeday
Yes, Prince 9 uses the HTML5 parser by default, whereas in Prince 8.1 you have to explicitly set "html5" as the input type.
sujithbabu
Mike, It woks when we add semi column.
But please try, if there is any option to avoid this, since we need to change code for this in lot of places.
mikeday
What if you use Prince 9 and set "html4" as the input type, to get the old parsing behaviour? If this works, then you can use that until we can fix the semicolon issue.
sujithbabu
Mike, It worked. But we have a small issue :-)
PFA image
  1. issue_07042013.png40.3 kB

Edited by sujithbabu

mikeday
Okay, seems we are going around in circles. We will hurry to fix the semicolon issue, then you can use the new HTML parser, and everything will be fine. If you would like to email me (mikeday@yeslogic.com), I will arrange an updated Prince build to try.
sujithbabu
Sure Mike.

Thanks,
Sujith
mikeday
We have now released Prince 9 rev 2, which fixes the issues affecting HTML entities that are not followed by semicolons.
sujithbabu
Thanks Mike for the update. I have downloaded prince 9 yesterday. We will upgrade this exe in our poduction servers.

Thanks,
Sujith