Skip to content
This repository has been archived by the owner on Aug 2, 2019. It is now read-only.

"Exception"/ "Error" when printing PDF - The operation completed successfully #180

Open
SchaFFFFFF opened this issue Oct 24, 2018 · 0 comments

Comments

@SchaFFFFFF
Copy link

SchaFFFFFF commented Oct 24, 2018

I have an application that is building a PDF and attempting to send it to a network printer. I am at a point now where some PDFs print and some do not. The PDFs that don't are not corrupt and can be printed manually, so the file is fine. And when they do not print, an exception is being thrown, but the Message is not fulpful at all; "The operation completed successfully." This is happening when the .Print() method is being called below.

// Set printer objects
var printerSettings = new PrinterSettings
{
     PrinterName = printerName,
     Copies = 1
};

// Create page settings
var pageSettings = new PageSettings(printerSettings)
{
     Margins = new Margins(0, 0, 0, 0)
};

// Now print the PDF document
using (var document = PdfiumViewer.PdfDocument.Load(combinedFilePath))
{
     using (var printDocument = document.CreatePrintDocument())
     {
          printDocument.PrinterSettings = printerSettings;
          printDocument.DefaultPageSettings = pageSettings;
          printDocument.PrintController = new StandardPrintController();
          printDocument.Print();
     }
}

Also here is most of the stack of where the error is happening.
Error: System.ComponentModel.Win32Exception (0x80004005): The operation completed successfully at System.Drawing.Printing.PrinterSettings.GetHdevmodeInternal(String printer) at System.Drawing.Printing.PrinterSettings.GetHdevmodeInternal() at System.Drawing.Printing.PrinterSettings.GetHdevmode(PageSettings pageSettings) at System.Drawing.Printing.PrintController.OnStartPrint(PrintDocument document, PrintEventArgs e) at System.Drawing.Printing.StandardPrintController.OnStartPrint(PrintDocument document, PrintEventArgs e) at System.Drawing.Printing.PrintController.Print(PrintDocument document) at System.Drawing.Printing.PrintDocument.Print()

Has anyone encountered this before and know how to fix it?

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant