Spire.Doc is a professional Word .NET library specifically designed for developers to create, read, write, convert and print Word document files. Get free and professional technical support for Spire.Doc for .NET, Java, Android, C++, Python.

Tue Sep 20, 2022 10:48 pm

I am using the licensed Pro Edition of Spire.Doc 10.7.16.0. A document is created by loading a Word template and populating its bookmarks.
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();

Last edited by Les43625 on Wed Sep 21, 2022 12:42 am, edited 2 times in total.

Les43625
 
Posts: 12
Joined: Tue Feb 22, 2022 1:41 am

Wed Sep 21, 2022 1:36 am

Resolved; the document created from a .DOT template was not in a printable state. I saved the doc to a temporary file and closed it, then reloaded it into a new Spire Document instance, and it printed correctly.

Les43625
 
Posts: 12
Joined: Tue Feb 22, 2022 1:41 am

Wed Sep 21, 2022 6:35 am

Hello,

Thank you for sharing your solution.
If you have any issue, just feel free to contact us. Have a nice day!

Sincerely
Abel
E-iceblue support team
User avatar

Abel.He
 
Posts: 860
Joined: Tue Mar 08, 2022 2:02 am

Return to Spire.Doc