New Text Document.txt (559 Bytes)
Portrait_Color.pdf (193.3 KB)
I am trying to create a PDF with Python. I have attached the script and the resulting PDF. I am not able to get it to output in color or at 8.5" × 11" size. What am I doing wrong?
New Text Document.txt (559 Bytes)
Portrait_Color.pdf (193.3 KB)
I am trying to create a PDF with Python. I have attached the script and the resulting PDF. I am not able to get it to output in color or at 8.5" × 11" size. What am I doing wrong?
FYI, Don’t want to use layout.
The pdf size seems correct, and running this script on a local file does give me color output. Can you share your model?
Get this.pdf (200.1 KB)
test.3dm (567.3 KB)
Want this.pdf (65.2 KB)
Made a new file and attached. There just test files.
Okay, I think what is happening is your Rhino viewport is wider than it is tall (landscape orientation), so when you zoom extents, there is extra space to the left and right of your geometry. Then, when you do the view capture, it shrinks that landscape image to fit in the portrait orientation page.
I modified your script to change the view size to match your desired page size before doing the zoom/print and then restore it afterward.
import Rhino
import System.Drawing
import rhinoscriptsyntax as rs
pdf_file = r"C:\Temp\Portrait_Color.pdf"
# Letter size at 300 dpi
width = 2550
height = 3300
view = Rhino.RhinoDoc.ActiveDoc.Views.ActiveView
# store original view size before modifying
old_size = view.Size
view.Size = System.Drawing.Size(width, height)
# Zoom everything first
rs.Command("_Zoom _Extents")
settings = Rhino.Display.ViewCaptureSettings(
view,
System.Drawing.Size(width, height),
300
)
# Keep display colors
settings.RasterMode = True
settings.OutputColor = Rhino.Display.ViewCaptureSettings.ColorMode.DisplayColor
pdf = Rhino.FileIO.FilePdf.Create()
pdf.AddPage(settings)
pdf.Write(pdf_file)
print("Saved:", pdf_file)
# restore original view size
view.Size = old_size
Actually, you can just use the settings.ViewArea property to avoid needing to manage the viewport size or even zoom extents.
import Rhino
import System.Drawing
import rhinoscriptsyntax as rs
pdf_file = r"C:\Temp\Portrait_Color.pdf"
# Letter size at 300 dpi
width = 2550
height = 3300
view = Rhino.RhinoDoc.ActiveDoc.Views.ActiveView
settings = Rhino.Display.ViewCaptureSettings(
view,
System.Drawing.Size(width, height),
300
)
settings.RasterMode = True
settings.OutputColor = Rhino.Display.ViewCaptureSettings.ColorMode.DisplayColor
settings.ViewArea = Rhino.Display.ViewCaptureSettings.ViewAreaMapping.Extents
pdf = Rhino.FileIO.FilePdf.Create()
pdf.AddPage(settings)
pdf.Write(pdf_file)
print("Saved:", pdf_file)
Thanks. That second one worked great. I appreciate the help.