zippy1978 / ghost4j

Java wrapper for Ghostscript C API + PS/PDF document handling API
http://www.ghost4j.org
GNU Lesser General Public License v3.0
64 stars 38 forks source link

Error converting PDF to PDF #61

Open alexTheSwEngineer opened 6 years ago

alexTheSwEngineer commented 6 years ago

I am having an error trying to convert a PDF to a prepress ready PDF.

This code:

private void correctPDF(OutputStream result, PDFDocument pdfDocument){
            PDFConverter converter = new PDFConverter();
            converter.setMaxProcessCount(16);
            converter.setPDFSettings(OPTION_PDFSETTINGS_PREPRESS);
            converter.convert(pdfDocument, result);
}

produces this error: ERROR: org.ghost4j.converter.ConverterException: org.ghost4j.document.DocumentException: Documents of class org.ghost4j.document.PDFDocument are not supported by the component``

Converting the pdf file to a ps file and then back to pdf seems to be working though.

I have this in my pom

            <groupId>net.java.dev.jna</groupId>
            <artifactId>jna</artifactId>
            <version>4.1.0</version>
        </dependency>

        <dependency>
            <groupId>org.ghost4j</groupId>
            <artifactId>ghost4j</artifactId>
            <version>1.0.1</version>
        </dependency>

and I have instaled ghost* and libgs-dev via apt-get on my system.

Akash1684 commented 5 years ago

I have faced same issue while converting PDF->PDF there are two possible options I've figured out:

  1. Use Core API for converting PDF->PDF http://www.ghost4j.org/coreapisamples.html
  2. Convert using intermediary PostScript document i.e. PDF->PS->PDF
4F2E4A2E commented 5 years ago

Did you try to set the right pdfx flag on? https://github.com/zippy1978/ghost4j/blob/master/src/main/java/org/ghost4j/converter/PDFConverter.java#L76