How to set paper size when when printing

6,024 views
Skip to first unread message

Brad

unread,
May 23, 2012, 2:16:14 PM5/23/12
to pdfne...@googlegroups.com
I am trying to print a 4 x 2 inch label.  I am using the below code:

        Dim doc As New PDFDoc("C:\Label.pdf")

        Dim mode As New PrinterMode
        mode.SetScaleType(PrinterMode.ScaleType.e_ScaleType_None)
        mode.SetAutoCenter(False)
        mode.SetAutoRotate(False)

        '2 inch height, 4 inch width
        mode.SetPaperSize(New Rect(0, 0, 2.0 * 72, 4.1 * 72))

        Dim pages As New PageSet(1, doc.GetPageCount)

        PDF.Print.StartPrintJob(doc, "", doc.GetFileName, "", pages, mode)


However, this results in three labels getting printed, 2 blank and 1 with the text I'm using.  The printer default label size is 4 x 6 inches, so I believe the printer is still using the default label size.  How do I force it to use the correct label size?

Support

unread,
May 23, 2012, 5:23:00 PM5/23/12
to pdfne...@googlegroups.com

You may want to try using one of predefined paper sizes with SetPaperSize(PrinterMode.PaperSize):

Widows print API sometimes does not select the proper paper when using Rect parameter.

Brad

unread,
May 23, 2012, 5:33:40 PM5/23/12
to pdfne...@googlegroups.com
Hi Ivan,

Thanks for the quick reply.  I'm trying to print on labels that are 4" wide by 2" tall.  None of the predefined paper sizes appear to be set for that... is there a list of what size each predefined paper is? (ie - I have no idea what size e_japanese_envelope_kaku_3_rotated is, and can't find it listed anywhere in the documentation). 

Support

unread,
May 23, 2012, 5:47:46 PM5/23/12
to pdfne...@googlegroups.com
 
These are standard Windows paper sizes.
 
They are listed here:
 
 
 
  • DMPAPER_LETTER = 1 (Letter 8 1/2 x 11 in)
  • DMPAPER_LETTERSMALL = 2 (Letter Small 8 1/2 x 11 in)
  • DMPAPER_TABLOID = 3 (Tabloid 11 x 17 in)
  • DMPAPER_LEDGER = 4 (Ledger 17 x 11 in)
  • DMPAPER_LEGAL = 5 (Legal 8 1/2 x 14 in)
  • DMPAPER_STATEMENT = 6 (Statement 5 1/2 x 8 1/2 in)
  • DMPAPER_EXECUTIVE = 7 (Executive 7 1/4 x 10 1/2 in)
  • DMPAPER_A3 = 8 (A3 297 x 420 mm)
  • DMPAPER_A4 = 9 (A4 210 x 297 mm)
  • DMPAPER_A4SMALL = 10 (A4 Small 210 x 297 mm)
  • DMPAPER_A5 = 11 (A5 148 x 210 mm)
  • DMPAPER_B4 = 12 (B4 (JIS) 250 x 354)
  • DMPAPER_B5 = 13 (B5 (JIS) 182 x 257 mm)
  • DMPAPER_FOLIO = 14 (Folio 8 1/2 x 13 in)
  • DMPAPER_QUARTO = 15 (Quarto 215 x 275 mm)
  • DMPAPER_10X14 = 16 (10x14 in)
  • DMPAPER_11X17 = 17 (11x17 in)
  • DMPAPER_NOTE = 18 (Note 8 1/2 x 11 in)
  • DMPAPER_ENV_9 = 19 (Envelope #9 3 7/8 x 8 7/8)
  • DMPAPER_ENV_10 = 20 (Envelope #10 4 1/8 x 9 1/2)
  • DMPAPER_ENV_11 = 21 (Envelope #11 4 1/2 x 10 3/8)
  • DMPAPER_ENV_12 = 22 (Envelope #12 4 \276 x 11)
  • DMPAPER_ENV_14 = 23 (Envelope #14 5 x 11 1/2)
  • DMPAPER_CSHEET = 24 (C size sheet)
  • DMPAPER_DSHEET = 25 (D size sheet)
  • DMPAPER_ESHEET = 26 (E size sheet)
  • DMPAPER_ENV_DL = 27 (Envelope DL 110 x 220mm)
  • DMPAPER_ENV_C5 = 28 (Envelope C5 162 x 229 mm)
  • DMPAPER_ENV_C3 = 29 (Envelope C3 324 x 458 mm)
  • DMPAPER_ENV_C4 = 30 (Envelope C4 229 x 324 mm)
  • DMPAPER_ENV_C6 = 31 (Envelope C6 114 x 162 mm)
  • DMPAPER_ENV_C65 = 32 (Envelope C65 114 x 229 mm)
  • DMPAPER_ENV_B4 = 33 (Envelope B4 250 x 353 mm)
  • DMPAPER_ENV_B5 = 34 (Envelope B5 176 x 250 mm)
  • DMPAPER_ENV_B6 = 35 (Envelope B6 176 x 125 mm)
  • DMPAPER_ENV_ITALY = 36 (Envelope 110 x 230 mm)
  • DMPAPER_ENV_MONARCH = 37 (Envelope Monarch 3.875 x 7.5 in)
  • DMPAPER_ENV_PERSONAL = 38 (6 3/4 Envelope 3 5/8 x 6 1/2 in)
  • DMPAPER_FANFOLD_US = 39 (US Std Fanfold 14 7/8 x 11 in)
  • DMPAPER_FANFOLD_STD_GERMAN = 40 (German Std Fanfold 8 1/2 x 12 in)
  • DMPAPER_FANFOLD_LGL_GERMAN = 41 (German Legal Fanfold 8 1/2 x 13 in)
  • DMPAPER_ISO_B4 = 42 (B4 (ISO) 250 x 353 mm)
  • DMPAPER_JAPANESE_POSTCARD = 43 (Japanese Postcard 100 x 148 mm)
  • DMPAPER_9X11 = 44 (9 x 11 in )
  • DMPAPER_10X11 = 45 (10 x 11 in )
  • DMPAPER_15X11 = 46 (15 x 11 in )
  • DMPAPER_ENV_INVITE = 47 (Envelope Invite 220 x 220 mm)
  • DMPAPER_RESERVED_48 = 48 (RESERVED--DO NOT USE)
  • DMPAPER_RESERVED_49 = 49 (RESERVED--DO NOT USE)
  • DMPAPER_LETTER_EXTRA = 50 (Letter Extra 9 \275 x 12 in)
  • DMPAPER_LEGAL_EXTRA = 51 (Legal Extra 9 \275 x 15 in)
  • DMPAPER_TABLOID_EXTRA = 52 (Tabloid Extra 11.69 x 18 in)
  • DMPAPER_A4_EXTRA = 53 (A4 Extra 9.27 x 12.69 in)
  • DMPAPER_LETTER_TRANSVERSE = 54 (Letter Transverse 8 \275 x 11 in)
  • DMPAPER_A4_TRANSVERSE = 55 (A4 Transverse 210 x 297 mm)
  • DMPAPER_LETTER_EXTRA_TRANSVE = RSE 56 (Letter Extra Transverse 9\275 x 12 in)
  • DMPAPER_A_PLUS = 57 (SuperA/SuperA/A4 227 x 356 mm)
  • DMPAPER_B_PLUS = 58 (SuperB/SuperB/A3 305 x 487 mm)
  • DMPAPER_LETTER_PLUS = 59 (Letter Plus 8.5 x 12.69 in)
  • DMPAPER_A4_PLUS = 60 (A4 Plus 210 x 330 mm)
  • DMPAPER_A5_TRANSVERSE = 61 (A5 Transverse 148 x 210 mm)
  • DMPAPER_B5_TRANSVERSE = 62 (B5 (JIS) Transverse 182 x 257 mm)
  • DMPAPER_A3_EXTRA = 63 (A3 Extra 322 x 445 mm)
  • DMPAPER_A5_EXTRA = 64 (A5 Extra 174 x 235 mm)
  • DMPAPER_B5_EXTRA = 65 (B5 (ISO) Extra 201 x 276 mm)
  • DMPAPER_A2 = 66 (A2 420 x 594 mm)
  • DMPAPER_A3_TRANSVERSE = 67 (A3 Transverse 297 x 420 mm)
  • DMPAPER_A3_EXTRA_TRANSVERSE = 68 (A3 Extra Transverse 322 x 445 mm)
  • DMPAPER_DBL_JAPANESE_POSTCAR = D 69 (Japanese Double Postcard 200 x 148 mm)
  • DMPAPER_A6 = 70 (A6 105 x 148 mm)
  • DMPAPER_JENV_KAKU2 = 71 (Japanese Envelope Kaku #2)
  • DMPAPER_JENV_KAKU3 = 72 (Japanese Envelope Kaku #3)
  • DMPAPER_JENV_CHOU3 = 73 (Japanese Envelope Chou #3)
  • DMPAPER_JENV_CHOU4 = 74 (Japanese Envelope Chou #4)
  • DMPAPER_LETTER_ROTATED = 75 (Letter Rotated 11 x 8 1/2 11 in)
  • DMPAPER_A3_ROTATED = 76 (A3 Rotated 420 x 297 mm)
  • DMPAPER_A4_ROTATED = 77 (A4 Rotated 297 x 210 mm)
  • DMPAPER_A5_ROTATED = 78 (A5 Rotated 210 x 148 mm)
  • DMPAPER_B4_JIS_ROTATED = 79 (B4 (JIS) Rotated 364 x 257 mm)
  • DMPAPER_B5_JIS_ROTATED = 80 (B5 (JIS) Rotated 257 x 182 mm)
  • DMPAPER_JAPANESE_POSTCARD_RO = TATED 81 (Japanese Postcard Rotated 148 x 100 mm)
  • DMPAPER_DBL_JAPANESE_POSTCAR = D_ROTATED 82 (Double Japanese Postcard Rotated 148 x 200 mm)
  • DMPAPER_A6_ROTATED = 83 (A6 Rotated 148 x 105 mm)
  • DMPAPER_JENV_KAKU2_ROTATED = 84 (Japanese Envelope Kaku #2 Rotated)
  • DMPAPER_JENV_KAKU3_ROTATED = 85 (Japanese Envelope Kaku #3 Rotated)
  • DMPAPER_JENV_CHOU3_ROTATED = 86 (Japanese Envelope Chou #3 Rotated)
  • DMPAPER_JENV_CHOU4_ROTATED = 87 (Japanese Envelope Chou #4 Rotated)
  • DMPAPER_B6_JIS = 88 (B6 (JIS) 128 x 182 mm)
  • DMPAPER_B6_JIS_ROTATED = 89 (B6 (JIS) Rotated 182 x 128 mm)
  • DMPAPER_12X11 = 90 (12 x 11 in)
  • DMPAPER_JENV_YOU4 = 91 (Japanese Envelope You #4)
  • DMPAPER_JENV_YOU4_ROTATED = 92 (Japanese Envelope You #4 Rotated)
  • DMPAPER_P16K = 93 (PRC 16K 146 x 215 mm)
  • DMPAPER_P32K = 94 (PRC 32K 97 x 151 mm )
  • DMPAPER_P32KBIG = 95 (PRC 32K(Big) 97 x 151 mm)
  • DMPAPER_PENV_1 = 96 (PRC Envelope #1 102 x 165 mm)
  • DMPAPER_PENV_2 = 97 (PRC Envelope #2 102 x 176 mm)
  • DMPAPER_PENV_3 = 98 (PRC Envelope #3 125 x 176 mm)
  • DMPAPER_PENV_4 = 99 (PRC Envelope #4 110 x 208 mm)
  • DMPAPER_PENV_5 = 100 (PRC Envelope #5 110 x 220 mm)
  • DMPAPER_PENV_6 = 101 (PRC Envelope #6 120 x 230 mm)
  • DMPAPER_PENV_7 = 102 (PRC Envelope #7 160 x 230 mm)
  • DMPAPER_PENV_8 = 103 (PRC Envelope #8 120 x 309 mm)
  • DMPAPER_PENV_9 = 104 (PRC Envelope #9 229 x 324 mm)
  • DMPAPER_PENV_10 = 105 (PRC Envelope #10 324 x 458 mm)
  • DMPAPER_P16K_ROTATED = 106 (PRC 16K Rotated)
  • DMPAPER_P32K_ROTATED = 107 (PRC 32K Rotated)
  • DMPAPER_P32KBIG_ROTATED = 108 (PRC 32K(Big) Rotated)
  • DMPAPER_PENV_1_ROTATED = 109 (PRC Envelope #1 Rotated 165 x 102 mm)
  • DMPAPER_PENV_2_ROTATED = 110 (PRC Envelope #2 Rotated 176 x 102 mm)
  • DMPAPER_PENV_3_ROTATED = 111 (PRC Envelope #3 Rotated 176 x 125 mm)
  • DMPAPER_PENV_4_ROTATED = 112 (PRC Envelope #4 Rotated 208 x 110 mm)
  • DMPAPER_PENV_5_ROTATED = 113 (PRC Envelope #5 Rotated 220 x 110 mm)
  • DMPAPER_PENV_6_ROTATED = 114 (PRC Envelope #6 Rotated 230 x 120 mm)
  • DMPAPER_PENV_7_ROTATED = 115 (PRC Envelope #7 Rotated 230 x 160 mm)
  • DMPAPER_PENV_8_ROTATED = 116 (PRC Envelope #8 Rotated 309 x 120 mm)
  • DMPAPER_PENV_9_ROTATED = 117 (PRC Envelope #9 Rotated 324 x 229 mm)
  • DMPAPER_PENV_10_ROTATED = 118 (PRC Envelope #10 Rotated 458 x 324 mm)
 
 
From another resource:
 
 

A4, 210 x 297 mm

SuperB/A3, 305 x 487 mm

Letter, 8 1/2 x 11"

Tabloid Extra, 12 x 18"

A4 Plus, 210 x 330 mm

A3 Extra, 322 x 445 mm

Legal, 8 1/2 x 14"

A3 Extra Transverse

Fax Paper, 215.1 x 285.1 mm

A3 Rotated, 420 x 297 mm

Broadsheet, 17 x 22"

A3 Transverse, 297 x 420 mm

Executive, 7 1/4 x 10 1/2"

A4 Extra, 235 x 322 mm

Folio, 8 1/2 x 13"

A4 Rotated, 297 x 210 mm

Junior Legal, 5 x 8"

A4 small, 210 x 297 mm

Ledger, 17 x 11"

A4 Transverse, 210 x 297 mm

Note, 8 1/2 x 11"

A5 Extra, 174 x 235 mm

Statement, 5 1/2 x 8 1/2"

A5 Rotated, 210 x 148 mm

Tabloid, 11 x 17"

A5 Transverse, 148 x 210 mm

US Standard Fanfold, 14 7/8 x 11"

A6 Rotated, 148 x 105 mm

German Legal Fanfold, 8 1/2 x 13"

B5 Extra, 201 x 276 mm

German Standard Fanfold, 8 1/2 x 12"

B0 (JIS), 1030 x 1456 mm

Quarto, 215 x 275 mm

B1 (JIS), 728 x 1030 mm

A0, 841 x 1189 mm

B2 (JIS), 515 x 728 mm

A1, 594 x 841 mm

B3 (JIS), 364 x 515 mm

A2, 420 x 594 mm

B4 (JIS), 257 x 364 mm

A3, 297 x 420 mm

B4 (JIS), Rotated

A5, 148 x 210 mm

B5 (JIS), 182 x 257 mm

A6, 105 x 148 mm

B5 (JIS), Rotated

A7, 74 x 105 mm

B5 (JIS), Transverse, 182 x 257 mm

A8, 52 x 74 mm

B6 (JIS), 128 x 182 mm

A9, 37 x 52 mm

B6 (JIS) Rotated

A10, 26 x 37 mm

Japan Envelope Chou #3 Rotated

B0, 1000 x 1414 mm

Japan Envelope Chou #3, 120 x 235 mm

B1, 707 x 1000 mm

Japan Envelope Chou #4 Rotated

B2, 500 x 707 mm

Japan Envelope Chou #4, 90 x 205 mm

B3, 353 x 500 mm

Japan Envelope Kaku #2 Rotated

B4, 250 x 353 mm

Japan Envelope Kaku #2, 240 x 332 mm

B5, 176 x 250 mm

Japan Envelope Kaku #3 Rotated

B6 , 125 x 176 mm

Japan Envelope Kaku #3, 216 x 277 mm

B7, 88 x 125 mm

Japan Envelope You #4 Rotated

B8, 62 x 88 mm

Japan Envelope You #4, 105 x 235 mm

B9 , 44 x 62 mm

Japan Postcard, 100 x 148 mm

B10, 31 x 44 mm

Japan Postcard Rotated

Envelope C0, 917 x 1297 mm

Japan Double Postcard, 200 x 148 mm

Envelope C1, 648 x 917 mm

Japan Double Postcard Rotate

Envelope C2, 458 x 648 mm

PRC 16K, 146 x 215 mm

Envelope C3, 324 x 458 mm

PRC 16K, Rotated

Envelope C4, 229 x 324 mm

PRC 32K(Big), 97 x 151 mm

Envelope C5, 162 x 229 mm

PRC 32K(Big), Rotated

Envelope C6, 114 x 162 mm

PRC 32K, 97 x 151 mm

Envelope C65, 114 x 229 mm

PRC 32K, Rotated

Envelope C7, 81 x 114 mm

PRC Envelope #1, 102 x 165 mm

Envelope DL, 110 x 220 mm

PRC Envelope #1, Rotated

Envelope B4, 250 x 353 mm

PRC Envelope #2 Rotated

Envelope B5, 176 x 250 mm

PRC Envelope #2, 102 x 176 mm

Envelope B6, 176 x 125 mm

PRC Envelope #3 Rotated

A (ANSI) Sheet, 8 1/2 x 11"

PRC Envelope #3, 125 x 176 mm

B (ANSI) Sheet, 11 x 17"

PRC Envelope #4 Rotated

C (ANSI) Sheet, 17 x 22"

PRC Envelope #4, 110 x 208 mm

D (ANSI) Sheet, 22 x 34"

PRC Envelope #5 Rotated

E (ANSI) Sheet, 34 x 44"

PRC Envelope #5, 110 x 220 mm

F (ANSI) Sheet, 28 x 40"

PRC Envelope #6 Rotated

G (ANSI) Sheet, 11 x 22 1/2"

PRC Envelope #6, 120 x 230 mm

H (ANSI) Sheet, 28 x 44"

PRC Envelope #7 Rotated

J (ANSI) Sheet, 34 x 55"

PRC Envelope #7, 160 x 230 mm

K (ANSI) Sheet, 40 x 62 11/16"

PRC Envelope #8 Rotated

ARCH A Sheet, 9 x 12"

PRC Envelope #8, 120 x 309 mm

ARCH B Sheet, 12 x 18"

PRC Envelope #9 Rotated

ARCH C Sheet, 18 x 24"

PRC Envelope #9, 229 x 324 mm

ARCH D Sheet, 24 x 36"

PRC Envelope #10, 324 x 458 mm

ARCH E Sheet, 36 x 48"

PRC Envelope #10, Rotated

Envelope #9, 3 7/8 x 8 7/8"

Avery 4150-4151, 1 1/8 x 3 1/2"

Envelope #10, 4 1/8 x 9 1/2"

Avery 4153, 2 1/8 x 4"

Envelope #11, 4 1/2 x 10 3/8"

Avery 9170, 1 x 2 5/8"

Envelope #12, 4 1/2 x 11"

Avery 9173, 2 1/8 x 3 1/3"

Envelope #14, 5 x 11 1/2"

Avery 9176, 11/16 x 3 7/16"

Envelope Monarch, 3 7/8 x 7 1/2"

Avery 9177, 1/2 x 1 3/4"

Envelope 6 3/4, 3 5/8 x 6 1/2"

Avery Dennison, 4.4 - 100 x 150 mm

Envelope Invite, 220 x 220 mm

Avery Dennison, 4.4 - 100 x 75 mm

Envelope, 110 x 230 mm

Badge Size, 2 5/16 x 3 1/2"

9 x 11"

Business Card CR-80, 85.6 x 53.9 mm

10 x 11"

Credit Card size, 2 1/8 x 3 3/8"

10 x 14"

Data Collection Size, 2 5/16 x 3 1/4"

11 x 17"

Government Size, 2 5/8 x 3 7/8"

12 x 11"

ID-1, 85.6 x 98 mm

15 x 11"

ID-2, 105 x 74 mm

Legal Extra, 9 1/2 x 15"

ID-3, 125 x 88 mm

Letter Extra Transverse, 9 1/2 x 12"

Index card, 3 x 5"

Letter Extra, 9 1/2 x 12"

Index card, 4 x 6"

Letter Plus, 8 1/2 x 12 11/16"

Index card, 5 x 8"

Letter Rotated, 11 x 8 1/2"

Japanese business card, 55 x 91 mm

Support

unread,
May 31, 2012, 6:57:55 PM5/31/12
to pdfne...@googlegroups.com
 

Thansk, I ended up using a solution along the lines of the 2nd example in the PDFPrint sample (http://www.pdftron.com/pdfnet/samplecode/PDFPrint.vb).   I had to tell the printer what size paper to use.  We then generated the labels so that there was 1 per page in the top-left corner, then cropped the pdf page to the correct size.  Sample code:

 

' Create objects needed

Dim printDoc As PrintDocument = New PrintDocument

Dim doc As PDFDoc

 

' Define label size

Dim width as integer = 4.1

Dim height as integer = 2

 

SetPaperSize(width, height)

 

' PDF’s are generated as 8.5 x 11 pages with 1 label per page in the top left corner

' Crop the pdf to label size

ResizePDF(width, height)

 

 

' Set paper size used by the printer in inches

Private Sub SetPaperSize(ByVal width As Double, ByVal height As Double)

    Dim size As New Drawing.Printing.PaperSize("Custom Size", width * 100, height * 100)

 

    printDoc.DefaultPageSettings.PaperSize = size

    printDoc.PrinterSettings.DefaultPageSettings.PaperSize = size

End Sub

 

 

'Change the size of the pages in the PDF document

Private Sub ResizePDF(ByVal width as Double, ByVal height As Double)

    'We only need to change the 1st page as all pages in a pdf have to be the same size

    Dim page As Page = myPDFDoc.GetPage(1)

 

    'Label dimensions in inches, converted to pdf units

    Dim pdfHeight As Double = height * 72

    Dim pdfWidth As Double = width * 72

 

    'Get the box used for printing.  Note that location (0, 0) on pdf documents is the bottom left corner.

    'We want to create the new media box in the top right corner instead which requires some math

    Dim box As Rect = page.GetMediaBox

 

    box.x1 = 0

    box.y1 = box.Height - pdfHeight

 

    box.x2 = box.x1 + pdfWidth

    box.y2 = box.y2 + pdfHeight

 

    'Apply the conversion.  All pages in memory are now the specified size

    box.Update()

End Sub

 

 

The PrintPage procedure was pretty much identical to what was in the Sample page.

 
 
 

On Wednesday, May 23, 2012 11:16:14 AM UTC-7, Brad wrote:

Support

unread,
May 31, 2012, 7:14:22 PM5/31/12
to pdfne...@googlegroups.com
 

On a relevant note, we posted an article showing how to print PDF documents via XPS print path (Apprach #4 in https://groups.google.com/d/msg/pdfnet-sdk/fOuGOvx06Tk/EckAX-ga2i8J). This is similar to what 'pdftron.PDF.Print.StartPrintJob' is doing under the hood. The main issue was that MS XPS Print is COM based, so you need to use PInvoke wrapper to print XPS spool file (generated using pdftron.PDF.Convert.ToXps()). With this approach you have the advantage of low-level control (via Windows Print API) while taking advantage of efficient and high-quality PDF printing.

 
Reply all
Reply to author
Forward
0 new messages