Free Support Forum - aspose.com

Error encountered when printing from Aspose.PDF

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

Hi June,<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

Thank you for sharing the template file and sample code.

I tested your issue on my machine and I am unable to reproduce the issue. I am using Windows 7 32 bit with VS2008 and .NET Framework 2.0. Please share the details regarding your system environment on which you are facing the issue. We will check it and get back to you soon.

Sorry for the inconvenience,

We’ve been unable to determine the exact pattern to replicate this issue. I don’t encounter the error on my machine which is Windows 7 64bit but pretty consistent with some of our servers like Windows Server 2008 R2. The application is built under Visual Studio 2010 using .NET Framework 3.5. The application is hosted in ASP.NET environment that we configure in IIS.


Do you have some sort of a tool that we can run that will help us determine the cause of the issue?

Hi June,<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

Thank you for the feedback.

We will check your issue under Windows 2008 R2 environment and share our results with you soon. Regarding any tool to identify the issue, I am afraid; we don’t have any tool to check such issues.

Sorry for the inconvenience,

Thanks and please let me know what you find. We really need to move to Aspose.PDF because of the several issues our clients are encountering when printing with Aspose.PDF.Kit (low quality printing, missing text, etc) and this issue is preventing us to upgrade.

Hi June,<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

I have further tested the issue on Windows Server 2008 R2 but I am unable to reproduce the issue. I would request you to share your sample application which can help us in reproducing the issue.

Sorry for the inconvenience,

Are you printing from a physical printer? I am asking because we had a similar case last time (collate) where you had difficulty replicating the issue until you tried to print to a physical printer.


Also if you will notice in the code, we are passing the page and printer settings to PrintDocumentWithSettings and it errors out in get_HardMarginX(). Any thoughts on what particular property in pagesettings and printersettings that could lead to divide by zero so we can check too.

Thanks,
June

Hi June,<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

Thank you for the details.

I tested it on a virtual server. However, I will try it on a physical printer and share the details with you soon.

Sorry for the inconvenience,

Hi Nausherwan,


Any update on this? Is there anything we can check in our end with regards to the properties of page and printer settings that could result to divide by zero?

Thanks,
June

Just an additional info the printer that we are using is Fuji Xerox Docucentre IV.

Hi June,<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

Please accept my apologies for the delay.

I am checking your issue and will get back to you with the results soon.

Sorry for the inconvenience,

Hi June,


Please accept my apologies for the delayed response. I’ve tested the scenario on a physical printer, Hp Laserjet 1020, and unfortunately I couldn’t reproduce the reported issue. For further investigation, could you please share a sample solution to replicate the issue?

Thanks for your patience and understanding.

Best Regards,
Can we possibly trick it to use the Fuji Xerox Docucentre IV driver to see if we will encounter the issue?

Or maybe give us some insight on what could possibly cause the divide by zero error in this call stack:

at System.Drawing.Printing.PageSettings.get_HardMarginX()
at Aspose.Pdf.Facades.PdfViewer.PrintDocumentWithSettings(PageSettings pageSettings, PrinterSettings printerSettings)

Thanks,
June

Hi June,


I just have tested the scenario using Aspose.Pdf for .NET 7.6.0 over Windows 7(X64) in Visual Studio 2010 application with target platform of application as .NET Framework 3.5 and I am unable to notice issue while printing the file to XPS format. Can you please try using the latest release version of Aspose.Pdf for .NET 7.6.0 and see if the problem still persists.

As per your suggestion, I have downloaded Fuji Xerox Docucentre IV driver but since I don’t have Fuji printer, so I am not how can I use these drivers to create soft printer. We are really sorry for your inconvenience.