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
Fix: individual /Resources directory are now properly produced for each document page #1133
base: master
Are you sure you want to change the base?
Conversation
f655bbb
to
d11887a
Compare
Could you please review this @andersonhc or @gmischler? Despite the 100+ reference PDF files modified, this PR onlys affects 2 source Python files and is relatively short. |
b9fdf5e
to
af159f9
Compare
There are some alternative approaches to the one currently used in this PR:
|
af159f9
to
c123b0e
Compare
I will try to make some time for a complete review by tomorrow. An example: from fpdf import FPDF
pdf = FPDF()
pdf.add_font("NotoSans", "B", "NotoSans-Bold.ttf")
pdf.add_font("NotoSans", "BI", "NotoSans-BoldItalic.ttf")
pdf.add_font("NotoSans", "I", "NotoSans-Italic.ttf")
pdf.add_font("NotoSans", "", "NotoSans-Regular.ttf")
pdf.set_font("NotoSans", "", 12)
pdf.single_resources_object = False
pdf.add_page()
pdf.multi_cell(w=pdf.epw, text="**Text in bold**", markdown=True)
pdf.add_page()
pdf.multi_cell(w=pdf.epw, text="__Text in italic__", markdown=True)
pdf.output("test1.pdf") The page 1 will have "F1" and "F4" in the resources dictionary, and page 2 will have "F3" and "F4". I have documents with many fallback fonts and there is a considerable amount of unused font data added to the documents. Might be something to tackle in a future PR. |
@@ -25,6 +25,7 @@ This can also be enabled programmatically with `warnings.simplefilter('default', | |||
* [`FPDF.write_html()`](https://py-pdf.github.io/fpdf2/fpdf/fpdf.html#fpdf.fpdf.FPDF.write_html) now accepts a `tag_indents` parameter to control, for example, the indent of `<blockquote>` elements | |||
* allow to define custom `cell_fill_mode` logic for tables: [_Set cells background_ - documentation section](https://py-pdf.github.io/fpdf2/Tables.html#set-cells-background). Also added 2 new values: `TableCellFillMode.EVEN_ROWS` & `TableCellFillMode.EVEN_COLUMNS`: [documentation](https://py-pdf.github.io/fpdf2/fpdf/enums.html#fpdf.enums.TableCellFillMode) | |||
### Fixed | |||
* individual `/Resources` directory are now properly produced for **each** document page. This causes a slight increase of PDF documents, but makes their structure more valid regarding the PDF spec. You can still use the old behaviour by setting `FPDF().single_resources_object = True`. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Suggestion to make it clearer the increase is the size of the documents:
- individual
/Resources
directories are now properly created for each document page. This change ensures better compliance with the PDF specification but results in a slight increase in the size of PDF documents. You can still use the old behavior by settingFPDF().single_resources_object = True
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't have anything else to add. The changes are simple and clear.
I didn't have time to visually inspect all the changed reference files but I did a few and everything looks OK.
page_img_objs_per_index, | ||
page_gfxstate_objs_per_name, | ||
) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Suggestions for future improvement:
If multiple pages use the exact same resources, they can make reference to the same resource dictionary object.
This change causes a slight increase of PDF documents, but makes their structure more valid regarding the PDF spec.
Checklist:
The GitHub pipeline is OK (green), meaning that both
pylint
(static code analyzer) andblack
(code formatter) are happy with the changes of this PR.A unit test is covering the code added / modified by this PR
This PR is ready to be merged
In case of a new feature, docstrings have been added, with also some documentation in the
docs/
folderA mention of the change is present in
CHANGELOG.md
By submitting this pull request, I confirm that my contribution is made under the terms of the GNU LGPL 3.0 license.