Excel Automation: PDF export brings up the Printer Setup pop-up

I am developing an application to automatically generate Excel to PDF. From time to time (and for no apparent reason, the following pop-up window appears during program execution:

The printer driver host for 32-bit applications stops working.

Print driver host for 32bit applications stopped working

and, shortly afterwards:

Printer Setup

Printer setup popup

What if anything I need to do here? My application is not too complicated. An error always (100%) occurs on this line:

_application.ActiveWorkbook.ExportAsFixedFormat(Excel.XlFixedFormatType.xlTypePDF, pdfTemplatePath, Excel.XlFixedFormatQuality.xlQualityStandard, _, _, 1, pdfPrintAreaEnd); 

where the variables in question are:

 Excel := Microsoft.Office.Intertop.Excel _application := Excel.Application _ := System.Type.Missing pdfPrintAreaEnd := int 6 

The exception message is as follows:

 System.Runtime.InteropServices.COMException (0x800A03EC): Exception from HRESULT: 0x800A03EC 

What's going on here? And, more importantly: why does this happen only every time?

+6
source share
1 answer

Ok, so after some research on this, I came across what, in my opinion, is one of the most confuzzling about Excel Automation that I have encountered so far.

The error message corresponds to other uses of Excel that are both automated and not automated. A common denominator in all these cases (buckle!) Is that the network printer was installed as the default printer .

Correct - when using the default network printer, even when you print using a completely different printer or without a printer at all (as in the case of export to PDF, which does not match printing, for example, using Adobe PDF Printer, right?) to the fact that this error sometimes appears on some machines.

I changed the default printer to something internal, like Microsoft XPS Document Printer, tried again, and now I can export hundreds and thousands of PDF files without a single error message.

+9
source

Source: https://habr.com/ru/post/972775/


All Articles