Hi there, Please view the code I'm working first: /*eliding some params init*/ string[] args = new string[10]; args[0] = "pdfinkcov"; args[1] = "-q"; args[2] = "-dNOPAUSE"; args[3] = "-dBATCH"; args[4] = "-dPARANOIDSAFER"; args[5] = "-dQUIET"; args[6] = "-dNOPROMPT"; args[7] = "-sDEVICE=inkcov"; args[8] = string.Format("-sOutputFile={0}",outfile.txt); args[9] = string.Format("{0}", inputfile.pdf); intElementCount = sArgs.Length; aAnsiArgs = new object[intElementCount]; aPtrArgs = new IntPtr[intElementCount]; aGCHandle = new GCHandle[intElementCount]; for (intCounter = 0; intCounter < intElementCount; intCounter++) { aAnsiArgs[intCounter] = StringToAnsiZ(sArgs[intCounter]); aGCHandle[intCounter] = GCHandle.Alloc(aAnsiArgs[intCounter], GCHandleType.Pinned); aPtrArgs[intCounter] = aGCHandle[intCounter].AddrOfPinnedObject(); } gchandleArgs = GCHandle.Alloc(aPtrArgs, GCHandleType.Pinned); intptrArgs = gchandleArgs.AddrOfPinnedObject(); intReturn = gsapi_new_instance(out intGSInstanceHandle, _objHandle); callerHandle = IntPtr.Zero; try { intReturn = gsapi_init_with_args(intGSInstanceHandle, intElementCount, intptrArgs); } I modified this from a code that convert PDF to jpeg (and it works). My issue is that the return now is -100, which should a fetal error. Is someone telling me how should I correct this code? Thanks! Best Regards, Kent
The most likely explanation is that the inkcov device is not built in. I'm not even sure the device was shipped in 9.05. If you do gs --help do you see the device listed ?
Please ensure you fill in the bug report form accurately. It looks like the inkcov device isn't setup to work with "-sOutputFile" which really is a bug. Please try using "-o <output file>" instead, and let us know.
(In reply to comment #2) > Please ensure you fill in the bug report form accurately. > > It looks like the inkcov device isn't setup to work with "-sOutputFile" which > really is a bug. > > Please try using "-o <output file>" instead, and let us know.
(In reply to comment #2) > Please ensure you fill in the bug report form accurately. > > It looks like the inkcov device isn't setup to work with "-sOutputFile" which > really is a bug. > > Please try using "-o <output file>" instead, and let us know. Hi Chris and Ken, I've tried in cmd.exe, both "-o filename" and "-sOutputFile=filename" is Ok for outputting a "filename" file. And then I tried changing in the code, and debug, the return number is still -100.
Yeh, sorry, that was a typo when I ran the gs executable that made me think that. Next thought is to remove the "-q" and "-dQUIET" options, and see if you're actually getting any error or warning messages (on stdout/stderr) before the actual error return.
I've the "-q" and "-dQUIET" removed, but nothing comes up, and it still return -100.
Do you have a way to view the stdout/stderr output from Ghostscript? We have some debug options we could follow, but they rely on feeding output to stdout/stderr
Note that -sstdout=___ (and -sstderr=___) allows for writing files instead of stdout and stderr.
(In reply to comment #8) > Note that -sstdout=___ (and -sstderr=___) allows for writing files instead of > stdout and stderr. Do you mean something like this: args[x]=string.format("-sstdout={0}","c:\\aaa.txt"); args[x+1]=string.format("-sstderr={0}","c:\\bbb.txt");
Thank you, Ray. I've export the stdout output into a file. And from the file, I realized that my code was using version 9.05 which did not contain the inkcov device. So how to change the code to import method from 9.06? Here's the code (one of them as sample): [DllImport("gsdll32.dll", EntryPoint = "gsapi_new_instance")] private static extern int gsapi_new_instance(out IntPtr pinstance, IntPtr caller_handle);
Hello guys, here's the message in stdout using gs9.06: GPL Ghostscript 9.06 (2012-08-08) Copyright (C) 2012 Artifex Software, Inc. All rights reserved. This software comes with NO WARRANTY: see the file PUBLIC for details. Processing pages 1 through 3. Page 1 Error: /invalidfileaccess in --showpage-- Operand stack: 1 true Execution stack: %interp_exit .runexec2 --nostringval-- --nostringval-- --nostringval-- 2 %stopped_push --nostringval-- --nostringval-- --nostringval-- false 1 %stopped_push 1926 1 3 %oparray_pop 1925 1 3 %oparray_pop 1909 1 3 %oparray_pop --nostringval-- --nostringval-- 2 1 3 --nostringval-- %for_pos_int_continue --nostringval-- --nostringval-- 1809 0 9 %oparray_pop --nostringval-- --nostringval-- Dictionary stack: --dict:1174/1684(ro)(G)-- --dict:1/20(G)-- --dict:82/200(L)-- --dict:82/200(L)-- --dict:109/127(ro)(G)-- --dict:293/300(ro)(G)-- --dict:25/31(L)-- --dict:6/8(L)-- --dict:21/40(L)-- Current allocation mode is local Last OS error: Bad file descriptor
So, what you're getting there is a Windows error, not something originating in Ghostscript. Any number of things might cause it - the file/directory being "locked" by another process, no permission to write to the directory, out of file handles...... If you're using Vista or Win7, for example, you might need to take account of UAC and/or other security measures.
(In reply to comment #12) > So, what you're getting there is a Windows error, not something originating in > Ghostscript. Any number of things might cause it - the file/directory being > "locked" by another process, no permission to write to the directory, out of > file handles...... > > If you're using Vista or Win7, for example, you might need to take account of > UAC and/or other security measures. Thanks Chris, this issue is solved! I'm using "-o c:\\a.txt" for output target while out last error message show it the stdout text file. Then, after reading you reply, searched on net, it suddenly comes into me:" hey, why not use '-sOutputFile=' instead of '-o'?" So I tried and it worked! No more error message in that text file. Thanks for all you guys' help!