saveToPdf problems

Hi,

I’ve encountered a problem when trying to understand and properly use the new saveToPdf feature in Aspose.Words 4.0.0 beta.
In order to create a PDF document out of our template using your library, here is what I do:

exporterDOC = new AWDocExporter();
exporterDOC.setParameter(AWExporterParameter.EXPORT_LINES, true);
exporterDOC.setParameter(AWExporterParameter.PAGE_BREAKS, AWExporterParameter.PAGE_BREAKS_NORMAL);
exporterDOC.setParameter(AWExporterParameter.PAGE_MARGINS, "20px;20px;50px;10px");
exporterDOC.setParameter(AWExporterParameter.RECOGNIZE_FIELDS, true);
output = exportReportToBytes(jasperPrint, exporterDOC, request);

Document tmp = new Document(new ByteArrayInputStream(output));
ByteArrayOutputStream baos = new ByteArrayOutputStream();
PdfOptions options = new PdfOptions();
options.setHeadingsOutlineLevels(3);
options.setExpandedOutlineLevels(1);
options.setTrueTypeFontsFolder(pathAmbienteASP + ".../.../JDK/jre/lib/fonts");
tmp.saveToPdf(0, tmp.getPageCount(), "C:/tmp.pdf", options);
tmp.saveToPdf(0, tmp.getPageCount(), baos, options);
output = baos.toByteArray();

basically it SHOULD work this way:

  1. export the whole compiled report to a byte array named “output”
  2. create a temporary document from that byte array
  3. create the output stream, “baos”, where to save the pdf version of the document
  4. save the document as pdf on the output stream (here also on file for testing)
  5. extract the byte array from the saved outputstream

The problem is that while the file is saved perfectly, the outputstream seems to be empty. What am I doing wrong?

Hi Matteo,

Thank you for reporting this problem to us. I managed to reproduce it on my side. You will be notified as soon as it is resolved.
Best regards.

Ok, we’ll wait then. About this, I’ve also tried to do in a simpler way:

Document tmp = new Document(new ByteArrayInputStream(output));
ByteArrayOutputStream baos = new ByteArrayOutputStream();
tmp.save(baos, SaveFormat.PDF);
output = baos.toByteArray();

but i got an exception doing so:

exception

javax.servlet.ServletException: stream
	SingleReport.CompileReport(SingleReport.java:592)
	SingleReport.processRequest(SingleReport.java:126)
	SingleReport.doPost(SingleReport.java: 188)
	javax.servlet.http.HttpServlet.service(HttpServlet.java:709)
	javax.servlet.http.HttpServlet.service(HttpServlet.java:802)

root cause

java.lang.NullPointerException: stream
com.aspose.words.Document.a(Document.java: 1695)
com.aspose.words.Document.a(Document.java: 1445)
com.aspose.words.Document.save(Document.java: 959)
SingleReport.CompileReport(SingleReport.java: 564)
SingleReport.processRequest(SingleReport.java: 126)
SingleReport.doPost(SingleReport.java: 188)
javax.servlet.http.HttpServlet.service(HttpServlet.java:709)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)

By the way, I wanted to “move” here the conversation from the other topic:

alexey.noskov:
Hi Matteo,
Thanks for your inquiry. Of course, you can use the following code to convert your document to PDF
Document doc = new Document(“C:\Temp\in.doc”);
doc.save(“C:\Temp\in.pdf”);
However, in this case you are unable to specify PdfOptions.
Best regards.

What I cannot understand is the “importance” of setting those options: I’ve just tried to simply remove them and saving the document as you suggest in your example, and the final output seems identical as when the options where set. Can it be the our specific report template does not care about those?

Hi Matteo,

Thank you for additional information. I reproduced the problem with Document.save method as well.
PdfOptions provides you to configure converter. You can learn more about these options here:
https://reference.aspose.com/words/net/aspose.words.saving/pdfsaveoptions/
They are optional, so if you do not need to specify them, you can just put null value instead of PdfOptions.
Best regards.

Hi Matteo,
May I ask why do you use Aspose.Words for JasperReports at first to convert to DOC and then immediately Aspose.Words for Java to convert that DOC to PDF?
If you need to go Jasper -> PDF then you can just export to PDF from Jasper I suppose.

I know that it is possible to generate PDF files directly using jasper reports “plain” class, but the fact is that, because of the way we “build” the two main reports our program must generate (that is, we create many sub-documents and then attach them all in one file), we can keep the global page numbers only in Word thanks to the new field export feature, but we’d lose it in pdf.
This trick allows us to have it in PDF version while having correct page numbers thanks to the fact it is actually a word document saved as pdf. Also, if I’m not mistaken, Aspose.Words for JasperReports does not offer PDF export capabilities.

Can you give me an estimate about when this saving problems might get solved? Or, can you suggest me a different way to obtain what I’ve described above?

Hi Matteo,

Thank you for additional information. Regarding the problem with saving to stream, please expect a reply before the next hotfix (within few weeks).
Best regards.

Is there now a better estimate about the date when the 4.0 version of Aspose.Words for Java will no longer be “beta”? If I remember correctly, it should have been by the end of December…

Hi Matteo,

Thanks for your request. Most likely, the next version of Aspose.Words for Java will be release somewhere in February. It is difficult to give a more solid estimate at the moment.
Best regards.

The issues you have found earlier (filed as 12210) have been fixed in this update.

This message was posted using Notification2Forum from Downloads module by aspose.notifier.
(1)

I have downloaded version 4.0.1 beta of Aspose.Words for Java, which actually solved the problem of saving to a stream.

Now, another problem happens, when merging many documents into a single one. In the attachment you’ll find the following:

  • report files generated by our software via Aspose.Words for JasperReports(named report__.doc)
  • the doc file resulting from merging them using Aspose.Words for Java, then saving the result as.doc(DVR_3_3_allegati.doc)
  • the pdf file resulting from merging them and then saving the result as.pdf(DVR_3_3_allegati.pdf)

as you can see, the PDF version contains many errors: some images are completely screwed, and also it is completely blank from about half its length to its end.

How can this problem be solved?

PS: the archive was compressed using 7zip, so even if the extension is .zip, it really is a .7z file, I needed to do this 'cause the actual zip compression was too little, the original size is about 35MB

Hi Matteo,

Thank you for additional information. I managed to reproduce the problem on my side. Your request has been linked to the appropriate issue. You will be notified as soon as it is resolved.
You should also note that export to PDF in Aspose.Words for Java is in beta at the moment. I also tried converting your document to PDF using .NET version of Aspose.Words and conversion works perfectly.
Best regards.

Yes, I know it is only a beta feature now, but we are really looking forward to be able to completely use it in the Java version of Aspose.Words, since we cannot use the .NET version

Matteo, we will keep you updated and let you know once this feature is out of beta.

Best regards.

Hi,
Is there a release date for the 4.0.1 (out of beta). We urgently needs the saveToPdf functionality.
Regards

Hi

Thanks for your request. Most likely converting to PDF feature will come out of beta in 4-5 weeks. We will notify you.
Best regards.

Hi,

I wanted to report this: it seems that the images get scewed in saving to pdf when they are GIF images with transparency.

Perhaps you can verify this?

Hi Matteo,

Thank you for reporting this problem. I managed to reproduce the problem with GIF images. Your request has been linked to the appropriate issue, you will be notified as soon as it is resolved.
Best regards.

I’ve noticed that the version 4.0.2 beta is out. Does that version address this problem, or does it just add the comment ranges functionality?

Thanks.

Hi Matteo,

Thanks for your request. Unfortunately the problems you have reported earlier are not resolved in this release. We will let you know once these issues are resolved.
Best regards.