I am using free spire.pdf v3.2.52.56040 to print existing pdf documents.
It prints about 1900+ documents and crashes with the either of the following message:
Handle is invalid or A generic error occurred in GDI+.
Here is the code that i am using.
- Code: Select all
PdfDocument doc = new PdfDocument();
try
{
doc.LoadFromFile(PrintFilePath);
doc.PrinterName = printer;
bool canDuplex = doc.PrintDocument.PrinterSettings.CanDuplex;
if (canDuplex)
{
doc.PrintDocument.PrinterSettings.Duplex = Duplex.Vertical;
}
if (doc.PrintDocument.PrinterSettings.IsValid)
{
doc.PrintDocument.Print();
}
else
{
throw new Exception(printer + " : Invalid Printer or Printer Settings");
}
}
catch (Exception ex)
{
throw new Exception(printer + " :" + ex.Message);
}
finally
{
doc.PrintDocument.Dispose();
doc.Close();
doc.Dispose();
}