ghost4j icon indicating copy to clipboard operation
ghost4j copied to clipboard

Error converting PS file containing PJL commands to PDF

Open omasseau opened this issue 7 years ago • 0 comments

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

omasseau avatar Aug 31 '17 15:08 omasseau