feristhia / xdocreport

Automatically exported from code.google.com/p/xdocreport
0 stars 0 forks source link

Error converting PDF #336

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. using code:
private static void createPDF() {
        try {
            long start = System.currentTimeMillis();

            // 1) Load DOCX into XWPFDocument
            InputStream is = new FileInputStream(new File(
                    "temp.docx"));
            XWPFDocument document = new XWPFDocument(is);

            // 2) Prepare Pdf options
            PdfOptions options = PdfOptions.create();

            // 3) Convert XWPFDocument to Pdf
            OutputStream out = new FileOutputStream(new File(
                    "temp.pdf"));
            PdfConverter.getInstance().convert(document, out, options);

            System.err.println("Generate pdf/HelloWorld.pdf with "
                    + (System.currentTimeMillis() - start) + "ms");

        } catch (Throwable e) {
            e.printStackTrace();
        }
    }
2. Using the File as attached
3.

What is the expected output? What do you see instead?
- Expectiing: Generate pdf/HelloWorld.pdf with

- But getting the stacktrace:
org.apache.poi.xwpf.converter.core.XWPFConverterException: 
java.lang.NullPointerException
    at org.apache.poi.xwpf.converter.pdf.PdfConverter.doConvert(PdfConverter.java:59)
    at org.apache.poi.xwpf.converter.pdf.PdfConverter.doConvert(PdfConverter.java:37)
    at org.apache.poi.xwpf.converter.core.AbstractXWPFConverter.convert(AbstractXWPFConverter.java:45)
    at various.testklasse.createPDF(testklasse.java:37)
    at various.testklasse.main(testklasse.java:19)
Caused by: java.lang.NullPointerException
    at org.apache.poi.xwpf.converter.core.utils.XWPFTableUtil.getGridColList(XWPFTableUtil.java:166)
    at org.apache.poi.xwpf.converter.core.utils.XWPFTableUtil.computeColWidths(XWPFTableUtil.java:99)
    at org.apache.poi.xwpf.converter.core.XWPFDocumentVisitor.visitTable(XWPFDocumentVisitor.java:827)
    at org.apache.poi.xwpf.converter.core.XWPFDocumentVisitor.visitBodyElements(XWPFDocumentVisitor.java:245)
    at org.apache.poi.xwpf.converter.core.XWPFDocumentVisitor.start(XWPFDocumentVisitor.java:193)
    at org.apache.poi.xwpf.converter.pdf.PdfConverter.doConvert(PdfConverter.java:55)
    ... 4 more

What version of the product are you using? On what operating system?
1.0.3

Please provide any additional information below.
- The File was generated by POI Apache 3.9
- I loaded this File into Windows 2013 on my Windows 8.1 System and saved it 
again. Now the converting works, seems Windows is adding something right which 
is not important for word.

I hope you can help.

Original issue reported on code.google.com by timopra...@gmail.com on 27 Nov 2013 at 10:56

Attachments:

GoogleCodeExporter commented 9 years ago
i forgot to add, that the same error happens when using the 'just-generated' 
XWPFDocument not like here a loaded file...

Original comment by timopra...@gmail.com on 27 Nov 2013 at 11:07

GoogleCodeExporter commented 9 years ago
Thank's for your attached docx. I will see your problem when I will have time.

Regards Angelo

Original comment by angelo.z...@gmail.com on 27 Nov 2013 at 1:13

GoogleCodeExporter commented 9 years ago
[deleted comment]
GoogleCodeExporter commented 9 years ago
when I use xdoc-report (the same method of the first post) happend:

code error:

org.apache.poi.xwpf.converter.core.XWPFConverterException: 
java.lang.NullPointerException
    at org.apache.poi.xwpf.converter.pdf.PdfConverter.doConvert(PdfConverter.java:59)
    at org.apache.poi.xwpf.converter.pdf.PdfConverter.doConvert(PdfConverter.java:37)
    at org.apache.poi.xwpf.converter.core.AbstractXWPFConverter.convert(AbstractXWPFConverter.java:45)
    at pe.edu.rpanaque.docxsunarppdf.ConvertDocx1.main(ConvertDocx1.java:30)
Caused by: java.lang.NullPointerException
    at org.apache.poi.xwpf.converter.core.utils.XWPFTableUtil.getGridColList(XWPFTableUtil.java:166)
    at org.apache.poi.xwpf.converter.core.utils.XWPFTableUtil.computeColWidths(XWPFTableUtil.java:99)
    at org.apache.poi.xwpf.converter.core.XWPFDocumentVisitor.visitTable(XWPFDocumentVisitor.java:827)
    at org.apache.poi.xwpf.converter.core.XWPFDocumentVisitor.visitBodyElements(XWPFDocumentVisitor.java:245)
    at org.apache.poi.xwpf.converter.core.XWPFDocumentVisitor.start(XWPFDocumentVisitor.java:193)
    at org.apache.poi.xwpf.converter.pdf.PdfConverter.doConvert(PdfConverter.java:55)
    ... 3 more

- Also I share you my word document

I have a question:
Why my pdf document has more pages than my word document?
How I can control this behavior?
How I can rewrite the method 
"PdfConverter.getInstance().convert(document, out, options);"
to set a standard PDF/A? 

....
thanks a lot.

Original comment by rtejadapa on 28 Dec 2013 at 10:16

Attachments:

GoogleCodeExporter commented 9 years ago
I will see your problem when I will have time.

> Why my pdf document has more pages than my word document?
Our converter si not perfect, so you can have this problem (or perhaps it's a 
problem of font that you have not on your computer?).

> How I can control this behavior?
You cannot, the page od pdf is managed by iText. Our converter must be 
improved, but it's very hard.

> to set a standard PDF/A? 
This feature is available for 1.0.4 (you can use the 1.0.4 snapshot with 
maven). Please read 
https://groups.google.com/forum/#!searchin/xdocreport/IPdfWriterConfiguration/xd
ocreport/xgarPynztF8/gH7s0RasxdoJ

Original comment by angelo.z...@gmail.com on 28 Dec 2013 at 10:58

GoogleCodeExporter commented 9 years ago
[deleted comment]
GoogleCodeExporter commented 9 years ago
hi angelo,
i have a problem with the standard PDF/A,
when i export my document to pdf print the 
next error:
_______________________
org.apache.poi.xwpf.converter.core.XWPFConverterException: 
org.apache.poi.xwpf.converter.core.XWPFConverterException: 
com.lowagie.text.DocumentException: 
com.lowagie.text.pdf.PdfXConformanceException: All the fonts must be embedded. 
This one isn't: Helvetica
    at org.apache.poi.xwpf.converter.pdf.PdfConverter.doConvert(PdfConverter.java:59)
    at org.apache.poi.xwpf.converter.pdf.PdfConverter.doConvert(PdfConverter.java:37)
    at org.apache.poi.xwpf.converter.core.AbstractXWPFConverter.convert(AbstractXWPFConverter.java:45)
    at pe.edu.rpanaque.docxsunarppdf.ConvertDocx1.main(ConvertDocx1.java:40)
Caused by: org.apache.poi.xwpf.converter.core.XWPFConverterException: 
com.lowagie.text.DocumentException: 
com.lowagie.text.pdf.PdfXConformanceException: All the fonts must be embedded. 
This one isn't: Helvetica
    at org.apache.poi.xwpf.converter.pdf.internal.elements.StylableDocument.flushTable(StylableDocument.java:349)
    at org.apache.poi.xwpf.converter.pdf.internal.elements.StylableDocument.close(StylableDocument.java:160)
    at org.apache.poi.xwpf.converter.pdf.internal.PdfMapper.endVisitDocument(PdfMapper.java:170)
    at org.apache.poi.xwpf.converter.core.XWPFDocumentVisitor.start(XWPFDocumentVisitor.java:196)
    at org.apache.poi.xwpf.converter.pdf.PdfConverter.doConvert(PdfConverter.java:55)
    ... 3 more
Caused by: com.lowagie.text.DocumentException: 
com.lowagie.text.pdf.PdfXConformanceException: All the fonts must be embedded. 
This one isn't: Helvetica
    at com.lowagie.text.pdf.PdfDocument.add(Unknown Source)
    at com.lowagie.text.Document.add(Unknown Source)
    at fr.opensagres.xdocreport.itext.extension.ExtendedDocument.add(ExtendedDocument.java:114)
    at org.apache.poi.xwpf.converter.pdf.internal.elements.StylableDocument.flushTable(StylableDocument.java:345)
    ... 7 more
Caused by: com.lowagie.text.pdf.PdfXConformanceException: All the fonts must be 
embedded. This one isn't: Helvetica
    at com.lowagie.text.pdf.internal.PdfXConformanceImp.checkPDFXConformance(Unknown Source)
    at com.lowagie.text.pdf.PdfWriter.addSimple(Unknown Source)
    at com.lowagie.text.pdf.PdfContentByte.setFontAndSize(Unknown Source)
    at com.lowagie.text.pdf.PdfDocument.writeLineToContent(Unknown Source)
    at com.lowagie.text.pdf.ColumnText.go(Unknown Source)
    at com.lowagie.text.pdf.ColumnText.goComposite(Unknown Source)
    at com.lowagie.text.pdf.ColumnText.go(Unknown Source)
    at com.lowagie.text.pdf.ColumnText.go(Unknown Source)
    at com.lowagie.text.pdf.PdfPRow.writeCells(Unknown Source)
    at com.lowagie.text.pdf.PdfPTable.writeSelectedRows(Unknown Source)
    at com.lowagie.text.pdf.PdfPTable.writeSelectedRows(Unknown Source)
    at com.lowagie.text.pdf.PdfPTable.writeSelectedRows(Unknown Source)
    at com.lowagie.text.pdf.ColumnText.goComposite(Unknown Source)
    at com.lowagie.text.pdf.ColumnText.go(Unknown Source)
    at com.lowagie.text.pdf.ColumnText.go(Unknown Source)
    at com.lowagie.text.pdf.PdfDocument.addPTable(Unknown Source)
    ... 11 more
________________________________________________

thanks all

Original comment by mario...@gmail.com on 30 Dec 2013 at 9:54

GoogleCodeExporter commented 9 years ago
Never played with PDF/A and iText. Perhaps 
http://stackoverflow.com/questions/19315917/all-the-fonts-must-be-embedded-this-
one-isnt-helvetica can help you?

Original comment by angelo.z...@gmail.com on 30 Dec 2013 at 10:55

GoogleCodeExporter commented 9 years ago
i need add font styles for i have convert docx to pdf/a

Original comment by mario...@gmail.com on 30 Dec 2013 at 11:37

GoogleCodeExporter commented 9 years ago
I cannot help you more, because never played with PDF/A. 

It should be cool if some iText user could help us with this toipc.

Thank's

Original comment by angelo.z...@gmail.com on 30 Dec 2013 at 11:48

GoogleCodeExporter commented 9 years ago
yes, It would be cool .
but you think that you can migrate your project to itext 5.4
,because in this itext's version exists support for the standard pdf/a

thank's.

Original comment by mario...@gmail.com on 31 Dec 2013 at 12:10

GoogleCodeExporter commented 9 years ago
We have choosen to use iText 2.3.7 for the license. Today we have not the 
intention (and not the time) to migrate to 5.4.

Original comment by angelo.z...@gmail.com on 31 Dec 2013 at 12:14

GoogleCodeExporter commented 9 years ago
and if I change itext for FOP or PDFBox its possible?

Original comment by mario...@gmail.com on 31 Dec 2013 at 12:27

GoogleCodeExporter commented 9 years ago
Our PDF converter is based on iText 2.3.7 so you cannot change it for FOP or 
PDFBox.
We have started a long time an implementation with FOP but we have gaven it 
(very slowly, hard to maintain because of XSL, problem with memory, etc). For 
PDFBox I don"t know how to create a PDF from scratch. See issues at 
https://code.google.com/p/xdocreport/issues/detail?id=33

Original comment by angelo.z...@gmail.com on 31 Dec 2013 at 8:00

GoogleCodeExporter commented 9 years ago
Hello, 
When I'm creating a table with apache poi(poi-3.9-20121203.jar):

XWPFTable table = new XWPFDocument().createTable();

System.out.println(table.getCTTbl());

<xml-fragment 
xmlns:wpc="http://schemas.microsoft.com/office/word/2010/wordprocessingCanvas" 
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
xmlns:o="urn:schemas-microsoft-com:office:office" 
xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships" 
xmlns:m="http://schemas.openxmlformats.org/officeDocument/2006/math" 
xmlns:v="urn:schemas-microsoft-com:vml" 
xmlns:wp14="http://schemas.microsoft.com/office/word/2010/wordprocessingDrawing"

xmlns:wp="http://schemas.openxmlformats.org/drawingml/2006/wordprocessingDrawing
" xmlns:w10="urn:schemas-microsoft-com:office:word" 
xmlns:w="http://schemas.openxmlformats.org/wordprocessingml/2006/main" 
xmlns:w14="http://schemas.microsoft.com/office/word/2010/wordml" 
xmlns:wpg="http://schemas.microsoft.com/office/word/2010/wordprocessingGroup" 
xmlns:wpi="http://schemas.microsoft.com/office/word/2010/wordprocessingInk" 
xmlns:wne="http://schemas.microsoft.com/office/word/2006/wordml" 
xmlns:wps="http://schemas.microsoft.com/office/word/2010/wordprocessingShape">
  <w:tblPr>
    <w:tblW w:w="0" w:type="auto"/>
    <w:tblBorders>
      <w:top w:val="single"/>
      <w:left w:val="single"/>
      <w:bottom w:val="single"/>
      <w:right w:val="single"/>
      <w:insideH w:val="single"/>
      <w:insideV w:val="single"/>
    </w:tblBorders>
  </w:tblPr>
  <w:tr>
    <w:tc>
      <w:p>
        <w:r>
          <w:t>Hello</w:t>
        </w:r>
      </w:p>
    </w:tc>
    <w:tc>
      <w:p>
        <w:r>
          <w:t>World</w:t>
        </w:r>
      </w:p>
    </w:tc>
  </w:tr>
  <w:tr>
    <w:tc>
      <w:p>
        <w:r>
          <w:t>This is</w:t>
        </w:r>
      </w:p>
    </w:tc>
    <w:tc>
      <w:p>
        <w:r>
          <w:t>a table</w:t>
        </w:r>
      </w:p>
    </w:tc>
  </w:tr>
</xml-fragment>

******It does not create the xml tag 
<w:tblGrid>
    <w:gridCol w:w="4360"/>
    <w:gridCol w:w="4360"/>
    ..........
    ..........
</w:tblGrid>

******* I think this could work so:

indexTable =0; //model existing table in the document, template 
CTTblPr ct = document.getTables().get(indexTable).getCTTbl().getTblPr();
table.getCTTbl().setTblPr(ct);  

CTTblGrid ctg =document.getTables().get(indexTable).getCTTbl().getTblGrid();
table.getCTTbl().setTblGrid(ctg);

thanks.

Original comment by rtejadapa on 31 Dec 2013 at 7:29

Attachments:

GoogleCodeExporter commented 9 years ago
Ok thank's for this info. If I remember w:tblGrid is important to know width of 
table, etc. But no time for the moment to fix that-(

Original comment by angelo.z...@gmail.com on 1 Jan 2014 at 8:14

GoogleCodeExporter commented 9 years ago
Hi rtejadapa,

Have you tried to convert your docx with 1.0.4-SNAPSHOT? I have tested your 
docx and it works well with 1.0.4-SNAPSHOT.

Regards Angelo

Original comment by angelo.z...@gmail.com on 5 Jan 2014 at 4:08

GoogleCodeExporter commented 9 years ago
I close this issue because none answer.

Original comment by angelo.z...@gmail.com on 18 Feb 2014 at 11:11

GoogleCodeExporter commented 9 years ago
1.0.4 seems fix the problem.

Original comment by angelo.z...@gmail.com on 18 Feb 2014 at 11:12