Skip to content Skip to sidebar Skip to footer

How To Chose Paper Format When Printing A Pdf File With Python?

I am trying to print out a PDF file, but I do not know how to specify the Page Format. I want to print all of my PDFs in A5 Format. Can someone please help me? # this code works an

Solution 1:

If your restriction is that you want every document printing in A5 regardless of its original size, I'm not seeing a way to do that directly within the sample code that you have shown here, as you're currently passing in only the printer name and filename.

You need to obtain the printer's Device Context in order to specify the page size for the job, which would be A5, and thus if the printer was not loaded with A5 (or did not have it in one of its defined trays; I have to be vague here as different printers would address this different ways), it will pause and show a request for A5 to be loaded.

I'm also guessing at other details here, as I'm not sure if you want to expand smaller documents to A5 size, rotate them for best fit, keep them at 100% but center them on the page, etc. The key is that your process needs to obtain the Device Context of your selected printer, such that you'll know its capabilities, and how to ask for the output to be A5 coming out of that particular printer for your submitted job.

If it's a single-size printer that can only be loaded with one size at a time (A5 or some other single size), then you can either preload it with A5 paper and throw jobs at it without further specification, or be more careful and specify A5 for the print job, on the theory that the printer will stop until A5 is loaded, and not default to printing on, say, A4, either condensed to fit or bleeding off the edge.

If you can control both the job output and the printer in use, then you can configure both with a minimum of setup to generate the output you want. If you have no control over what the user will be selecting for an output device, then you will need to obtain the Device Context for that device in order to dictate the attributes of your print job (including the A5 paper size), and let the printer figure out how it's going to do as instructed.

Post a Comment for "How To Chose Paper Format When Printing A Pdf File With Python?"