How to publish into single PDF file a few hundred pages?

Adding pages to write into file like so:


slows Rhino to a crawl and crashes it after about a dozen of pages.

[ERROR] FATAL UNHANDLED EXCEPTION: System.ArgumentException: Parameter is not valid.
at System.Drawing.Graphics.GetHdc()
at System.Windows.Forms.Internal.WindowsGraphics.FromGraphics(Graphics g, ApplyGraphicsProperties properties)
at System.Windows.Forms.WindowsGraphicsWrapper…ctor(IDeviceContext idc, TextFormatFlags flags)
at System.Windows.Forms.TextRenderer.MeasureText(IDeviceContext dc, String text, Font font, Size proposedSize, TextFormatFlags flags)
at ICSharpCode.TextEditor.TextView.MeasureStringWidth(Graphics g, String word, Font font)
at ICSharpCode.TextEditor.TextView.GetLogicalColumnInternal(Graphics g, LineSegment line, Int32 start, Int32 end, Int32& drawingPos, Int32 targetVisualPosX)
at ICSharpCode.TextEditor.TextView.GetLogicalColumn(Int32 lineNumber, Int32 visualPosX, FoldMarker& inFoldMarker)
at ICSharpCode.TextEditor.TextArea.OnMouseMove(MouseEventArgs e)
at System.Windows.Forms.Control.WmMouseMove(Message& m)
at System.Windows.Forms.Control.WndProc(Message& m)
at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)


if more than a few letter size simple curveline work pages present, it crashes after 4-5 added pages.

        Rhino.RhinoDoc.ActiveDoc.UndoRecordingEnabled = False

None of this seems to help…

Hi Asterisk,

As a test or solution if acceptable you might try and decrease the pdf resolution.
I’ve had succes to allow for more pages per pdf by lowering DPI from 600 to 300.

Still not a favorable solution but at least a workaround and pointer to the probable cause.


Yeah that’s the first thing I tried - it didn’t matter and from my little understanding, shouldn’t matter, 'cause the output is Vector.

A tool like Split PDF might be convenient too

If you have details in shaded, rendered or any other mode involving some form of shading, the output is not pure vector.

Can you provide an example to repeat the issue for someone at McNeel to look at?

PD example.3dm (270.1 KB)

Nah, it’s pretty minimal. Dims, curves and texts. The individual pdfs are <100Kb.

PD MCM 01X.pdf (76.2 KB)

An example plus the script would help. (2.8 KB)

PD release example.3dm (2.7 MB)

import math
import Rhino
import time
import datetime
import scriptcontext as sc
import System.Drawing as sd
import rhinoscriptsyntax as rs

view = sc.doc.Views.ActiveView.ActiveViewport
ox = view.ConstructionPlane()

def main():
    wplane = Rhino.Geometry.Plane.WorldXY
    view.SetToPlanView(Rhino.Geometry.Point3d(0,0,0), wplane.XAxis, wplane.YAxis, True)
    tmp = sc.doc.Objects.GetObjectList(Rhino.DocObjects.ObjectType.Curve)
    for obj in tmp:
        if not obj.IsValid: obj.Select(True)
    seldobjs = [j for j in sc.doc.Objects.GetSelectedObjects(False, False)]
    if seldobjs:
        print "\nBad objects present. Fix selected and re-run.\n"
    fpath = sc.doc.Path
    fpath = fpath[0 : fpath.rfind("\\") + 1]
    alltbs = sc.doc.Objects.FindByUserString("Title", "Border", True)
    pubtbs = [j for j in alltbs if not j.IsHidden and not j.IsLocked]
    if not pubtbs:
        print "\nNo Part Drawings found.\n"
    bbox = None
    for crv in pubtbs:
        box = crv.Geometry.GetBoundingBox(True)
        if not bbox:
            bbox = box
    print "\n\nPD Publishing in progress. Please wait...\n"
    sc.doc.Views.RedrawEnabled = False
    pdlayer = sc.doc.Layers.FindName("PD")
    pdlayers = Rhino.DocObjects.Layer.GetChildren(pdlayer)
    allpdobjs = []
    for lay in pdlayers:
        allpdobjs += sc.doc.Objects.FindByLayer(lay.Name)
    dimlayer = sc.doc.Layers.FindName("DIMs")
    allpdobjs += sc.doc.Objects.FindByLayer(dimlayer.Name)
    release = "MCM 01X"
    pdf = Rhino.FileIO.FilePdf.Create()
    dpi = 300
    size = sd.Size(11 * dpi, 8.5 * dpi)
    settings = Rhino.Display.ViewCaptureSettings(sc.doc.Views.ActiveView, size, dpi)
    for pdtb in pubtbs:
        pdpt = rs.CurveAreaCentroid(pdtb)[0]
        pt1 = Rhino.Geometry.Point3d(pdpt.X - 131, pdpt.Y + 101, 0)
        pt2 = Rhino.Geometry.Point3d(pdpt.X + 131, pdpt.Y - 101, 0)
        crossline = Rhino.Geometry.Line(pt1, pt2)
        bbox = crossline.ToNurbsCurve().GetBoundingBox(True)
        settings.SetWindowRect(pt1, pt2)
        pdf.AddPage(settings) #add 1 or more pages based on ViewCaptureSettings
        print "added"
    pdf.Write(fpath + "\PD " + release + ".pdf") #write the pdf file to disk

if __name__ == "__main__": main()

sc.doc.Views.RedrawEnabled = True
print "\nPublishing done.\n\n"


I managed to make it print more than 50 pages by Hiding everything in the document and showing only what is being output into a single PDF page. Rhino still becomes unresponsive and you have to just wait it out. And after running the script 3-4 times, it starts crashing again. Have to reopen the file in a new instance of Rhino and it works again.

test file.3dm (19.3 MB)

test (4.7 KB)

I managed to cram 278 pages into one pdf. That’s not nearly enough and the issue is still there.
And the issue feels like some “display memory buffer” gets overfilled and even outside programs like PDF viewer becomes sluggish while the Rhino instance in which script ran once is running.

test (5.1 KB)
test (2.6 MB)

Hiding everything and only showing geometry for a single page to PDF when Adding Pages is critical for Rhino not to crash on the 40th page and go full 270+. It still gets progressively slower and crashes after 270.

Plz, halp. @stevebaer @brian

I have this thread bookmarked and will try to repeat what you are seeing when I get a chance.

1 Like

Not sure if this matters, but .Finalize method doesn’t exist in .FilePdf class. Only in documentation.

@stevebaer any chance of looking at this next week?

Here’s the final script we’re going to use, but it still makes Rhino crash after about 170 pages:
Publish (8.3 KB)
Publish Test 799 (crashes).zip (4.9 MB)

Hi @Asterisk,

The sample is very helpful - thanks. I’ve logged the crash issue.

– Dale

1 Like

Is there a chance this is out before the end of the year?image


Did you try last week’s 7.13 release candidate?

Yes. Wasn’t sure if I had last weeks update, so updated to yesterdays and no changes. Still the same crash at the same “spot”.

@Asterisk - this issue will be fixed in SR14. When a release candidate is available, please try it.

– Dale

1 Like