GrapeCity Forums

The GrapeCity Message Boards
Welcome to GrapeCity Forums Sign in | Join | Help
in Search

Getting Win32Exception that I can't catch on PDF Print

Last post 07-03-2009, 10:31 AM by scotts. 5 replies.
Sort Posts: Previous Next
  •  07-01-2009, 5:29 PM 79754

    Getting Win32Exception that I can't catch on PDF Print

    I perform printing on a spread using the following:

                 PrintInfo printset = new PrintInfo();
                printset.PrintToPdf = true;
                printset.PdfFileName = pdfFileName;

                foreach (SheetView sheet in mySpread.Sheets)
                {
                    sheet.PrintInfo = printset;
                    mySpread.PrintSheet(sheet);
                }

     

    If I have a network printer attached that for some reason I can't access (server down, wrong username/pw, etc) then it appears a background thread is throwing a Win32Exception with the message "The RPC server is unavailable".  I don't believe this to be an issue with Spreads persay, but the only solution I've found is by creating a class that inherits from PrintDocument and overloading some functions.

    Here is the stack trace of the exception:

       at System.Windows.Forms.Control.MarshaledInvoke(Control caller, Delegate method, Object[] args, Boolean synchronous)
       at System.Windows.Forms.Control.Invoke(Delegate method, Object[] args)
       at FarPoint.Win.Spread.FpSpread.q()
       at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
       at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
       at System.Threading.ThreadHelper.ThreadStart()

     

    And here is a thread with how to handle this Exception by overloading methods:

    http://www.dotnetmonster.com/Uwe/Forum.aspx/winform/16852/PrintPreviewDialog-and-Win32Exception-The-RPC-server-is-unavailab

     

    Is this a problem already potentially handled in Spreads, and if not is there a way I can reach to that low level of printing?

    Filed under: , ,
  •  07-02-2009, 8:24 AM 79778 in reply to 79754

    Re: Getting Win32Exception that I can't catch on PDF Print

    Hello,

    I tested it with a shared printer, by making it not accessible and found that no Exception was thrown using the code provided by you.

    I am using Spread(latest) v4.0.2010.2005 for Windows Forms, please upgrade to the same if you are using an older version and let me know your observations.

     

     

    Regards,

     


    Deepak Sharma
    GrapeCity FarPoint
  •  07-02-2009, 10:36 AM 79787 in reply to 79778

    Re: Getting Win32Exception that I can't catch on PDF Print

    I made sure I was referencing 4.0.2010.2005 WinForm DLLs, I get the same exception and stacktrace now but the message is "Access is denied."
  •  07-02-2009, 2:39 PM 79802 in reply to 79787

    Re: Getting Win32Exception that I can't catch on PDF Print

    Hi,

    I tested the snippet with 4.0.2010.2005 and did not get any exception while printing to a n/w printer from spread using the PrintInfo object. Any additional steps required to reproduce the issue at our side?


    Suresh Singh Dasila
    GrapeCity FarPoint
  •  07-02-2009, 2:57 PM 79803 in reply to 79802

    Re: Getting Win32Exception that I can't catch on PDF Print

    I'm not trying to print to the network printer, I'm trying to make a PDF export while a network printer is attached but not available.  It's also not an exception thrown by the Spread component but instead by a background thread used by some Win32Api calls at a bit lower level.

    Other than the snippet provided and a network printer that fails to connect I'm not sure how else to reproduce the issue.  I can reliably reproduce it on at least 2 machines here in the office: one XP and one Vista, both using 4.0.2010.2005 DLLs.  For what it's worth both also have .Net v2 SP2.

    The worst part is the inability to catch the exception since it occurs on another thread, instead it just forces my application to exit entirely.  Using a debugger I can see the exception, but still do nothing about it other than an Unhandled Exception event handler which still will force my app to exit.

  •  07-03-2009, 10:31 AM 79823 in reply to 79803

    Re: Getting Win32Exception that I can't catch on PDF Print

    Hello,

    I am not sure about the exception, but I do know the code you have written is not safe code. Since the PrintSheet method will spawn another thread (as you have seen) to implement the print, you can can not just keep calling the printSheet method in a tight loop as you are. You would need to either catch the PrintMessageBox event to be notified when the first print is finished (BeginPrint parameter will be sent in as False). Or you can use an undocumented method called SafePrint. The SafePrint method will print the Spread on the same thread as the executing call, so you would not need to worry about waiting for an event to call to be notified the print job is finished.

    To call the SafePrint method, you would use code like the following.

               int i = 0;
               foreach (SheetView sheet in mySpread.Sheets)
                {
                    sheet.PrintInfo = printset;
                    mySpread.SafePrint(mySpread, i);
                    i++;
                }

    Also, if you are printing all sheets, you can set the PrintInfo property for each sheet before the print and then call the PrintSheet method and pass in a -1 which will tell Spread to print all sheets.


    Scott S.
    Product Manager, Spread ASP.NET
    GrapeCity FarPoint
View as RSS news feed in XML
     FarPoint Forums Home