Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error in current page handling of Ghostscript Processor #26

Closed
msdobrescu opened this issue Sep 12, 2016 · 1 comment
Closed

Error in current page handling of Ghostscript Processor #26

msdobrescu opened this issue Sep 12, 2016 · 1 comment
Labels

Comments

@msdobrescu
Copy link

Hi,

Running the following:
gswin64c -dNODISPLAY -q -sFile="test.PDF" pdf_info.ps

has the following output:


        test.PDF has 1 page.

Title: 120906_DACHSER_CMYK
Creator: Adobe Illustrator CS5
Producer: Adobe PDF library 9.90
CreationDate: D:20121017105900+02'00'
ModDate: D:20121017105900+02'00'

Page 1 MediaBox: [0.0 0.0 157.833 34.666] BleedBox: [0.0 0.0 157.833 34.666] TrimBox: [0.0 0.0 157.833 34.666] ArtBox: [2.76025 1.92285 155.824 31.4028]

No system fonts are needed.

The GhostScript processor throws an exception with the following stacktrace:

   at System.Number.StringToNumber(String str, NumberStyles options, NumberBuffer& number, NumberFormatInfo info, Boolean parseDecimal)
   at System.Number.ParseInt32(String s, NumberStyles style, NumberFormatInfo info)
   at Ghostscript.NET.Processor.GhostscriptProcessor.ProcessOutputLine(String line) in R:\EDENRED\Ghostscript.NET\Ghostscript.NET-master\Ghostscript.NET\Processor\GhostscriptProcessor.cs:line 462
   at Ghostscript.NET.Processor.GhostscriptProcessor.OnStdIoOutput(String output) in R:\EDENRED\Ghostscript.NET\Ghostscript.NET-master\Ghostscript.NET\Processor\GhostscriptProcessor.cs:line 407
   at Ghostscript.NET.Processor.GhostscriptProcessorInternalStdIOHandler.StdOut(String output) in R:\EDENRED\Ghostscript.NET\Ghostscript.NET-master\Ghostscript.NET\Processor\GhostscriptProcessorInternalStdIOHandler.cs:line 51
   at Ghostscript.NET.GhostscriptStdIO.gs_std_out(IntPtr handle, IntPtr pointer, Int32 count) in R:\EDENRED\Ghostscript.NET\Ghostscript.NET-master\Ghostscript.NET\GhostscriptStdIO.cs:line 173

Code sample:

using (GhostscriptProcessor processor = new GhostscriptProcessor(gv, true))
            {
                List<string> switches = new List<string>();
                switches.Add("-q");
                switches.Add("-dNODISPLAY");
                switches.Add(@"-sFile=" + fileName);
                switches.Add("pdf_info.ps");

                // if you don't want to handle stdio, you can pass 'null' value as the last parameter
                StdIOHandler stdio = new StdIOHandler(_output, _error);
                processor.StartProcessing(switches.ToArray(), stdio);

                string output = _output.ToString();
            }

The stdio class used is this:

    public class StdIOHandler : GhostscriptStdIO
    {
        private StringBuilder _output = null;
        private StringBuilder _error = null;

        public StdIOHandler(StringBuilder output, StringBuilder error)
            : base(true, true, true)
        {
            _output = output;
            _error = error;
        }

        public override void StdIn(out string input, int count)
        {
            input = null;
        }

        public override void StdOut(string output)
        {
            if (_output != null)
            {
                _output.Append(output);
            }
        }

        public override void StdError(string error)
        {
            if (_error != null)
            {
                _error.Append(error);
            }
        }
    }

The exception is due to the current page parsing algorithm used here:


        private void ProcessOutputLine(string line)
        {
            if (line.StartsWith("Processing pages"))
            {
                string[] chunks = line.Split(EMPTY_SPACE_SPLIT);
                _totalPages = int.Parse(chunks[chunks.Length - 1].TrimEnd('.'));
            }
            else if (line.StartsWith("Page"))
            {
                string[] chunks = line.Split(EMPTY_SPACE_SPLIT);
                int currentPage = int.Parse(chunks[chunks.Length - 1]);

                this.OnProcessing(new GhostscriptProcessorProcessingEventArgs(currentPage, _totalPages));
            }
        }

for the line:

Page 1 MediaBox: [0.0 0.0 157.833 34.666] BleedBox: [0.0 0.0 157.833 34.666] TrimBox: [0.0 0.0 157.833 34.666] ArtBox: [2.76025

The next token after 'Page' should be checked in this case.

Regards,
Mike

@jhabjan
Copy link
Contributor

jhabjan commented Dec 13, 2016

Thanks. Fixed in version 1.2.1.

@jhabjan jhabjan closed this as completed Dec 13, 2016
@jhabjan jhabjan added the bug label Dec 14, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants