We have recently deployed window service on our test server which uses aspose.words to create a word document and then send it to the printer. This service is installed on corporate network account and have access to the printer and drivers are installed on it too.
I have used the following code to print the document
-----------------------------------------------------------------------------
Dim prtdoc As Rendering.AsposeWordsPrintDocument = New Rendering.AsposeWordsPrintDocument(doc)
Dim ps As PrinterSettings = New PrinterSettings
Dim Pgs As PageSettings = New PageSettings()
ps.PrinterName = printername
Try
For Each source As PaperSource In ps.PaperSources
If source.SourceName = TraytoPrint Then
Pgs.PaperSource = source
End If
Next
ps.PrintRange = PrintRange.AllPages
prtdoc.PrinterSettings = ps
ps.DefaultPageSettings.PaperSource = Pgs.PaperSource
prtdoc.DefaultPageSettings = Pgs
prtdoc.Print()
prtdoc.Dispose()
Catch ex As Exception
Printed = False
CatchAnError = ex.ToString
End Try
prtdoc.Dispose()
-------------------------------------------------------------------------------------------------
I am not able to print the document, rather the following is printed on the paper.
I would appreciate if you could let me what permission ASPOSE uses to print the document and what is going wrong in here. We really like to get this resolve so we can buy aspose.words license. thanks
Thanks for your interest in Aspose.Words. Please try using the following overload of Print method which prints the document according to the specified printer settings, using the standard (no User Interface) print controller.
public void Print(PrinterSettings);
Also, please try running the ‘XpsPrint’ demo project; you can find this project in offline sample pack here. This demo project demonstrates how to use Aspose.Words for .NET to print documents using the XpsPrint API. I hope, this helps.
We have managed to print now but it seems to change font size when printing.
If we view the document in Word or Acrobat it looks fine. Also If we print the document from Acrobat or word it prints fine too.
It’s
only when we print via ASPOSE, font size changes.
We have tried multiple printers of different manufacturers but the problem persists in all.
Can you please help?
Thanks for your inquiry. Please make sure you have all the fonts installed on the machine you’re printing your documents. Aspose.Words performs fonts substitution during rendering a document. So, if the font is not available when the document is rendered, it will be replaced with an alternative font. Instead of window service, could you please try printing from a simple console application and let us know how it goes? Also, please attach a sample input word document, fonts and source code you used for printing here for testing. I will investigate the issue on my side and provide you more information.
As suggested I have modified the code so that printer settings are passed into print method.
It is printing fine but it ignores the printer settings defined for paper source. I am trying to print on Cassette 1 but it ignores the paper source settings completely and always prints from Cassette 2. Any clue to why printer settings are not getting picked up.
Dim ps As PrinterSettings = New PrinterSettings
ps.PrinterName = printername
Try
For i = 0 To ps.PaperSources.Count - 1
If ps.PaperSources.Item(i).SourceName = TraytoPrint Then
ps.DefaultPageSettings.PaperSource = ps.PaperSources.Item(i)
Exit For
End If
Next
ps.PrintRange = PrintRange.AllPages
doc.Print(ps)
Catch ex As Exception
CatchAnError = ex.ToString
End Try
I have changed it so it is printing using xps api as suggested however it will not print to the correct tray even if defined within the document template.
I am opening an existing word document, replacing bookmark with data and then trying to print the document using xps api but it wont print to the correct tray (cassette 1) which is defined within the document tempalte itself. I have attached the document I am trying to print.
Can you please suggest what can be done to resolve this problem?
Thanks for the addional information. Aspose.Words supports printing as per the paper tray values stored in the document.
Aspose.Words reads values from document in Raw format (i.e. as int) and after Print method is called, a function compares the Raw value of PaperTray of current page and values in PrinterSettings.PaperSources and if it doesn’t find coincidence, function returns “Automatic” value. Then it passes the value for PaperTray to underlying Windows function that actually sends document to printer.
You should also note that paper tray numbers are printer specific. I suppose the problem might occur because paper trays numbers specified in your document do not match paper tray numbers of the printer running on your local environment. So, first of all you should make sure that paper trays in your document are specified correctly.
Please let me know if I can be of any further assistance.
I am not able to set any values in codes when using XPS api. I have only defined the correct paper tray in the document template which is not getting picked up. So, I am not sure what you mentioned above will resolve the problem I have using.
How can we define the paper source settings when using XPS API, that was my question.
I really need urgent response to this problem otherwise we would have to start thinking about alternative product in the market.
Thanks for your inquiry. Regarding my previous reply, since you have specified number 14 as the paper tray source, all pages in “statement template.doc” will be printed to 14th paper tray of the selected printer. Could you please run the following code to determine whether a tray with number 14 actually exists in your printer?
PrinterSettings settings = new PrinterSettings();
settings.PrinterName = "name of your multi-tray printer";
foreach (PaperSource ps in settings.PaperSources)
Console.WriteLine(ps.RawKind);
Secondly, I have attached a sample project with this post; the GetPrintTicketFromPrinter method should be what you need. There is a similar thread on MSDN Forum which states you need to manually get the PrintTicket XML and modify the desired values. Please follow the code given here and hopefully it will all work.
Best regards,
Cookie Notice
To provide you with the best experience, we use cookies for personalization, analytics, and ads. By using our site, you agree to our cookie policy.
Enables storage, such as cookies, related to analytics.
Sets consent for sending user data to Google for online advertising purposes.
Sets consent for personalized advertising.
Cookie Notice
To provide you with the best experience, we use cookies for personalization, analytics, and ads. By using our site, you agree to our cookie policy.
More info
Enables storage, such as cookies, related to analytics.
Enables storage, such as cookies, related to advertising.
Sets consent for sending user data to Google for online advertising purposes.
Sets consent for personalized advertising.
Cookie Notice
To provide you with the best experience, we use cookies for personalization, analytics, and ads. By using our site, you agree to our cookie policy.
More info
Enables storage, such as cookies, related to analytics.
Enables storage, such as cookies, related to advertising.
Sets consent for sending user data to Google for online advertising purposes.