Efficient way to convert all text to outlines in a multi-page doc?



  • I'm going to be sending a PDF specimen to a printer, but I'm somewhat concerned that the variable fonts I've used might cause problems on their end.

    Is there a way to convert an entire document (like, 200 pages of text, mostly not that complex, but complex as a whole) to outlines? I see that BezierPath() might be the answer, but I can't imagine how I'd wrap an entire document in it, if it wasn't something planned from the outset.

    My backup is to just export everything to JPEG and bring those into a PDF. Maybe this is just the better option, anyway?

    Curious whether there's some option I'm missing. 🙂 Thanks!



  • You're right to use the BezierPath(). Instead of using a normal textBox use the BezierPath's textBox like so:

    textPath = BezierPath()
    overflow = textPath.textBox(txt, (x, y, w, h))
    fill(0.5)
    drawPath(textPath)
    


  • Ahhh this is very helpful. Thank you!



  • A few notes as I figure things out.

    I found that things had to be pretty particular for the Bezier object. I got this error a lot:

    Traceback (most recent call last):
      File "/Users/stephennixon/type-repos/recursive/src/proofs/drawbot-diagrams-etc/flipbook/recursive-flipbook-wave_viz-multistage-visualization_2-outlined_text-081419.drawbot.py", line 481, in <module>
        showAxisVals("i", italVal, i, infoHeight)
      File "/Users/stephennixon/type-repos/recursive/src/proofs/drawbot-diagrams-etc/flipbook/recursive-flipbook-wave_viz-multistage-visualization_2-outlined_text-081419.drawbot.py", line 475, in showAxisVals
        textPath.textBox(valueString,((x,y,w,h)), align="right")
      File "/usr/local/lib/python3.7/site-packages/drawBot-3.120-py3.7.egg/drawBot/context/baseContext.py", line 340, in textBox
        self.optimizePath()
      File "/usr/local/lib/python3.7/site-packages/drawBot-3.120-py3.7.egg/drawBot/context/baseContext.py", line 423, in optimizePath
        if self._path.elementAtIndex_(count - 1) == AppKit.NSMoveToBezierPathElement:
    IndexError: NSRangeException - elementAtIndex:associatedPoints:: index (-1) beyond bounds (0)
    

    And found that I needed to work in a specific order:

    • to use fontVariations, I had to setup a formatted string
    • to make the path with text show up, I had to use fill just before the drawPath function – it didn't work in the formatted string
    txt = FormattedString()
    txt.font(sans)                                                     # MUST be here
    txt.fontSize(textSize)                                             # MUST be here
    txt.fontVariations(wght=500, XPRN=xprnVals[0], slnt=0, ital=0)     # styling
    txt.align("right")                                                 # styling
    txt.append("this is my styled string")
    
    valueTextPath = BezierPath()
    fill(foreground)                                                   # MUST be here between BezierPath() setup and drawPath(), *not* in formatted string,
    valueTextPath.textBox(txt,((x,y,w,h)))
    drawPath(valueTextPath)
    


  • I did end up going through my document and putting about 10 different types of text into bezier paths.

    I know this is the kind of feature that might be a LOT more complex to implement than I realize, but I'd love it if in the future, the saveImage function just had an optional "outline text" feature, for needs like this. 🙂



  • Small update here: even though it took a bit of figuring out to convert text to outlined text, I'm very glad I took that route instead of outputting hi-res bitmaps for the printer.

    If the outlines didn't work, the printer said a good backup would be 2400dpi bitmaps (this is an all black-and-white book, and bitmaps would be smaller than JPEGs/PNGs). Even though I'm only making a 3.5-inch (8.89 cm) book, these images were 282.2MB apiece. This meant that generating them was somewhat slow, and also that uploading the 208 images to Dropbox (a total of almost 60 GB) would probably take my internet connection about 20 minutes at 100 Mbps.

    I'll share the DrawBot script soon, in case anyone needs it. (If I forget and this is something you do need, please email me: stephen at arrowtype dot com).



  • Oh, it's probably also worth mentioning the reason I did have to outline text, for anyone who might be Googling this subject.

    The printer reported to me that they couldn't place pages from my PDF into InDesign to prep for printing, and that "ripping" the file in Adobe Acrobat also had issues. I'm not quite sure whether this was caused by my variable font (likely) or another logo-specific font I used (also possible).

    The warning he reported to me, verbatim, was:

    The document could not be saved.
    
    Bad font object or font descriptor object.
    

  • admin

    mmm, generate an instance with fontTools, use that font with a path and generate the pdf?

    wondering if the Bad font object... error is also reported with old-style-static-fonts?