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.

Wed Nov 13, 2013 3:37 pm

Hello,

I'm trying to print a document from the code behind in ASP.NET application. It is working fine in winForms.

First attempt:
Code: Select all
   Document doc = new Document();
            doc.LoadFromFile("C:\\Temp\\word.docx");
            PrintDocument printDoc = doc.PrintDocument;
            printDoc.Print();

doc.PrintDocument = 'doc.PrintDocument' threw an exception of type 'System.NullReferenceException'

Then I added a WinForm dialog call from your sample (what is weird in asp.net app):
Code: Select all
         PrintDialog dialog = new PrintDialog();
                dialog.AllowPrintToFile = true;
                dialog.AllowCurrentPage = true;
                dialog.AllowSomePages = true;
                dialog.UseEXDialog = true;
                document.PrintDialog = dialog;
                PrintDocument printDoc = document.PrintDocument;
                printDoc.Print();

And now the exception is on the last line printDoc.Print() - "No printers are installed."

Printers are installed, and the same code works in console or winforms application.

Any ideas?

Thank you.

Pierrers
 
Posts: 8
Joined: Wed Nov 13, 2013 2:59 pm

Thu Nov 14, 2013 7:18 am

Hello,

Thanks for your inquiry.
Where is your printer installed? Where did you test the print method in ASP.net application? publish to IIS or local?
Could you please refer to the following method to select Microsoft XPS Document Writer as default printer and try it again.
Code: Select all
 
Document doc = new Document();
string filename = Server.MapPath("Word.doc");
doc.LoadFromFile(filename);
PrintDialog dialog = new PrintDialog();
dialog.AllowPrintToFile = true;
dialog.AllowCurrentPage = true;
dialog.AllowSomePages = true;
dialog.UseEXDialog = true;
doc.PrintDialog = dialog;
PrintDocument printDoc = doc.PrintDocument;
if(dialog.ShowDialog()==DialogResult.OK)
            {
                printDoc.Print();
            }

Thanks,
Gary
E-iceblue support team
User avatar

Gary.zhang
 
Posts: 1380
Joined: Thu Apr 04, 2013 1:30 am

Thu Nov 14, 2013 9:33 am

Thank you for your answer.

The code that you posted is exactly the same that I use already.

Printers is installed on both server and client computers and, as I already mentionned, the same code works for a WinForm application.

My application is actually a Sharepoint 2010 webpart, and I run it in a virtual machine environnement.

Pierrers
 
Posts: 8
Joined: Wed Nov 13, 2013 2:59 pm

Thu Nov 14, 2013 11:22 am

I made another test, this time creating a new web application. Event it is weird to use WinForms dlls in an asp.net application, the printing works. But it still does not work in Sharepoint context.

Pierrers
 
Posts: 8
Joined: Wed Nov 13, 2013 2:59 pm

Fri Nov 15, 2013 8:23 am

Hello,

Thanks for your feedback.
We will investigate the issue, and get it back to you ASAP. Sorry for inconvenience.

Thanks And Regards,
Gary
E-iceblue support team
User avatar

Gary.zhang
 
Posts: 1380
Joined: Thu Apr 04, 2013 1:30 am

Tue Nov 19, 2013 9:02 am

Hello,

Thanks for your waiting.
We have done some investigation, you could try specifying name of network printer using IP addresse, please refer to the following code and try it, also, make sure that the sharepoint has rights to visit the printer.
Code: Select all
printDoc.PrinterSettings.PrinterName = @"\\192.168.1.108\HP LaserJet P1007";

If there are any questions, welcome to get it back to us.

Sincerely,
Gary
E-iceblue support team
User avatar

Gary.zhang
 
Posts: 1380
Joined: Thu Apr 04, 2013 1:30 am

Tue Nov 19, 2013 3:34 pm

Thank you, we will finally use a PDF.

Pierrers
 
Posts: 8
Joined: Wed Nov 13, 2013 2:59 pm

Return to Spire.Doc

cron