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

Free Support Forum - aspose.com

Printing with PrinterSettings not working

I have tried to use Aspose Words.NET and Aspose PDF .NET to print documents to a printer with PrinterSettings. I need to specify printing properties such as paper size (A3/A4), Landscape/Portrait orientation, paper tray to use, etc.

I have tried to use PdfViewer.PrintDocumentWithSettings and Aspose.Words.Document.Print, but without success. Here is a code fragment for Aspose.Words.

// I have previously loaded the printer setting options into combo boxes cBSources and cbSizes
System.Drawing.Printing.PaperSize pSize;
System.Drawing.Printing.PaperSource pSource;
PrinterSettings pS = new PrinterSettings();
pS.PrinterName = strPrinterName;
for (i = 0; i < ps.PaperSources.Count; i++)
pSource = ps.PaperSources[i];
for (i = 0; i < ps.PaperSizes.Count; i++)
pSize = ps.PaperSizes[i];

// later I want to use selected parameters to print a document
PrinterSettings pS = new PrinterSettings();
Aspose.Words.Document document = new Aspose.Words.Document(strFileName);
pS.PrinterName = strPrinterName;
ps.Duplex = Duplex.Simplex;
ps.DefaultPageSettings.Color = false;
ps.DefaultPageSettings.Landscape = true;
if(cbSources.SelectedIndex != -1)
ps.DefaultPageSettings.PaperSource = ps.PaperSources[cbSources.SelectedIndex];
if (cbSizes.SelectedIndex != -1)
ps.DefaultPageSettings.PaperSize = ps.PaperSizes[cbSizes.SelectedIndex];

The document always prints in portrait and A4 size (the printer defaults) no matter what I choose for size, orientation, etc.
I get the same result using Aspose PDF for .NET.
Is there a different method I should use. Do you have a code sample I can use?

Many Thanks

Hi Peter,

Please try changing page setup before print e.g.

DocumentBuilder db = new DocumentBuilder(doc);<?xml:namespace prefix = "o" ns = "urn:schemas-microsoft-com:office:office" />

db.PageSetup.PaperSize = Aspose.Words.PaperSize.A4;

Best Regards,