I am using a .doc file as a template and populating merge fields in it to generate my document.
I’m using the latest version of Aspose.Words.
What I’m trying to achieve is the auto printing of a pdf when my code is finished populating all of the merge fields.
Currently I use the line of code:
in order to load it as a PDF in the browser.
What I want to do now instead is have the generated PDF go directly to the printer.
I’ve tried things like
resultDoc.Print(), but I find the browser page loads blank and just freezes and does nothing.
I’ve alos tried
Aspose.Words.Rendering.AsposeWordsPrintDocument abc = new Aspose.Words.Rendering.AsposeWordsPrintDocument(resultDoc);
abc.Print();
but again it just freezes.
I would have expected it to go directly to the printer, but I see nothing happening.
What am I doing wrong?
thanks.
Thanks for your request. Document.Print() method will print document on the server side. So, make sure the printer on your server is properly installed and accessible.
Note, there is no way to print the document on client side, since you have no access to the client’s printers.
Best regards.
I’m running it localhost right now, so I should have access to the printer without issues (as I can print no problem in other programs).
This is essentially my page load:
But I just get a frozen browser window instead of anything printing (I’m monitoring the print queue).
What else can I test? I don’t get why (when debugging) it hits the “.Print()” line, but then it just locks up.
I’ve got the “freezing” problem to go away by testing it out on .net3.5 instead of the .net1.1 I was using before.
So now I so something like:
resultDoc.Print("Dell Laser Printer 5310n");
But I am getting the error
Settings to access printer ‘Dell Laser Printer 5310n’ are not valid.
What settings do I need to check/change now that I got beyond the original problem? I’m ok if this only works in .net3.5 as we are upgrading our systems currently.
Thanks for your request. If you are developing Web application, I think, you should make sure that ASPNET (IUSR) user, which runs Web applications, has access to the printer.
Best regards.
The Website is running under the domain admin account for testing.
I’ve also set the on in the web.config file but I still get the same “settings no valid” error.
How else can I test that it has access to the printer?
Thanks for your request. Please try to create simple console application, which will print a Word document using Aspose.Words (just for test purposes). Use code like the following:
Document doc = new Document(@"C:\Temp\test.doc");
PrinterSettings printerSettings = new PrinterSettings();
printerSettings.PrinterName = @"hp LaserJet 1010 Series Driver";
doc.Print(printerSettings);
Also, you can try specify another printer, for example you can try using Image Writer
In my web app, I’ve tried using the image writer and that worked out perfectly…it created the file on my C drive.
However, even after trying more than one network printer, I get settings not valid error.
Correct me if I’m wrong, but I’ve set the user for the IIS website to be the domain administrator account (to eliminate potential security problems during testing), but I still get the message. Do I really care about the ASPNET (IUSR) user account if I have the website running under the domain admin?
Is there another web based test I could test to see if I can access the printer?
Thanks.
I am using impersonation (via my web.config) already.
As a side note, when I use the following code, I don’t see any network printers listed (only local printers). This seems to be the problem. Not sure why (when using impersonation) it won’t see the network printers.
System.Drawing.Printing.PrintingPermission PrintingPermission = new System.Drawing.Printing.PrintingPermission(System.Security.Permissions.PermissionState.Unrestricted);
PrintingPermission.Level = System.Drawing.Printing.PrintingPermissionLevel.AllPrinting;
foreach(string printerStr in System.Drawing.Printing.PrinterSettings.InstalledPrinters)
{
Response.Write("Printer: " +printerStr);
}
New update.
I am now able to get the network printers to show up in my response.write code as written in my last post.
I did this by making sure to impersonate the windows account where I installed the printers (i.e. myusername, and not the admin account).
So, I can see the network printers now, but I STILL get the settings not valid error.
Any other help?
Hi
Maybe you can try the solution described here: https://social.msdn.microsoft.com/Forums/en-us/325206c1-66a3-4fea-8fb9-3d3e6374f1ab/settings-to-access-printer-herculesprtmark01-are-not-valid
Best regards.
However, still the same error message. Like I said before, I can now see the network printer when I check all installed printers using impersonation, but cannot get to print to it.
I FINALLY got it!
It was the stupid server name that I was missing from the printer name
I added "networkservername\ before the printer and I heard the sweet noise of the printer firing up.
Thanks for you r help.