When the Print method is called I get a object reference exception.
System.NullReferenceException
HResult=0x80004003
Message=Object reference not set to an instance of an object.
Source=Spire.Doc
StackTrace:
at Spire.Doc.Documents.Paragraph.()
at spr᳔.ᜁ(DocumentObject A_0)
at spr᪳.ᜩ()
at spr᪳.ᜳ()
at spr.ᜀ(Document A_0, spr A_1)
at Spire.Doc.Document.ល()
at Spire.Doc.Document.OnBeginPrint(Object sender, PrintEventArgs e)
at System.Drawing.Printing.PrintDocument.OnBeginPrint(PrintEventArgs e)
at System.Drawing.Printing.PrintController.Print(PrintDocument document)
at System.Drawing.Printing.PrintDocument.Print()
I have followed the guides for printing with and without System.Windows.Forms.PrintDialog().
This will run in a background service without a UI, so really hope I can make it print without trying to show any dialogs.
Does the document need to be saved to a file before printing?
Using this:
- Code: Select all
PrintDocument printDoc = spireDoc.PrintDocument;
printDoc.PrintController = new StandardPrintController();
printDoc.PrinterSettings = new PrinterSettings()
{
PrinterName = printerName,
Copies = (short)numberOfCopies
};
printDoc.Print();