Printer Settings Pro-grammatically - Aspose.Words

Hi,

I recently started looking into Aspose.Words Library for solving my document related problems. My Experience was successful, and i’m just stuck on one thing. I want to set my Printer and Tray Settings programmatically, is it possible using Aspose.Words ?

I don’t want the user to see that Print Dialog, and even on Print Dialog, there is no option for setting Tray Number. So i’m sorting my questions below for easy understanding:

  1. Can I get names of Installed Printers ? (as i can see in Print Dialog)

  2. Can I set a specific printer for printing my documents programmatically? (Without showing PrintDialog)

  3. Main problem is, Can I set Tray Number while printing ?

I’d be obliged if i can get help regarding my issues. Thanks a lot.

Regards,
Maher Shahmeer

Thanks Tahir Manzoor.
But I’m really sorry to say that i asked specifically for Aspose.Words Java library.
I’m not using .NET.
Can you please guide me with Java references ?

Best,
Maher Shahmeer

Hi Maher,

Please accept my apologies for your inconvenience. Please check the following detail about printing documents using Aspose.Word for Java.

Shahmeer:

I want to set my Printer and Tray Settings programmatically, is it possible using Aspose.Words ?
3. Main problem is, Can I set Tray Number while printing ?

Following code example changes all sections in a document to use the default paper tray of the selected printer.

Document doc = new Document(MyDir + "in.docx");
//Find the printer that will be used for printing this document. In this case it is the default printer.
//You can define a specific printer by using PrintServiceLookup.lookupPrintServices. 
PrintService printService = PrintServiceLookup.lookupDefaultPrintService();
Media defaultTray = (Media)printService.getDefaultAttributeValue(Media.class);
//The paper tray value stored in documents is completely printer specific. This means
//The code below resets all page tray values to use the current printers default tray.
//You can enumerate getSupportedAttributeValues for Media type to find the other valid
//paper tray values of the selected printer.
for (Section section : doc.getSections())
{
    section.getPageSetup().setFirstPageTray(defaultTray.getValue());
    section.getPageSetup().setOtherPagesTray(defaultTray.getValue());
}

Shahmeer:

I don’t want the user to see that Print Dialog, and even on Print Dialog, there is no option for setting Tray Number.

Document.Print
method prints the document without bringing up any user interface
forms. Please read the overloaded methods of Document.Print from here:
https://reference.aspose.com/words/java/com.aspose.words/document#print()

Shahmeer:

  1. Can I set a specific printer for printing my documents programmatically? (Without showing PrintDialog).

You
can use Document.Print(String) method to print the whole document to
the specified printer, using the standard (no User Interface) print
controller.

Shahmeer:

  1. Can I get names of Installed Printers ? (as i can see in Print Dialog)

*Please check following link for your kind reference.
https://stackoverflow.com/questions/410967/how-do-i-get-a-list-of-installed-printers

https://docs.microsoft.com/en-us/dotnet/api/system.drawing.printing.printersettings.installedprinters?view=dotnet-plat-ext-6.0

Hi,

I want to Programmatically select List of Markup from document info in Print Settings before printing it as PDF. Is this Possible in Aspose Words?

@NanthiniSenthil123 Unfortunately, there is no way to achieve this using Aspose.Words.