PDF to PDF/A conversion fails

727 views
Skip to first unread message

Shervin Asgari

unread,
Mar 16, 2010, 9:25:43 AM3/16/10
to jodcon...@googlegroups.com
Hi. I get failed conversion exception when trying to convert pdf to pdf/a.
It works fine when running jodconverter 2.2, but fails on 3.0.beta.

What I have noted is that on the old code you had to explicitly set the input and output Document format to DocumentFamily.DRAWING.
But in the new api that is not done. Maybe the error is there?

This is my output:
inputFIle: /tmp/SaksappTmpFile5918183243922122356.pdf
outputFile: /tmp/SaksappTmpFile59181832439221223563498583100718631904.pdf

Executing this code:
converter.convert(inputFile, outputFile, toFormatPDFA());

14:16:36,028 ERROR [ConverterService3Impl] failed conversion: pdf [8430b] to .pdf; org.artofsolving.jodconverter.office.OfficeException: unsupported conversion; input file: SaksappTmpFile5918183243922122356.pdf
14:16:36,033 ERROR [STDERR] org.artofsolving.jodconverter.office.OfficeException: unsupported conversion
14:16:36,033 ERROR [STDERR]     at org.artofsolving.jodconverter.AbstractConversionTask.storeDocument(AbstractConversionTask.java:113)
14:16:36,033 ERROR [STDERR]     at org.artofsolving.jodconverter.AbstractConversionTask.execute(AbstractConversionTask.java:63)
14:16:36,033 ERROR [STDERR]     at org.artofsolving.jodconverter.office.PooledOfficeManager$2.run(PooledOfficeManager.java:81)
14:16:36,034 ERROR [STDERR]     at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:417)
14:16:36,034 ERROR [STDERR]     at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:269)
14:16:36,034 ERROR [STDERR]     at java.util.concurrent.FutureTask.run(FutureTask.java:123)
14:16:36,034 ERROR [STDERR]     at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:651)
14:16:36,035 ERROR [STDERR]     at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:676)
14:16:36,035 ERROR [STDERR]     at java.lang.Thread.run(Thread.java:595)

private DocumentFormat toFormatPDFA() {
        DocumentFormat format = new DocumentFormat("PDF/A", "pdf", "application/pdf");
        Map<String, Object> properties = new HashMap<String, Object>();
        properties.put("FilterName", "writer_pdf_Export");

        Map<String, Object> filterData = new HashMap<String, Object>();
        filterData.put("SelectPdfVersion", this.PDFX1A2001);
        properties.put("FilterData", filterData);

        format.setStoreProperties(DocumentFamily.TEXT, properties);

        return format;
    }

Mirko Nasato

unread,
Mar 21, 2010, 7:44:02 AM3/21/10
to JODConverter
That's because PDF is not a format that can be imported according to
the DefaultDocumentFormatRegistry. You need to create a custom
registry where PDF is declared as having inputFamily = DRAWING. (The
PDF import extension loads PDFs as Draw documents.)

Kind regards

Mirko

Shervin

unread,
Mar 22, 2010, 6:41:20 AM3/22/10
to JODConverter
Hi Mirko.

Thanks for the reply. Sounds like I need to change the source and
create this new class. Is this something that you think would benefit
the API? If so I am more than willing to donate code back to trunk.

Kind regards Shervin

Mirko Nasato

unread,
Mar 22, 2010, 6:16:51 PM3/22/10
to JODConverter
No need to change the source code, you can use
JsonDocumentFormatRegistry with a configuration file in json format

http://groups.google.com/group/jodconverter/browse_thread/thread/2a2d8cc80e957811

or subclass DefaultDocumentFormatRegistry to add what you need. In
fact you could even use DefaultDocumentFormatRegistry directly like
this

DocumentFormatRegistry formatRegistry = new
DefaultDocumentFormatRegistry();

formatRegistry.getFormatByExtension("pdf").setInputFamily(DocumentFamily.DRAWING);
OfficeDocumentConverter converter = new
OfficeDocumentConverter(officeManager, formatRegistry);

Kind regards

Mirko

Shervin

unread,
Mar 24, 2010, 7:51:37 AM3/24/10
to JODConverter
However, after alot of debugging, I found out that we have to use
another
DocumentFormat when going from pdf to pdf/a.

In case others needs to know:

/**
* This DocumentFormat must be used when converting from document
(not
pdf) to pdf/a
*/


private DocumentFormat toFormatPDFA() {
DocumentFormat format = new DocumentFormat("PDF/A", "pdf",
"application/pdf");
Map<String, Object> properties = new HashMap<String,
Object>();
properties.put("FilterName", "writer_pdf_Export");

Map<String, Object> filterData = new HashMap<String,
Object>();
filterData.put("SelectPdfVersion", this.PDFX1A2001);
properties.put("FilterData", filterData);

format.setStoreProperties(DocumentFamily.TEXT, properties);

return format;
}

/**
* This DocumentFormat must be used when converting from pdf to
pdf/a
*/
private DocumentFormat toFormatPDFA_DRAW() {


DocumentFormat format = new DocumentFormat("PDF/A", "pdf",
"application/pdf");
Map<String, Object> properties = new HashMap<String,
Object>();

properties.put("FilterName", "draw_pdf_Export");

Map<String, Object> filterData = new HashMap<String,
Object>();
filterData.put("SelectPdfVersion", this.PDFX1A2001);
properties.put("FilterData", filterData);

format.setStoreProperties(DocumentFamily.DRAWING, properties);

return format;
}


On Mar 22, 11:16 pm, Mirko Nasato <mirko.nas...@gmail.com> wrote:
> No need to change the source code, you can use
> JsonDocumentFormatRegistry with a configuration file in json format
>

>  http://groups.google.com/group/jodconverter/browse_thread/thread/2a2d...

Reply all
Reply to author
Forward
0 new messages