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

Low level API not able to transform PDF to PDF in multi-threading environment #63

Open Akash1684 opened 5 years ago

Akash1684 commented 5 years ago

I am using Ghost4j 1.0.1 with Ghostscript version Ghostscript 9.05 and converting PDF to PDF using the following parameters:

final String[] gsArgs = new String[10];
        gsArgs[0] = "-pdf2pdf";
        gsArgs[1] = "-dNOPAUSE";
        gsArgs[2] = "-dBATCH";
        gsArgs[3] = "-dSAFER";
        gsArgs[4] = "-sDEVICE=pdfwrite";
        gsArgs[5] = "-sOutputFile=" + outputFileName;
        gsArgs[6] = "-c";
        gsArgs[7] = ".setpdfwrite";
        gsArgs[8] = "-f";
        gsArgs[9] = inputFileName;

However, I am getting following exception on calling gs.initialize(gsArgs):

org.ghost4j.Ghostscript: Page 3
org.ghost4j.Ghostscript: Error: /nocurrentpoint in --run--
org.ghost4j.Ghostscript: Operand stack:
org.ghost4j.Ghostscript: --dict:14/14(L)-- --dict:0/0(ro)(G)--
org.ghost4j.Ghostscript: Execution stack:
org.ghost4j.Ghostscript: %interp_exit .runexec2 --nostringval-- --nostringval-- --nostringval-- 2 %stopped_push --nostringval-- --nostringval-- --nostringval-- false 1 %stopped_push 1910 1 3 %oparray_pop 1909 1 3 %oparray_pop 1893 1 3 %oparray_pop --nostringval-- --nostringval-- 4 1 10 --nostringval-- %for_pos_int_continue --nostringval-- --nostringval-- false 1 %stopped_push --nostringval-- --nostringval-- --nostringval-- %array_continue --nostringval-- --nostringval-- --nostringval-- --nostringval-- --nostringval--
org.ghost4j.Ghostscript: Dictionary stack:
org.ghost4j.Ghostscript: --dict:1157/1684(ro)(G)-- --dict:1/20(G)-- --dict:83/200(L)-- --dict:83/200(L)-- --dict:109/127(ro)(G)-- --dict:291/300(ro)(G)-- --dict:24/31(L)-- --dict:6/8(L)-- --dict:28/40(L)--
org.ghost4j.Ghostscript: Current allocation mode is local
org.ghost4j.Ghostscript: Last OS error: 2
org.ghost4j.Ghostscript: GPL Ghostscript 9.05: Unrecoverable error, exit code 1

I am using thread safe approach, defined in http://www.ghost4j.org/threadsafetyandmultithreading.html and synchronizing on GS instance.

4F2E4A2E commented 5 years ago

Please upload a pdf document example in order to be able to reproduce the problem. It could be very well related to your content, thanks.

Akash1684 commented 5 years ago

@4F2E4A2E - I am not able to share the exact file. However, I have added the log trace for more information. I agree that issue is related to the content of the file since the same approach worked for multiple PDF files in past.

The pattern I am seeing is that PDF files generated through Acrobat Distiller 18.0 (Windows) are causing this issue.

Note: I've found a similar issue for PS to PDF https://stackoverflow.com/questions/9905507/what-does-this-ghostscript-error-message-mean

4F2E4A2E commented 5 years ago

Did you ask the Acrobat Distiller 18.0 (Windows) about this?

Akash1684 commented 5 years ago
Error: /nocurrentpoint in --run--
Operand stack:
   --dict:14/14(L)--   --dict:0/0(ro)(G)--
Execution stack:
   %interp_exit   .runexec2   --nostringval--   --nostringval--   --nostringval--   2   %stopped_push   --nostringval--   --nostringval--   --nostringval--   false   1   %stopped_push   1894   1   3   %oparray_pop   1893   1   3   %oparray_pop   1877   1   3   %oparray_pop   --nostringval--   --nostringval--   6   1   10   --nostringval--   %for_pos_int_continue   --nostringval--   --nostringval--   false   1   %stopped_push   --nostringval--   --nostringval--   --nostringval--   %array_continue   --nostringval--   --nostringval--   --nostringval--   --nostringval--   --nostringval--
Dictionary stack:
   --dict:1155/1684(ro)(G)--   --dict:1/20(G)--   --dict:83/200(L)--   --dict:83/200(L)--   --dict:109/127(ro)(G)--   --dict:291/300(ro)(G)--   --dict:24/31(L)--   --dict:6/8(L)--   --dict:28/40(L)--
Current allocation mode is local
Last OS error: 2

GPL Ghostscript 9.05: Unrecoverable error, exit code 1

GPL Ghostscript 9.05: ERROR: A pdfmark destination page 5 points beyond the last page 4.

The issue is that Ghostscript is reading pdfmark and then failing on incorrect pdfmark. PDF is now generated using Adobe Acrobat Standard DC 18.11.20063 rather than Acrobat Distiller 18.0 (Windows) so the generation software was not an issue.