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.
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 |
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 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.