This project is read-only.

Processing event of GhostscriptProcessor class

Dec 13, 2013 at 1:55 PM
I am having difficulty subscribing to the Processing event of GhostscriptProcessor class. Any help would be greatly appreciated. Here's my code.

Public Class PostscriptToPDFConverter
Inherits Ghostscript.NET.Processor.GhostscriptProcessor

Public Event UpdateExtraInfo(ByRef lstrInfo As String, ByVal lblnLog As Boolean)

Public Sub Convert(lstrInputPSFile As String)

    Dim lstrOutputPDF As String = System.IO.Path.ChangeExtension(lstrInputPSFile, ".pdf")
    Dim lstrInfo As String = String.Empty

    lstrInfo = String.Format("Convert {0} to {1}", System.IO.Path.GetFileName(lstrInputPSFile), System.IO.Path.GetFileName(lstrOutputPDF))
    RaiseEvent UpdateExtraInfo(lstrInfo, True)

    Dim switches As New List(Of String)()
    switches.Add(String.Format("-sOutputFile={0}", lstrOutputPDF))

    AddHandler MyBase.Processing, AddressOf GSProcessing
    MyBase.StartProcessing(switches.ToArray(), Nothing)
    RemoveHandler MyBase.Processing, AddressOf GSProcessing

End Sub

Private Sub GSProcessing(sender As Object, e As Ghostscript.NET.Processor.GhostscriptProcessorProcessingEventArgs)
    Dim lstrInfo As String = String.Format("Page: {0} out of {1}", e.CurrentPage, e.TotalPages)
    RaiseEvent UpdateExtraInfo(lstrInfo, True)
End Sub
End Class
Dec 13, 2013 at 2:07 PM
Edited Dec 13, 2013 at 2:15 PM

Remove "switches.Add("-dQUIET")" as this switch suppresses routine information comments on standard output which Processing event relays on.

Dec 13, 2013 at 2:29 PM
Thanks for the prompt response, but it hasn't made any difference. I also tried commenting out all the switches below to see if they had any effect but still no event:-
' switches.Add("-dQUIET")
' switches.Add("-dSAFER")
' switches.Add("-dBATCH")
' switches.Add("-dNOPAUSE")
' switches.Add("-dNOPROMPT")
Dec 14, 2013 at 11:59 AM

I did not saw earlier that you are converting PostScript to PDF. I spoke with the developers of the Ghostscript native library and they said that the thing is that a PDF file is a structured format which includes (amongst other things) a definition of the number of pages. PostScript is a streamable simple format and does not contain that information. Some PostScript files contain 'DSC' comments which declare the number of pages in the document. However these can include the not terribly useful 'atend' value, which means that the number of pages is defined at the end of the program. By which time, of course, an interpreter knows how many pages there are, because its processed them all.

That means that by default for the PostScript files there is no way to get back information from the Ghostscript which PostScript page is processing.

Dec 17, 2013 at 11:38 AM
Makes sense. However couldn't it still trigger the event and just populate the e.CurrentPage property whilst leaving the e.TotalPages property at zero or minus one or something, just so we can show some on-screen activity during processing?
Jan 29, 2014 at 11:57 AM
Any news on this one?
Jan 29, 2014 at 5:23 PM
Edited Jan 29, 2014 at 5:24 PM
This could be eventually done by manually parsing the postscript file, determining page start/end and sending each page to render separately. Something what I did in the [GhostscriptViewerPsFormatHandler.cs] which relies on the DSC comments. (

When I find some time I will try to put together some code...