PDF import corrupts some characters inside otherwise correct text

When importing some PDF files, parts of the text are corrupted. It mostly affects numbers and punctuation, while the rest of the same text object can remain correct.

It doesn’t look like a straightforward missing-font issue: a single text object can contain both correct and corrupted characters.

For example, Rhino imported this text as:

ARCHITECTS U P XC X IS PROHIBITED X

The intended text is:

ARCHITECTS, P.C. IS PROHIBITED.

In the same document:

  • ì í î ï ð ñ ò ó ô õ represent 0 1 2 3 4 5 6 7 8 9.
  • r sometimes represents a hyphen.
  • U sometimes represents a comma.
  • X sometimes represents a period.

These mappings are ambiguous. For example, the X in EXPRESS is a real X, while the standalone X in RIGHTS RESERVED X should be a period. The same applies to the U in USE, which must remain a U.

Rhino also inserts actual ASCII spaces between some of the corrupted characters. For example:

  • ì î r î ì r î ì î ò should be 02-20-2026.
  • A î X î ì should be A2.20.
  • M ð rRF ì î ì should be M4-RF020.

I have a PDF-import command in my plug-in, so I added a postprocessing pass immediately after import. It scans the imported TextEntity objects, applies the unambiguous number mapping, and uses context to make an educated guess for punctuation and the inserted spaces.

This workaround has handled my recent conversions successfully, but it is still only a heuristic. It cannot resolve every ambiguous case without access to the PDF’s original font encoding.

Standalone Rhino 9 Python workaround

Run this in Rhino’s Script Editor immediately after importing the PDF. It scans all text objects in the active document.

import re

import Rhino


DIGIT_MARKERS = "ìíîïðñòóôõ"
DIGIT_MAP = dict(zip(DIGIT_MARKERS, "0123456789"))
MARKER_SET = frozenset(DIGIT_MARKERS)

PUNCTUATION_MAP = {
    "r": "-",
    "X": ".",
    "U": ",",
}


def repair_pdf_text(text):
    if not text:
        return text

    marker_class = re.escape(DIGIT_MARKERS)

    # Rhino sometimes inserts one extra space before each corrupted digit.
    # Removing exactly one preserves a real space when two are present.
    repaired_text = re.sub(
        rf"[ \t](?=[{marker_class}])",
        "",
        text,
    )

    # Avoid guessing punctuation in strings containing unknown control
    # characters. The distinctive digit mapping can still be applied.
    has_unknown_control_character = any(
        (ord(character) < 32 and character not in "\r\n\t")
        or 0x7F <= ord(character) <= 0x9F
        for character in repaired_text
    )

    if not has_unknown_control_character:
        # P XC X -> P.C.
        repaired_text = re.sub(
            r"(?<!\S)([A-Z])[ \t]+X([A-Z])[ \t]+X(?=[ \t]|$)",
            r"\1.\2.",
            repaired_text,
        )

        # Standalone U and X commonly represent commas and periods.
        repaired_text = re.sub(
            r"[ \t]+U(?=[ \t]|$)",
            ",",
            repaired_text,
        )
        repaired_text = re.sub(
            r"[ \t]+X(?=[ \t]|$)",
            ".",
            repaired_text,
        )

        # Punctuation next to corrupted numbers.
        repaired_text = re.sub(
            rf"[ \t]+X(?=[{marker_class}])",
            ".",
            repaired_text,
        )
        repaired_text = re.sub(
            rf"[ \t]+r(?=[{marker_class}])",
            "-",
            repaired_text,
        )
        repaired_text = re.sub(
            rf"(?<=[{marker_class}])[ \t]+r(?=[A-Z{marker_class}])",
            "-",
            repaired_text,
        )

        # FLOOR PLAN r DIMENSION -> FLOOR PLAN - DIMENSION
        repaired_text = re.sub(
            r"(?<=[ \t])r(?=[ \t])",
            "-",
            repaired_text,
        )

    # Replace corrupted digits and punctuation directly adjacent to them.
    repaired_characters = []

    for index, character in enumerate(repaired_text):
        repaired_digit = DIGIT_MAP.get(character)
        if repaired_digit is not None:
            repaired_characters.append(repaired_digit)
            continue

        punctuation = PUNCTUATION_MAP.get(character)
        previous_is_marker = (
            index > 0
            and repaired_text[index - 1] in MARKER_SET
        )
        next_is_marker = (
            index + 1 < len(repaired_text)
            and repaired_text[index + 1] in MARKER_SET
        )

        if punctuation is not None and (
            previous_is_marker or next_is_marker
        ):
            repaired_characters.append(punctuation)
        else:
            repaired_characters.append(character)

    return "".join(repaired_characters)


def main():
    doc = Rhino.RhinoDoc.ActiveDoc
    changed_count = 0
    undo_record = doc.BeginUndoRecord(
        "Repair corrupted PDF text"
    )

    try:
        annotation_objects = doc.Objects.GetObjectList(
            Rhino.DocObjects.ObjectType.Annotation
        )

        for rhino_object in annotation_objects:
            geometry = rhino_object.Geometry
            if not isinstance(
                geometry,
                Rhino.Geometry.TextEntity,
            ):
                continue

            original_text = str(geometry.PlainText)
            repaired_text = repair_pdf_text(original_text)

            if repaired_text == original_text:
                continue

            replacement = geometry.Duplicate()
            replacement.PlainText = repaired_text

            # Assigning PlainText can reset the font to the annotation
            # style font, so restore the imported font afterward.
            replacement.Font = geometry.Font

            if doc.Objects.Replace(
                rhino_object.Id,
                replacement,
            ):
                changed_count += 1

    finally:
        doc.EndUndoRecord(undo_record)

    if changed_count:
        doc.Views.Redraw()

    Rhino.RhinoApp.WriteLine(
        f"Repaired {changed_count} PDF text "
        f"object{'' if changed_count == 1 else 's'}."
    )


main()

It looks as though Rhino may be importing some PDF font character codes directly instead of resolving them through the font’s encoding or Unicode mapping, but that is only my guess.

Is there a way for Rhino’s PDF importer to recover the intended characters from the embedded font information instead of relying on this kind of heuristic?


This snapshot shows the PDF in a viewer on the left and the imported drawing in Rhino on the right:

Hi Stefano -
There is a lot of information in your report but I’m afraid there is nothing there that can be used for troubleshooting or fixing from our side.

You have put this thread in the “Serengeti” category, indicating that this is feedback on something that is new in Rhino 9. Can you confirm that you are not having this issue in Rhino 8?

As always, please post the output from the Rhino SystemInfo command and a file that we can use to test - in this case a PDF file.

Apart from that, we currently have five open issues related to how characters in PDF files are imported, one of which is public: RH-80686 File IO: Import PDF text - Failure example

The others being:
RH-53168 - Imported Text in AI or PDF
RH-77591 - PDF shows chinese charactrers
RH-89156 - Import PDF changes text to chinese characters
RH-90387 - File IO: Chinese characters can’t be displayed

We haven’t had anyone working on PDF import for a while and won’t in the short-term future. For now, using your Python workaround is the way to go.
-wim

Perhaps also send your post processing script to attach to an appropriate open issue?

Hi Wim,

I posted this in the Serengeti category because that’s the version I’m using. I’m a new Rhino user and started directly with Rhino 9 WIP, I’ve never used Rhino 8. I’ve just tested the same PDF in Rhino 8, and the text corruption occurs there as well.

I had already found a few similar reports (one, two, and three) but I couldn’t find much detail about the underlying cause or the specific character mappings.

I don’t know whether my case has exactly the same cause as those reports, but I found a repeatable pattern in the corrupted text. I thought it was worth reporting in case it provides some additional information to work with.

I’ve uploaded the PDF through rhino3d.com/upload and included a link to this thread for reference.

Here is my SystemInfo output:

Rhino 9 SR0 2026-8-25 (Rhino 9 BETA, 9.0.26237.15343, Git hash:master @ 96051fb40f8d55297d947c054b9d2f7c03d4bdeb)
License type: Commercial, build 2026-08-25
License details: Cloud Zoo
Expires on: 2026-10-09

Windows 10 (10.0.19045 SR0.0) or greater (Physical RAM: 32GB)
.NET 10.0.11

Computer platform: LAPTOP  - Plugged in [80% battery remaining]

Non-hybrid graphics configuration using DirectX
  Primary display: NVIDIA GeForce RTX 3080 Laptop GPU (NVidia) Memory: 8GB, Driver date: 5-19-2026 (M-D-Y). DirectX(11)
    > Integrated accelerated graphics device with 1 adapter port(s)
        - Windows Main Display is laptop's integrated screen or built-in port

Secondary graphics devices.
  Intel(R) UHD Graphics (Intel) Memory: 1GB, Driver date: 12-23-2021 (M-D-Y).
    > Integrated graphics device with 4 adapter port(s)
        - Secondary monitor is laptop's integrated screen or built-in port
        - Secondary monitor attached to adapter port #1
  Intel(R) UHD Graphics (Intel) Memory: 1GB, Driver date: 12-23-2021 (M-D-Y).
    > Integrated graphics device with 4 adapter port(s)
        - Secondary monitor is laptop's integrated screen or built-in port
        - Secondary monitor attached to adapter port #1

DirectX Settings
  Safe mode: Off

OpenBLAS: OpenBLAS 0.3.30 DYNAMIC_ARCH NO_AFFINITY SkylakeX MAX_THREADS=64.

Rhino plugins that do not ship with Rhino
  C:\Users\StefanoMenci\AppData\Roaming\McNeel\Rhinoceros\packages\9.0\BlockEditNew\2.1.7\blockeditnew.rhp	"BlockEditNew"	2.0.0.0
  C:\Users\StefanoMenci\AppData\Roaming\McNeel\Rhinoceros\packages\9.0\IntelliClad\0.0.11-beta\IntelliClad.TestInput.rhp	"IntelliClad.TestInput"	1.0.0.0
  C:\Users\StefanoMenci\AppData\Roaming\McNeel\Rhinoceros\packages\9.0\Rhino-MCP-Platform\0.2.1-wip\net8.0\RhinoMcpPlatform.rhp	"RhinoMcpPlatform"	0.2.1.0
  C:\Users\StefanoMenci\AppData\Roaming\McNeel\Rhinoceros\packages\9.0\CommandHistoryMD\0.1.0\CommandHistoryMD.rhp	"CommandHistoryMD"	0.1.0.0

Rhino plugins that ship with Rhino
  C:\Program Files\Rhino 9 WIP\Plug-ins\Commands.rhp	"Commands"	9.0.26237.15343
  C:\Program Files\Rhino 9 WIP\Plug-ins\rdk.rhp	"Renderer Development Kit"	
  C:\Program Files\Rhino 9 WIP\Plug-ins\3dxRhino.9.rhp	"3DxRhino.9"	
  C:\Program Files\Rhino 9 WIP\Plug-ins\UpdatesAndStatistics\UpdatesAndStatistics.rhp	"UpdatesAndStatistics"	9.0.26237.15343
  C:\Program Files\Rhino 9 WIP\Plug-ins\RhinoRenderCycles.rhp	"Rhino Render"	9.0.26237.15343
  C:\Program Files\Rhino 9 WIP\Plug-ins\rdk_etoui.rhp	"RDK_EtoUI"	9.0.26237.15343
  C:\Program Files\Rhino 9 WIP\Plug-ins\NamedSnapshots.rhp	"Snapshots"	
  C:\Program Files\Rhino 9 WIP\Plug-ins\MeshCommands.rhp	"MeshCommands"	9.0.26237.15343
  C:\Program Files\Rhino 9 WIP\Plug-ins\Import_PDF.rhp	"PDFReader"	
  C:\Program Files\Rhino 9 WIP\Plug-ins\RhinoCycles.rhp	"RhinoCycles"	9.0.26237.15343
  C:\Program Files\Rhino 9 WIP\Plug-ins\Displacement.rhp	"Displacement"	
  C:\Program Files\Rhino 9 WIP\Plug-ins\SectionTools.rhp	"SectionTools"	

The script I use to fix the texts was in my original post, in a collapsed paragraph.

I’m using a similar version inside the command defined in the plugin, but that script is essentially the same thing.

If you are having the same problem when importing PDF files, it would be interesting to see if that script helps you too.

Hi Stefano,

It is pretty obvious that the viewer and Rhino in your illustration are rendering different fonts: that may be sufficient to cause the character deviations.

Could you post a troublesome PDF here? - we mere mortals don’t have access to the upload location you used, but I would be interested in exploring the issue from a typographer’s perspective. If your files are confidential, you could copy something non-contentious that briefly illustrates the problem into a new PDF.

Regards
Jeremy

Hi @Stefano_Menci,
Thanks for sending the PDF to us.
I can duplicate the issue here and will get it logged.

Sincerely,
Mary Ann Fugier

Hi mere mortal Jeremy,

I used Bluebeam to create a small PDF containing only the corner of the page that shows the problem. That PDF causes a Null reference error when importing into Rhino:
Import PDF - null reference.pdf (57.3 KB)

So I used Publish-Flattened in Bluebeam and got this file:
Import PDF - flattened.pdf (57.4 KB)

This one imports into Rhino without the null reference error, but the text is corrupted again, and interestingly, in a different way from the original PDF.

I fed the raw text imported by Rhino to Codex, and it found a pretty interesting pattern.

For example, the flattened PDF contains:

  • 02-20-2026, which Rhino imports as ϬϮͲϮϬͲϮϬϮϲ
  • M4-RF020, which Rhino imports as DϰͲZ&ϬϮϬ
  • SHEET NO, which becomes something equivalent to ^,dEK, including actual control characters
  • 2.20, which becomes Ϯ͘ϮϬ

What is especially interesting is that some of these characters have a very precise relationship with the corruption in the original PDF.

In the original PDF Rhino imported:

0 → ì   U+00EC
2 → î   U+00EE
4 → ð   U+00F0
6 → ò   U+00F2
- → r   U+0072
. → X   U+0058

After Bluebeam flattened the PDF, Rhino imports those same intended characters as:

0 → Ϭ   U+03EC
2 → Ϯ   U+03EE
4 → ϰ   U+03F0
6 → ϲ   U+03F2
- → Ͳ   U+0372
. → ͘   U+0358

Every one of those new Unicode values is exactly the previous corrupted value + 0x300.

For example:

ì U+00EC → Ϭ U+03EC
î U+00EE → Ϯ U+03EE
r U+0072 → Ͳ U+0372
X U+0058 → ͘ U+0358

That seems a little too systematic to be random.

The flattened PDF also corrupts characters that were previously imported correctly, for example M → D, R → Z, and F → &, so Bluebeam has presumably rewritten/subset/re-encoded the font while flattening, and Rhino is now interpreting that new encoding differently.

I obviously don’t know what is happening inside the PDF importer, but this makes it look less like a missing-font problem and more like some character/glyph codes are being interpreted using the wrong mapping.

Hi @mary ,

I’ve attached two more small PDF files in my reply to Jeremy.

One of them causes a NullReference error when imported into Rhino. The other is a flattened version of the same file; that one imports, but the text is corrupted in a different way from the original PDF.

Both text corruptions look like character-mapping problems, but with different mappings.

In the original PDF, the digit corruption is very systematic. For example:

0 → ì
1 → í
2 → î
...
9 → õ

Those Unicode values are exactly the ASCII digit values plus 0xBC.

In the flattened PDF, the corruption changes again. For the same characters, some of the new corrupted Unicode values are exactly the previous corrupted values plus 0x300.

So it looks like Rhino may be reading character codes from different PDF font encodings and mapping them incorrectly, rather than this being a simple missing-font issue.

At this point there are three useful test cases:

  • the original PDF, which imports with one repeatable character mapping;
  • the small PDF, which fails with a NullReference;
  • the flattened version, which imports but produces a different repeatable character mapping.

I don’t know whether the NullReference is directly related, but since all three files come from the same content, hopefully they help narrow down what the importer is doing.

Stefano,

Your PDFs are using a font called Calibri-Bold. That font is not installed on my PC and I don’t know where it comes from. The Calibri font from Microsoft has a Bold weight available (CalibriB.ttf) but it is not referenced with a hyphen.

As a test, try creating a PDF using the Microsoft Calibri font and the bold weight and see if that reads better. If BlueBeam insists on/substitutes Calibri-Bold, try creating the text in Word using Calibri with bold weight and save to PDF (ie use the MS PDF writer). If push comes to shove, try this small file:
A2.pdf (31.5 KB)

In quick tests here I find the Word originated PDF imports correctly into Rhino.

Let me know how you get on.

Regards
Jeremy

Jeremy,

I created a small Word document with a few lines in Calibri and then repeated the same lines in Calibri-Bold as you suggested. Word warned me that Calibri-Bold wasn’t available on this computer and that this could cause problems later.

I then printed the document to PDF and imported that PDF into Rhino. Interestingly, neither set of text came through correctly, not even the regular Calibri text.

Here is what the document looks like in Word and after importing into Rhino:

Calibri-Bold from Word.pdf (211.4 KB)

I was never convinced that the problem was simply Rhino choosing the wrong replacement font, as suggested in some of the older reports.

A missing font could explain why the text is rendered with a different typeface, but it shouldn’t normally change the actual characters. Here Rhino seems to be doing two separate things: falling back to another font, which is reasonable if the original font isn’t available, and also interpreting some of the character codes incorrectly.

That second part seems more consistent with the repeatable character mappings I found in the other PDFs.

Thanks @Stefano_Menci and @jeremy5.

This is logged and on the developers stack of issue.
RH-98116/PDF-Imports-Some-Text-Incorrectly
They will let you know if they need anything more.

We do have quite a few of these logged. There may be a “domino” affect, when one of two are fixed, then that fix applies to and fixes many others.

You will be notified here when there is a fix to test.

Sincerely,
Mary Ann Fugier

Hi Stefano,

In your latest example you referenced the missing font Calibri-Bold, however the interesting thing to explore is what happens when you don’t. I copied the text from your illustration and set the first four lines to Calibri and the last four to Calibri with Bold applied. I made no reference to the missing Calibri-Bold. The text imports and displays correctly.


abc calib reg and bold.pdf (63.9 KB)

@mary, This suggests to me that the problem may lie in a mismatch between the way PDF writers handle missing font files at the time of creation and Rhino’s import capabilities.

HTH
Jeremy

Hi Jeremy,

You said Calibri-Bold, so I actually typed Calibri-Bold as the font name rather than selecting Calibri and then applying bold formatting. I’m not sure whether I misunderstood what you meant, but either way it gave us another useful test case.

And the result is consistent with what I’ve seen in most of the other PDFs I’ve tried, as well as the older reports in this forum: the PDF renders correctly in normal PDF viewers, a simple Python script extracts the correct text from it, and it imports correctly into other CAD software, but the text is corrupted when imported into Rhino.

That seems to point pretty strongly to the problem being in Rhino’s PDF importer rather than in the PDF itself.


P.S. In case you are trying to help me generate PDFs that are more Rhino-friendly, that’s not really the problem I’m trying to solve.

I need to import PDFs coming from different clients, generated by different applications, with different fonts and different PDF writers. I don’t have control over how those files are created.

So for me the important part is understanding why PDFs that render correctly, contain extractable text, and import correctly elsewhere can still have their text corrupted by Rhino.

@mary,
Just to point the finger more firmly at missing fonts, I used Fontlab to create a new font ‘Calibri-Bold’ (as a copy of the standard Microsoft Calibri Bold). With this installed, Stefano’s ‘Calibri-Bold fromWord.pdf’ file now imports and displays correctly.

When a PDF Writer attempts to create a pdf file using a font that is missing from the PC and therefore not embeddable, it applies a special font name, CIDFont+Fn, where n is an integer starting at 1 and incremented for each missing font. If the missing font is available on target PCs then it is used and the PDF renders correctly. Otherwise a font substitution is used. In Rhino’s case, it substitutes Arial, but this renders incorrect glyphs.

I don’t know why that isn’t rendering the correct glyphs given a variant of the PDF with the text created using Arial instead of Calibri renders almost correctly on import (for the punctuation it displays the right glyphs but unfortunately doesn’t always advance the next character):


A separate bug.

One would have to look at the source code to understand why this fails.
Once someone who understands that code looks at it, it’s likely this gets fixed. As I’ve said before, we don’t currently have anyone looking at that part of the code.

Just for what it’s worth…
An AI looking at that code tells me:

PDFs with a /ToUnicode CMap (typically “printed from Word”) import fine. CAD/plot PDF writers (AutoCAD, Bluebeam, Revit) that subset fonts and reassign codes via a bare /Differences array with no /ToUnicode dump their arbitrary internal subset byte codes straight into Rhino’s text — hence the mixed correct/incorrect characters in one string, the different-but-internally-consistent mapping between the original and Bluebeam-flattened copy of the same page, and the stray control characters.

It then produces a Python script to “solve” that. Running that script on the PDF files that were provided here fails miserably for all of them.
-wim

RH-98116 is fixed in Rhino 8 Service Release 36