Use multiple paper types in one pdf?


I've been looking for a new way to create and print pdf files. Looking at your SDK, I've been impressed with the features and functionality, especially the python support. However, I do have few questions.

On one job I do, I need the ability to dynamically decide which type of paper to use on each individual page. That is, page one is letterhead, page two is plain and so on. Currently, the process produces a pdf, then converts it to postscript.

This postscript file is read, and I add either of these postscript commands to each page. << /MediaColor (white) /MediaType (plain)>> setpagedevice << /MediaColor (white) /MediaType (letterhead)>> setpagedevice

Can I duplicate this functionality with your SDK? Preferably, I would like to skip the postscript step entirely, but if not, does your SDK support converting to postscript?


Spencer Rathbun
L & D Mail Masters, Inc.
110 Security Parkway
New Albany, IN 47150
Phone: 812.981.7161
Fax: 812.981.7169

Spencer Rathbun
L & D Mail Masters, Inc.
110 Security Parkway
New Albany, IN 47150
Phone: 812.981.7161
Fax: 812.981.7169

You can use PDFNet to create, print, and edit PDFs, so you can skip the PostScript step entirely :slight_smile:

For options to create new PDF files from scratch please see the following entry:

There are also multiple ways to print PDF using PDFNet. This is shown in PDFPrint sample:

Also, see the following entries:

You can adjust PDF page dimensions using page.SetCropBox() and page.SetMediaBox() as shown in Rect sample:

Alright, I think I need to clarify something. The examples you’ve cited all seem to deal with changing the physical size of the pdf page. I’m not interested in changing it from using standard letter size paper. The printer we have reads the setpagedevice dictionary and uses that to look up what paper type to pull.

Then, it checks which drawer is set to the appropriate type of paper, and pulls from that drawer. I append the MediaColor and MediaType key/value pairs to the setpagedevice dictionary in postscript. Can I do the same thing with PDFNet? That is, change the paper name to letterhead, but leave the physical size and shape alone?

I’ve added my sample code based off of the Rect python sample code. Is there something I’m missing here?
Spencer Rathbun

import site
import sys
if sys.version_info.major < 3:
 from PDFNetPython2 import *
 from PDFNetPython3 import *

class iterPages(object):
 def __init__(self,source):
  self.source = source
 def next(self):
  if self.source.HasNext() == False:
   raise StopIteration
  item = self.source.Current()
  return item
 def __iter__(self):
  return self

def main():
 # Relative path to the folder containing the test files.
 input_path = "../../TestFiles/"
 output_path = "../../TestFiles/Output/"
 # Test  - Adjust the position of content within the page.
 print("Opening the input pdf...")
 input_doc = PDFDoc(input_path + "64828_18866-20457.pdf")
 pg_itr1 = iterPages(input_doc.GetPageIterator())
 for page in pg_itr1:
   rd = page.GetResourceDict()
  except Exception, e:
   print e
 input_doc.Save(output_path + "pageSwitched.pdf", 0)
 print("Done. Result saved in pageSwitched.pdf...")   

if __name__ == '__main__':

PDF format does not support this feaure (similar to MediaType).

You can achieve similar results by instructing the printer to use a specific page size. For example you can define a specific PaperSize in ‘pdftron.PDF.Print.PrinterMode’ when calling pdftron.PDF.Print.StartPrintJob().

If you need to print PDF pages in the same document on different trays (physical paper) you could split the PDF into multiple temp docs (without saving them to disk) and print each doc with a separate call to StartPrintJob().