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 PS file containing PJL commands to PDF #60

Open omasseau opened 7 years ago

omasseau commented 7 years ago

I have a ps file that contains PJL commands. If I convert it to pdf with the command line (Ghostcript 9.20 on Windows10 64 bits) it works correctly:

gswin64c -dNOPAUSE -dBATCH -dSAFER -dProcessColorModel=/DeviceRGB -dPDFSETTINGS=/default -dCompatibilityLevel=1.4 -dPDFX=false -dDEVICEWIDTHPOINTS=612 -dDEVICEHEIGHTPOINTS=792 -sDEVICE=pdfwrite -sOutputFile=pjl.pdf -q -f pjl.ps

But it does not work with ghost4j. I get an Invalid memory access exception:

Exception in thread "main" java.lang.Error: Invalid memory access at com.sun.jna.Native.invokeInt(Native Method) at com.sun.jna.Function.invoke(Function.java:383) at com.sun.jna.Function.invoke(Function.java:315) at com.sun.jna.Library$Handler.invoke(Library.java:212) at com.sun.proxy.$Proxy0.gsapi_exit(Unknown Source) at org.ghost4j.Ghostscript.exit(Ghostscript.java:555) at org.ghost4j.Ghostscript.initialize(Ghostscript.java:359) at org.ghost4j.converter.PDFConverter.run(PDFConverter.java:238) at org.ghost4j.converter.AbstractRemoteConverter.convert(AbstractRemoteConverter.java:85)

Test code:


    public static void main(String[] args) throws Exception {

        try {
            String input = "C:\\postscript\\pjl.ps";

            PSDocument document = new PSDocument();
            document.load(new ByteArrayInputStream(Files.readAllBytes(Paths.get(input))));

            PDFConverter converter = new PDFConverter();

            converter.convert(document, new ByteArrayOutputStream()); 

        } catch (Exception e) {
            throw new Exception("Could not convert postscript to pdf", e);
        }
    }

Without the PJL commands it works fine.

I attached the problematic file: pjl.txt (rename extension to .ps as github does not support .ps attachments). I also attached the file that works: no-pjl.txt

no-pjl.txt pjl.txt