Forum Bugs

Migrating from Prince 7.0 to 9.1

anat28dec
We are trying to migrate our application (written in java) from Prince 7.0 to 9.1. We have installed the never version and upgraded the jar to the one shipped with 91.

Looks like instead of generating a good pdf it is printing out html source in the pdf (output attached). Please advise if there are additinal changes needed in our java code?

The java code is fairly straightforward

Prince princeExe = new Prince(princeExePath);
princeExe.setLog(logFilesPath + logger.currentFileName);
princeExe.addStyleSheet(invoiceCssFile);
princeExe.convert(invoiceTemplateFileNameWithPath);
  1. Prince 9.pdf59.8 kB
mikeday
Does it work if you run Prince from the command-line on the same file? And what is the file extension of the file?
anat28dec
Extension of the file is .html. I have not tried through command line but through Prince UI it generates correct pdf.
mikeday
That is very strange. It would be helpful if you could try from the command-line, as it really should behave the same way as when it is called from the Java wrapper.
anat28dec
Could you provide the exact command and its options. Is there a way we could get into a screen share and show you this issue in action during EST day time?
mikeday
The exact command based on your Java code above would be:
c:\program files\prince\engine\bin\prince --log=LOG.TXT --style=INVOICE.CSS INPUT.HTML

Where the file names are changed as appropriate.

I'm not sure how to set up screen sharing, and we are in AEST, so it might be easier to just send me the log output, HTML input, and PDF. :)
anat28dec
Below is the command we used

"C:\Program Files (x86)\Prince\Engine\bin\prince" --log=c:\LOG.TXT --style=C:\Work\eInvoicing\web/css/invoice.css C:\Users\stiwari\Desktop\test.html

Html and pdf file attached (PDF looks perfect here) but when called from java it does not look good (Already provided bad copy)

Log file also attached.

  1. LOG.TXT0.1 kB
  2. test.html5.6 kB
  3. test.pdf633.6 kB
mikeday
That output looks fine, so it is difficult to understand why it would not work when called from the Java wrapper, unless the input file has been modified in some way. The output PDF file that you posted earlier (Prince 9.pdf) has been modified by iText, is this relevant?
anat28dec
It is not relevant. We use itext to finally sign the pdf file generated by prince. There is no way input file can be modified as it is generated programmatically and is deleted once pdf is generated. Whole setup has been working fine in production for years, We started seeing this issue when we though to migrating to newer version of prince. I will have to make a decision by mid next week. If this is not resolved then we would like to stay as it is with Prince 7.x
mikeday
The only way we can reproduce the problem you are experiencing is if the input HTML document is using UTF-16 encoding. Do you know if this is the case?
anat28dec
That does not appear to be the case. We use UTF-8.
mikeday
Are you sure? The first two bytes in the PDF you sent are þÿ which is 0xFF 0xFE, the UTF-16 byte order mark. (The UTF-8 byte order mark is 0xEF 0xBB 0xBF).

Can you reproduce this issue and send me the input HTML document?
anat28dec
That helped. In our code, we were writing the help file as utf-16
OutputStreamWriter osw = new OutputStreamWriter(new FileOutputStream(invoiceTemplateFileNameWithPath, true), "UTF-16");
Changing it to
OutputStreamWriter osw = new OutputStreamWriter(new FileOutputStream(invoiceTemplateFileNameWithPath, true), "UTF-8");

fixes the issue. Thanks for your help.
mikeday
Great, good to hear. We will see if we can improve the handling of UTF-16 in Prince, as it would have been helpful to at least have got a warning message or something other indication of what was going on.
mikeday
We have now released Prince 10, which includes support for UTF-16 in HTML documents.