We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Printing from a webservice

I’m done alot of searching to find a way to print an RTF document from a webservice. MS Word is not able to perform this task, and I’ve been referred by several people to Aspose. I’ve downloaded the trial version of Aspose.Words to see if this tool can perform this task. To test to see if this would work I setup a simple webservice and had it call the following (where safeFileName is a file I know exists on the server):

Aspose.Words.Viewer.DocumentRenderer doc = new Aspose.Words.Viewer.DocumentRenderer(safeFileName);
doc.PrinterSettings.PrinterName = "NetWork Printer";
doc.Print();

I added impersonation to web.config file so I know that I have security rights, but its still not working. I keep getting the following errors:

Exception: System.Drawing.Printing.InvalidPrinterException: Settings to access printer ‘NetWork Printer’ are not valid.
at System.Drawing.Printing.StandardPrintController.OnStartPrint(PrintDocument document, PrintEventArgs e)
at System.Windows.Forms.PrintControllerWithStatusDialog.OnStartPrint(PrintDocument document, PrintEventArgs e)
at System.Drawing.Printing.PrintController.Print(PrintDocument document)
at System.Drawing.Printing.PrintDocument.Print()
at Aspose.Words.Viewer.DocumentRenderer.Print()
at PrintRtfServiceApplication.Service1.PrintDocument(String safeFileName) in …Service1.asmx.cs:line 80
at PrintRtfServiceApplication.Service1.PrintRtf(String fileName, String rtf) in …Service1.asmx.cs:line 30

Any ideas?

Hi

Thanks for your inquiry. Please check the following link

https://docs.aspose.com/words/net/print-a-document-programmatically-or-using-dialogs/

Maybe this helps.

Best regards.

I’ve already setup impersonation in the web.config file so that the entire set of code is run with the correct security permissions. Unfortunately this doesn’t seem to change the problem at all.

Hi

I also found this could be caused by NTFS partitions. You have to have NTFS permission from the printer. This has to be granted to you by your network administrator. Please check this and let me know if this does not work for you.

Best regards.

I verified that I had permission to print by logging into the server using the same credentials as the user that I am impersonating. I was able to print just fine at that point.

Hi

Maybe this occurs because you are not logined. Try logining before printing. Just type in the command line \servername, enter your login and password and then try to print the document.

Best regards.

Alexey,

I am trying to set this up as a webservice. I don’t want the user to have to be directly logged into the server at all. To take care of this problem, I’m having the webservice use impersonation. Inside the web.config file for the webservice I have the following line of code:

Using this impersonation I have full rights on the machine, but still get the errors that I posted at the beginning. My only guess is that your product is somehow tied to the profile, that is, that unless you are actually logged into the machine, that you will be unable to print correctly. This would mean that your product would be unable to print from a webservice.

Please let me know if any of my assumptions are incorrect. I’ve heard great things about your product, and really hope that your product can be used to help me solve my problem, but being able to print from a webservice is absolutely essential if we are going to purchase your product.

Hi

Thanks for your inquiry. Could you please try using the following code for testing?

public void Test155()
{
    System.Drawing.Printing.PrintDocument pd = new System.Drawing.Printing.PrintDocument();
    pd.PrintPage += new System.Drawing.Printing.PrintPageEventHandler(pqr);
    pd.Print();
}

void pqr(object o, System.Drawing.Printing.PrintPageEventArgs e)
{
    System.Drawing.Image i = System.Drawing.Image.FromFile(@"C:\Temp\test.jpg");
    Point p = new Point(100, 100);
    e.Graphics.DrawImage(i, p);
}

Please let me know if this code print image without issues from your service.

Best regards.

I tried the code, and I got an error. The error said, “SoapException was unhandled”, “Server was unable to process request. —> No printers are installed.”

I don’t know how this could be. I actually have 3 different printers installed (2 of them are to print to documents). I logged in as the user that I’m impersonating and there is, in fact, a printer, and there is a default printer selected. What am I doing wrong?

Hi

Thanks for your inquiry. You can try setting printer name

pd.PrinterSettings.PrinterName = "printer name";

Hope this helps.

Best regards.

I tried that, but as soon as I do that it tells me that it received a “SoapException was Unhandled” “Server was unable to process request. —> Settings to access printer ‘printer name’ are not valid”

Hi

Thanks for your inquiry. Have you specified IP of the server where printer is installed? Please try using the following code to get correct printer names.

// Loop through the string collection of printers
foreach (string strPrinter in System.Drawing.Printing.PrinterSettings.InstalledPrinters)
{
    // Show the name of the printer
    MessageBox.Show(strPrinter);
}

Hope this helps.

Best regards.

I tried the code you suggested, and it listed the printer I’m trying to print to (it listed it exactly the way I’d typed it). I still get the same error that the settings to access the printer are not valid.

I don’t understand what setting I could be missing. I checked the printer’s actual settings to make sure there wasn’t any security issue. I checked the server to make sure that I had access (I even went so far as to allow anonymous users to be able to print). I double checked that the user I am impersonating has access (which I verified that he did by printing from that account). I verified that the printer was installed using your code. I verified that the basic code should work by testing it in a regular application. The only think I can think of is the fact that I am not actually logged in, but am using a webservice.

Hi

Thanks for your request. I found an interesting forum thread here

http://bytes.com/forum/thread261508.html

Maybe information provided there could help you to resolve the problem.

Best regards.

Hmm. It does look like this might help. I’ll give it a try and see if I can get Aspose working using this method and then let you know either way. Thanks again