Page 1 of 1

Unable to convert xlsx to pdf

PostPosted: Thu Mar 03, 2016 12:45 pm
by mcmssupereditor
I'm using docx4j.NET. When I try to convert xlsx to pdf, an exception occurs. Exception message: "Docx4JException: Invalid document package in the settings, it isn't a WordprocessingMLPackage"

Does docx4j only support converting docx to pdf?
Thanks

Here is my code
Code: Select all
....
            string fileIN = projectDir + @"src\samples\resources\sample-xlsx.xlsx";
            string fileOUT = projectDir + @"OUT_sample-xlsx.pdf";
....
            SpreadsheetMLPackage excelMLPackage = SpreadsheetMLPackage
                    .load(new java.io.File(fileIN));
            org.docx4j.events.StartEvent startEvent = new org.docx4j.events.StartEvent(excelMLPackage, org.docx4j.events.WellKnownProcessSteps.PDF);
            startEvent.publish();

            org.docx4j.convert.@out.FOSettings settings = new org.docx4j.convert.@out.FOSettings();
            settings.setWmlPackage(excelMLPackage);
            settings.setApacheFopMime("application/pdf");
            org.docx4j.convert.@out.common.Exporter exporter = org.docx4j.convert.@out.fo.FOExporterXslt.getInstance();
            exporter.export(
                settings
                , new java.io.FileOutputStream(new java.io.File(fileOUT))
                );
....


Error details:
[ERROR] org.docx4j.convert.out.common.AbstractExporter - Exception exporting pac
kage
org.docx4j.openpackaging.exceptions.Docx4JException: Invalid document package in
the settings, it isn't a WordprocessingMLPackage

Unhandled Exception: org.docx4j.openpackaging.exceptions.Docx4JException: Except
ion exporting package ---> org.docx4j.openpackaging.exceptions.Docx4JException:
Invalid document package in the settings, it isn't a WordprocessingMLPackage
at org.docx4j.convert.out.common.AbstractWmlExporter.preprocess(AbstractConve
rsionSettings conversionSettings)
at org.docx4j.convert.out.common.AbstractWmlExporter.<bridge>preprocess(Abstr
actConversionSettings x0)
at org.docx4j.convert.out.common.AbstractExporter.export(AbstractConversionSe
ttings conversionSettings, OutputStream outputStream)
--- End of inner exception stack trace ---
at org.docx4j.convert.out.common.AbstractExporter.export(AbstractConversionSe
ttings conversionSettings, OutputStream outputStream)
at docx4j.NET.samples.XlsxToPDF.Main(String[] args)

Re: Unable to convert xlsx to pdf

PostPosted: Thu Mar 03, 2016 7:38 pm
by jason
Unfortunately, that's right: built-in support for docx to pdf only.

Although you could write some code using xslx4j to convert a simple spreadsheet easily enough, for anything more complex some alternative solution is probably preferable.

Re: Unable to convert xlsx to pdf

PostPosted: Mon Apr 16, 2018 9:22 pm
by Frederic
Hi mcmssupereditor,

Did you find a solution for your problem ?
I found some (jodconverter, documents4j, ...) but it isn't exactly what I want.

Thanks