* chore: warn if wkhtmltopdf is invalid
wkhtmltopdf ( with patched qt ) is required to generate pdfs properly.
when user clicks on PDF, pdf will be generated and downloaded.
however, on print preview page warning will be shown.
* chore: refactor based on review comments
* chore: return False incase of exception
* chore: refactor and better naming
Co-authored-by: Ankush Menat <ankushmenat@gmail.com>
- Regex incorrectly fetches .print-format's child styles and also extracts the wrong attribute value
- A CssParser is more maintainable and more readable as well as less prone to errors while extracting values
- Method: We extract style tag contents out of the html and tokenize them. We then filter the styles for the right selector and extract the attributes we want from them.
- This way we make sure that the right value is extracted and only the ones applicable to .print-format directly
* refactor: Private images rendering in PDFs
Private images currently render fine if PDF is generated during a
request as we pass the cookiejar to WKHTML.
Background jobs however fail completeley because they can't retrieve
private images without cookiejar.
This PR converts all image types to base64 encoded sources in HTML
itself, so wkhtmltopdf doesn't have to a fire a request.
* test: private images in pdf
- Extract header/footer html into `content` first, then remove any instances from the main content since it is already rendered via the extracted header/footer html
- `frappe.get_print` calls `get_response_content("printview")` which calls `www/printview` that adds header and footer scripts
- Now it gets added again via `pdf_header_footer.html` which causes the script to run twice
- Header and Footer html are also added twice but then removed and handled in pdf.py (because printview + wkhtml processing)
- Misc: Use walrus operator
- Remove passed `letterhead` to insert script via pdf.py, printview handles it
- feat: Allow script injection into header/footer.html to allow manipulation of styles using page numbers/args received by wkhtmltopdf
- misc: also validate letterhead scripts
- Include scripts in printview as well as pdf
- Add helper instructions & re-arrange fields
refactor: clean up code to py39+ supported syntax
- f-strings instead of format
- latest typing support instead of pre 3.9 TitleCase
- remove UTF-8 declarations.
- many more changes
Powered by https://github.com/asottile/pyupgrade/ + manual cleanups
The license.txt file has been replaced with LICENSE for quite a while
now. INAL but it didn't seem accurate to say "hey, checkout license.txt
although there's no such file". Apart from this, there were
inconsistencies in the headers altogether...this change brings
consistency.
* Remove six for PY2 compatability since our dependencies are not, PY2
is legacy.
* Removed usages of utils from future/past libraries since they are
deprecated. This includes 'from __future__ ...' and 'from past...'
statements.
* Removed compatibility imports for PY2, switched from six imports to
standard library imports.
* Removed utils code blocks that handle operations depending on PY2/3
versions.
* Removed 'from __future__ ...' lines from templates/code generators
* Used PY3 syntaxes in place of PY2 compatible blocks. eg: metaclass
* chore(deps): bump bleach from 2.1.4 to 3.1.2
Bumps [bleach](https://github.com/mozilla/bleach) from 2.1.4 to 3.1.2.
- [Release notes](https://github.com/mozilla/bleach/releases)
- [Changelog](https://github.com/mozilla/bleach/blob/master/CHANGES)
- [Commits](https://github.com/mozilla/bleach/compare/v2.1.4...v3.1.2)
Signed-off-by: dependabot[bot] <support@github.com>
* chore: use html.parser instead of html5lib
bleach no longer ships html5lib as a requirement and instead has
included it in the system. we can switch to using html.parser instead;
which is not an external dependency unlike html5lib.
source: https://github.com/mozilla/bleach/blob/master/CHANGES#L206
Signed-off-by: Chinmay D. Pai <chinmaydpai@gmail.com>
* chore: use html5lib from bleach
Signed-off-by: Chinmay D. Pai <chinmaydpai@gmail.com>
* chore: import html5lib from bleach._vendor
fixes issue where bs4 is unable to find html5lib in the tree:
bs4.FeatureNotFound: Couldn't find a tree builder with the features you requested: bleach._vendor.html5lib. Do you need to install a parser library?
Signed-off-by: Chinmay D. Pai <chinmaydpai@gmail.com>
* chore: just give up and install html5lib as a dependency
Signed-off-by: Chinmay D. Pai <chinmaydpai@gmail.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: Chinmay D. Pai <chinmaydpai@gmail.com>
Same as other attributes, we could indicate default orientation by indicating in the .print-format css class without hardcoding, which is useful for cloud users.
Co-authored-by: Suraj Shetty <13928957+surajshetty3416@users.noreply.github.com>