Hi,
here’s a tweaked version, which allows selecting between combined PDF or individual files.
In the case of individual files, the user can select which layouts to print using a MultiListBox.
import Rhino
import scriptcontext as sc
import System.Drawing
import rhinoscriptsyntax as rs
def createSinglePDF(view, folder):
pdf = Rhino.FileIO.FilePdf.Create()
dpi = 300
inch = 25.4
width = (view.PageWidth)/inch
height = (view.PageHeight)/inch
size = System.Drawing.Size(width*dpi,height*dpi)
settings = Rhino.Display.ViewCaptureSettings(view, size, dpi)
settings.RasterMode = False
pdf.AddPage(settings)
filename = folder+'/'+view.PageName+'.pdf'
pdf.Write(filename)
def createCombinedPDF(views, filename):
pdf = Rhino.FileIO.FilePdf.Create()
dpi = 300
inch = 25.4
i = 1
for view in views:
print "Printing page " + str(i) + " of " + str(len(views))
i = i+1
width = (view.PageWidth)/inch
height = (view.PageHeight)/inch
size = System.Drawing.Size(width*dpi,height*dpi)
settings = Rhino.Display.ViewCaptureSettings(view, size, dpi)
settings.RasterMode = False
pdf.AddPage(settings)
pdf.Write(filename)
layouts = []
layoutNames = []
for i in sc.doc.Views:
Rhino.Display.RhinoPageView
if type(i) is Rhino.Display.RhinoPageView:
layouts.append(i)
layoutNames.append(i.PageName)
combine = rs.MessageBox("Combine pages to a single PDF?", 3, "Combine PDF?")
if combine == 6: #YES
filename = rs.SaveFileName ("Save PDF", "PDF files (*.pdf)|*.pdf||")
if filename:
createCombinedPDF(layouts, filename)
print "Printing finished."
elif combine == 7: #NO
if len(layoutNames)>0:
layoutNames = rs.MultiListBox(layoutNames, "Pick layouts to print", "Layouts")
folder = rs.BrowseForFolder("G:\\" )
if folder:
for i in layouts:
if (i.PageName in layoutNames):
print "Printing: " + i.PageName + ".pdf"
createSinglePDF(i,folder)
elif combine == 2: #CANCEL
exit
Print to PDF.py (2.0 KB)
This seems insanely fast to print a bunch of PDF’s with this. 250-page PDF in about 10
seconds. Through _Print
that would take me hours.