Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Convert fontname to str if it is bytes in HTMLConverter #734

Merged
merged 2 commits into from
Mar 21, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,17 +1,26 @@
# Changelog
All notable changes in pdfminer.six will be documented in this file.

All notable changes in pdfminer.six will be documented in this file.

The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).

## [Unreleased]

### Fixes

- `TypeError` in HTMLConverter when using a bytes fontname ([#734](https://github.com/pdfminer/pdfminer.six/pull/734))

## [20220319]

### Added

- Export type annotations from pypi package per PEP561 ([#679](https://github.com/pdfminer/pdfminer.six/pull/679))
- Support for identity cmap's ([#626](https://github.com/pdfminer/pdfminer.six/pull/626))
- Add support for PDF page labels ([#680](https://github.com/pdfminer/pdfminer.six/pull/680))
- Installation of Pillow as an optional extra dependency ([#714](https://github.com/pdfminer/pdfminer.six/pull/714))

### Fixed

- Hande decompression error due to CRC checksum error ([#637](https://github.com/pdfminer/pdfminer.six/pull/637))
- Regression (since 20191107) in `LTLayoutContainer.group_textboxes` that returned some text lines out of order ([#659](https://github.com/pdfminer/pdfminer.six/pull/659))
- Add handling of JPXDecode filter to enable extraction of images for some pdfs ([#645](https://github.com/pdfminer/pdfminer.six/pull/645))
Expand Down
5 changes: 3 additions & 2 deletions pdfminer/converter.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
from .pdfinterp import PDFGraphicState, PDFResourceManager
from .pdfpage import PDFPage
from .pdftypes import PDFStream
from .utils import AnyIO, Point, Matrix, Rect, PathSegment
from .utils import AnyIO, Point, Matrix, Rect, PathSegment, make_compat_str
from .utils import apply_matrix_pt
from .utils import bbox2str
from .utils import enc
Expand Down Expand Up @@ -633,7 +633,8 @@ def render(item: LTItem) -> None:
render(child)
self.end_div("textbox")
elif isinstance(item, LTChar):
self.put_text(item.get_text(), item.fontname, item.size)
fontname = make_compat_str(item.fontname)
self.put_text(item.get_text(), fontname, item.size)
elif isinstance(item, LTText):
self.write_text(item.get_text())
return
Expand Down
5 changes: 4 additions & 1 deletion pdfminer/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,10 @@ def make_compat_str(o: object) -> str:
"""Converts everything to string, if bytes guessing the encoding."""
if isinstance(o, bytes):
enc = chardet.detect(o)
return o.decode(enc["encoding"])
try:
return o.decode(enc["encoding"])
except UnicodeDecodeError:
return str(o)
else:
return str(o)

Expand Down