-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
ENH: Return color/font/formatting information for outline/bookmarks #513
Labels
is-feature
A feature request
PdfWriter
The PdfWriter component is affected
workflow-bookmarks
From a users perspective, bookmarks is the affected feature/workflow
Comments
With pull request #514, the following code should work. def detail_outlines(pdf):
for line in pdf.getOutlines():
if isinstance(line, list):
yield extract_outlines(line)
else:
title = line.title
page = line.page.pdf.getDestinationPageNumber(line)
typ = line.typ
color = rgb_to_hex([0, 0, 0])
italic = 'notItalic'
bold = 'notBold'
if item.get('/C'):
color = rgb_to_hex(item.get('/C'))
if item.get('/F'):
if item.get('/F') in [1,3]:
italic = 'italic'
if item.get('/F') in [2,3]:
bold = 'bold'
yield f'{title}, {pagenum}, {color}, {italic}, {bold}, {typ}'
def rgb_to_hex(rgb):
red, green, blue = (int(x*255) for x in rgb)
hex_string = f'#{red:02X}{green:02X}{blue:02X}'
return hex_string
detail_outlines(pdf)
>>> 'a newly added bookmark that is red and bold, 2, #FF0000, notItalic, bold, /XYZ' |
MartinThoma
added
is-feature
A feature request
workflow-bookmarks
From a users perspective, bookmarks is the affected feature/workflow
PdfWriter
The PdfWriter component is affected
labels
Apr 16, 2022
MartinThoma
changed the title
Extracting outline/bookmarks doesn't return color or font formatting information
ENH: Return color/font/formatting information for outline/bookmarks
Jul 9, 2022
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
is-feature
A feature request
PdfWriter
The PdfWriter component is affected
workflow-bookmarks
From a users perspective, bookmarks is the affected feature/workflow
Currently, when applying bookmarks to a document through the
PdfFileWriter
class methodaddBookmark
, one can specify the color, bold, and italic properties of the bookmark using code such asHowever, when retrieving the bookmarks via the
PdfFileReader
class methodgetOutlines
the color, bold, and italic formatting information is not returned.The text was updated successfully, but these errors were encountered: