Bug 693405 - Invoke with device "inkcov"
Summary: Invoke with device "inkcov"
Status: RESOLVED WORKSFORME
Alias: None
Product: Ghostscript
Classification: Unclassified
Component: Client API (show other bugs)
Version: 9.06
Hardware: PC Windows 7
: P4 normal
Assignee: Default assignee
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2012-10-23 19:03 UTC by Kent
Modified: 2012-10-25 08:45 UTC (History)
1 user (show)

See Also:
Customer:
Word Size: ---


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Kent 2012-10-23 19:03:44 UTC
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
Comment 1 Ken Sharp 2012-10-23 19:20:53 UTC
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 ?
Comment 2 Chris Liddell (chrisl) 2012-10-23 19:23:06 UTC
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.
Comment 3 Kent 2012-10-23 19:36:40 UTC
(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.
Comment 4 Kent 2012-10-23 19:40:43 UTC
(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.
Comment 5 Chris Liddell (chrisl) 2012-10-23 19:48:56 UTC
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.
Comment 6 Kent 2012-10-24 03:26:35 UTC
I've the "-q" and "-dQUIET" removed, but nothing comes up, and it still return -100.
Comment 7 Chris Liddell (chrisl) 2012-10-24 07:55:29 UTC
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
Comment 8 Ray Johnston 2012-10-24 13:31:49 UTC
Note that -sstdout=___ (and -sstderr=___) allows for writing files instead of
stdout and stderr.
Comment 9 Kent 2012-10-24 17:15:16 UTC
(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");
Comment 10 Kent 2012-10-25 03:18:04 UTC
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);
Comment 11 Kent 2012-10-25 03:40:08 UTC
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
Comment 12 Chris Liddell (chrisl) 2012-10-25 07:41:14 UTC
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.
Comment 13 Kent 2012-10-25 08:34:19 UTC
(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!