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

Free Support Forum - aspose.com

Printing PDF returns Exception


When trying to print a PDF document to a network printer an error is returned:

System.DivideByZeroException: Attempted to divide by zero.
at System.Drawing.Printing.PageSettings.get_HardMarginX()
at Aspose.Pdf.Facades.PdfViewer.PrintDocumentWithSettings(PageSettings pageSettings, PrinterSettings printerSettings)

The code:

public static void PrintToMailRoom(Document document)

using (PdfViewer viewer = new PdfViewer())

viewer.AutoResize = true;
viewer.AutoRotate = true;
viewer.PrintPageDialog = false;

var printerSettings = new PrinterSettings();
var pageSettings = new PageSettings
PaperSize = new PaperSize(“A4”, 827, 1169),
Margins = new Margins(0, 0, 0, 0)

printerSettings.PrinterName = MailRoomPrinter;

viewer.PrintDocumentWithSettings(pageSettings, printerSettings);

private static void AssertPrinterIsInstalled()
if (PrinterSettings.InstalledPrinters.Cast().Any(printer => printer.ToLower() == MailRoomPrinter.ToLower()))

throw new Exception(String.Format("The printer " +
“{0} is not known as an installed printer. No print job can be created.”
, MailRoomPrinter));

Can someone please help me out?


Hi Gorden,

Thanks for your inquiry. Can you please share your problematic document here? It will help us to replicate the issue at our end and we will investigate it further.

Sorry for the the inconvenience caused.

Best Regards,