Hi,
We are trying to migrate from Aspose.PDF.Kit to Aspose.PDF because it contains several fixes that we reported in Aspose.PDF.Kit. However upon testing printing, we are encountering the error "Attempted to divide by zero" after calling the PrintDocumentWithSettings(). This doesn't happen in Aspose.PDF.Kit using the same code and we are using the latest version of Aspose.PDF (v7.4).
Here's the code:
Public Sub PrintReportFromPDF(ByVal PDFPath As String, ByVal PrintArgs As PrintReportArgs)
'create PdfViewer object
Dim viewer As New PdfViewer()
Dim asposeLicense As Aspose.Pdf.License = New Aspose.Pdf.License
Dim errVar As Framework.Errors.Common.FrameworkException
Try
asposeLicense.SetLicense("Aspose.Pdf.lic")
viewer.OpenPdfFile(PDFPath)
'set attributes for printing
viewer.AutoRotate = True
viewer.PrintPageDialog = False 'do not produce the page number dialog when printing
'create objects for printer and page settings and PrintDocument
Dim ps As New PrinterSettings()
Dim pgs As New System.Drawing.Printing.PageSettings()
Dim prtdoc As New System.Drawing.Printing.PrintDocument()
ps.PrinterName = PrintArgs.DefaultPrinter
'set the color
pgs.Color = PrintArgs.PrintColor
ps.Copies = CShort(PrintArgs.PrintCopies)
ps.Collate = PrintArgs.PrintCollate
ps.PrintRange = PrintRange.AllPages
''Set Page Size
For i As Integer = 0 To ps.PaperSizes.Count - 1
If ps.PaperSizes(i).RawKind = PrintArgs.PrintPageSize Then
pgs.PaperSize = ps.PaperSizes(i)
Exit For
End If
Next
'Set Paper Tray
For i As Integer = 0 To ps.PaperSources.Count - 1
If ps.PaperSources(i).RawKind = PrintArgs.PrintPaperTray Then
pgs.PaperSource = ps.PaperSources(i)
Exit For
End If
Next
pgs.Margins = New System.Drawing.Printing.Margins(0, 0, 0, 0)
viewer.PrintDocumentWithSettings(pgs, ps)
viewer.ClosePdfFile()
Catch ex As Exception
End Try
End Sub
Here's the call stack of the error:
Stack:
at System.Drawing.Printing.PageSettings.get_HardMarginX()
at Aspose.Pdf.Facades.PdfViewer.PrintDocumentWithSettings(PageSettings pageSettings, PrinterSettings printerSettings)
Any idea what is causing this? We encountered this in most of the servers that we have but not all (3 out of 4).
Thanks,
June
June