Custom paper sizes via DEVMODE

The Amyuni PDF Converter is our Printer Driver that enables you to convert any documents to PDF format. If you have any questions about installing and using the Amyuni PDF Converter please post them here.
Post Reply
rec
Posts: 19
Joined: Tue Feb 21 2006

Custom paper sizes via DEVMODE

Post by rec »

I am using the PDF Converter v2.50f and am having a problem creating a PDF that uses a custom paper size. Note that I am using "normal" Windows printing code - i.e. using the DEVMODE structure to specify the printer settings and then using StartDoc/StartPage/EndPage/EndDoc to generate the file.

Some of the documents I use require a custom paper size, and according to the MSDN, you can achieve this by specifying zero as the dmPaperSize member, and use the dmPaperLength and dmPaperWidth members to specify the custom size in tenths of a millimetre. However, when I do with with PDF Converter, it doesn't work and I end up with a PDF that is 0.04 inches wide and 0.04 inches tall.

Any ideas how I can overcome this problem?
rec
Posts: 19
Joined: Tue Feb 21 2006

Post by rec »

OK, I figured it out. You need to ensure the DM_PAPERLENGTH and DM_PAPERWIDTH flags are set in the DEVMODE dmFields member, e.g.:

pDevMode->dmPaperLength = CUSTOM_HEIGHT;
pDevMode->dmPaperWidth = CUSTOM_WIDTH;
pDevMode->dmPaperSize = 0;
pDevMode->dmFields |= DM_PAPERLENGTH|DM_PAPERWIDTH;

I have used custom paper sizes with physical printers before, without having to set these flags, but this doesn't seem to to any harm (the MSDN seems to hint that dmFields indicates what flags the driver supports, and I haven't seen code that sets this explicitly before).
sprezzatura
Posts: 46
Joined: Fri Nov 18 2005
Location: Nova Scotia

Custom paper size

Post by sprezzatura »

Wouldn't you want to specify

pDevMode->dmPaperSize = DMPAPER_USER ?
rec
Posts: 19
Joined: Tue Feb 21 2006

Re: Custom paper size

Post by rec »

sprezzatura wrote:Wouldn't you want to specify

pDevMode->dmPaperSize = DMPAPER_USER ?
According to the MSDN that ships with VS2005:

"dmPaperSize
For printer devices only, selects the size of the paper to print on. This member can be set to zero if the length and width of the paper are both set by the dmPaperLength and dmPaperWidth members. Otherwise, the dmPaperSize member can be set to one of the following predefined values. "

Though I have also seen other documents on the web that mention DMPAPER_USER.
Post Reply