.netacrobatpdfiumprint-spooler-api

How to reduce print spool file size


I have a pdf files of size 13.1MB. When print with Acrobat Reader DC, the size of the spool file is 105MB. However, when I try to programatically print with PdfiumViewer, the spool file size become over 500MB and eventually crash the program due to insufficient printer memory.

The code is as follow

var pdfStream = new FileStream("file.pdf", FileMode.Open);
var pdfDocument = PdfDocument.Load(pdfStream);
var printDocument = pdfDocument.CreatePrintDocument();

printDocument.Print();

I'm aware that the pdf file need to be converted to some data format understood by the printer, and the size of the data vary from application to application. My question is, how does Acrobat reduce the spool file size? Does it preprocess the pdf file (compress?) before converting the file to data format understood by the printer?

I'm trying to get some clues and hopefully can reduce spool file size just like Acrobat did.


Solution

  • There are no easy answers to your questions, so I'll give you the hard ones.

    You could try printing simpler documents (e.g. single PDF pages) from both programs to a paused printer with a PostScript driver and then diff the spool files stored here:

    C:\Windows\System32\spool\PRINTERS
    

    From past experience I suspect Acrobat does some PDF optimization to make it simpler to render. This knowledge won't help solve your problem though, unless you plan to improve Pdfium or PdfiumViewer.

    I'd say your options are:

    1. Profile the print operation and find out what is going wrong. Is it a leak? That might be something you could fix. If it would help, can you print one page at a time? Or is the PDF document you're trying to print composed of large high-resolution pages that aren't handled properly, like this issue? (I've linked to the archived original repo since you don't say which one you're using.)

    2. Look for other PDF printing options such as those mentioned in this somewhat old question. There are various commercial and open source solutions that you could use. If you can't fix PdfiumViewer yourself then you'll need to use a project that's still maintained so you can report any bugs you find.