Commit graph

102 commits

Author SHA1 Message Date
David Arnold
d17136cd04
fix: redirect cssutils logger to file (#28692) 2024-12-08 13:42:18 +05:30
Akhil Narang
84ef6ec677
refactor: fixup with ruff 0.8.1
Signed-off-by: Akhil Narang <me@akhilnarang.dev>
2024-12-04 13:18:04 +05:30
David Arnold
bd06784d1b
ci: Run optimized python and control warnings (#28063)
* ci: run doubly optimized python

* ci: control python warnings
2024-10-09 13:29:30 +00:00
Maharshi Patel
6a6ded156f
chore: warn if wkhtmltopdf is invalid (#26174)
* 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>
2024-04-30 10:36:56 +00:00
Raffael Meyer
2ec9ef5bf3
fix: handle case where mimetype is None (#26131) 2024-04-23 14:24:49 +00:00
Ankush Menat
b47d9d57fb
fix: handle empty style tag (#25910) 2024-04-11 10:06:36 +00:00
marination
96667b1bab chore: Use dict comprehension instead of nested loops 2024-03-27 12:00:49 +01:00
marination
5dbcbbb915 fix: Use CssParser to correctly pass options to wkhtmltopdf
- 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
2024-03-26 10:33:35 +01:00
Ankush Menat
718b5b8bee
fix: Private images in PDFs from background jobs (#24980)
* 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
2024-02-21 10:38:02 +00:00
Ankush Menat
de9ac89748 style: re-format with ruff 2024-02-05 18:53:33 +05:30
Maharshi Patel
3fb418f28f
Merge pull request #23907 from marination/dynamic-header-footer-develop
feat: Letterhead Scripts & fix disappearing header in pdf
2024-02-01 17:43:12 +05:30
marination
4d2c4f020b fix: Check if header/footer html exists before trying to extract
- issue: AttributeError: 'NoneType' object has no attribute 'extract', when no letterhead html was present
2024-01-31 12:54:20 +01:00
marination
bcca1da8d8 fix: Extract header/footer html into content to simplify things
- 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
2024-01-29 13:25:45 +01:00
barredterra
9d6cbd0c15 fix: typos 2024-01-24 02:41:03 +01:00
marination
f77b99396e fix: Custom Script runs twice
- `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
2024-01-22 22:42:13 +01:00
marination
29e761671d feat: Letterhead scripts
- 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
2023-12-21 17:25:19 +01:00
marination
fc0ba51894 fix: Disappearing letterhead header in pdf
- fix: Make sure 'header-html' is extracted from document after it is rendered as html and loaded in wkhtmltopdf options, else it goes missing
2023-12-21 16:15:56 +01:00
Ankush Menat
b0c2f56dae Revert "feat: wkhtmltopdf logging (#19935)"
This reverts commit 6354a018de.
2023-12-05 21:11:35 +05:30
Akhil Narang
0be3b61aec
chore: drop usage of the deprecated distutils.version.LooseVersion
Use `packaging.version.Version` instead

Signed-off-by: Akhil Narang <me@akhilnarang.dev>
2023-10-11 20:13:59 +05:30
Ankush Menat
a2b2998684
fix(DX): Wrap print format errors (#21944)
[skip ci]
2023-08-06 18:55:16 +05:30
Ankush Menat
18e791a353 build(deps): PyPDF2 -> pypdf
closes https://github.com/frappe/frappe/issues/19861
2023-06-10 20:47:27 +05:30
Ankush Menat
fa6dc03cc8
refactor: frappe.cache() usage to frappe.cache (#21282) 2023-06-08 11:47:17 +05:30
Richard Case
6354a018de
feat: wkhtmltopdf logging (#19935)
* feat: wkhtmltopdf logging

* fix: must supply output function
2023-05-24 16:00:32 +05:30
Maharshi Patel
1bae6a2b0b
feat: hooks added for print formats / pdf. (#20734) 2023-04-17 19:03:53 +05:30
Ankush Menat
81b37cb7d2
refactor: clean up code to py310 supported features (#17367)
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
2022-07-01 11:51:05 +05:30
Ankush Menat
d35d7ffbe2 fix: remove bare exception catching
A bare except catches lots of things (like generator iteration end) and should never be used.
2022-06-28 18:05:00 +05:30
Gavin D'souza
ef0a92c849 chore(deps): Bump PyPDF2 from 1.26.0 to 2.1.0
* Updated changes in API usages
* changelog: https://github.com/py-pdf/PyPDF2/blob/main/CHANGELOG
2022-06-10 12:08:10 +05:30
Gavin D'souza
3aef47200b chore(deps): Bumped pdfkit from 0.6.1 to 1.0.0
* Updated from_string API to match latest signature
* changelog: https://github.com/JazzCore/python-pdfkit/blob/master/HISTORY.rst
2022-06-10 11:53:50 +05:30
Suraj Shetty
c0c5b2ebdd
style: format all python files using black (#16453)
Co-authored-by: Frappe Bot <developers@frappe.io>
2022-04-12 10:59:25 +05:30
HarryPaulo
f4518e2cf9
fix(print): Added properties page-width, page-height (#16045) 2022-02-23 13:49:40 +05:30
Rohan Bansal
64c18a3187 feat: allow more print page size options 2021-10-26 17:04:41 +05:30
Gavin D'souza
3446026555 chore: Update header: license.txt => LICENSE
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.
2021-09-03 12:02:59 +05:30
Suraj Shetty
291d7b0f16 fix: Call is_rtl function to get the actual value 2021-08-10 10:13:19 +05:30
Suraj Shetty
0b3402236c fix: Add layout direction to pdf template 2021-07-05 14:44:04 +05:30
Suraj Shetty
70f5df6a05 chore: debug 2021-06-17 18:50:21 +05:30
Gavin D'souza
e407b78506 chore: Drop dead and deprecated code
* 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
2021-05-26 15:31:29 +05:30
Faris Ansari
e72bb135e1 fix: Asset URLs
Helpers to get asset path
Python: frappe.utils.jinja_globals.bundled_asset
JS: frappe.assets.bundled_asset
2021-04-29 14:47:52 +05:30
Faris Ansari
34c6d099b1 fix: Update all /assets urls with new urls 2021-04-24 16:24:08 +05:30
prssanna
a4d8161a87 fix: print pdf fixes 2020-11-24 12:29:27 +05:30
prssanna
76bb9fc608 feat: skeleton loading state for print preview 2020-11-10 11:03:13 +05:30
Aditya Hase
16fc29e48d
fix(pdf): frappe.local.request is not available in backgound jobs and tests
Use frappe.utils.get_host_name instead of frappe.local.request.host
2020-10-27 14:18:36 +05:30
Aditya Hase
3f5f6f3b21
fix(pdf): Remove in_test check from get_pdf 2020-10-27 14:18:35 +05:30
Suraj Shetty
d254933a7c fix: Build cookie jar only if request object is present 2020-10-24 14:12:59 +05:30
Marica
1ad3bb76a5
fix: Skip using cookie-jar to set cookies if via tests (#11700) 2020-10-13 13:35:42 +05:30
Aditya Hase
3c9f265091
fix(pdf): Restrict cookies to the host domain
Use wkhtmltopdf's cookie-jar options to set domain
Reference: 7952b0f3e7/src/lib/multipageloader.cc (L532-L536)
Cookie format Reference: https://doc.qt.io/qt-5/qnetworkcookie.html#parseCookies

Also, werkzeug 0.16.x shows port in the host attribute.
https://werkzeug.palletsprojects.com/en/0.16.x/wrappers/#werkzeug.wrappers.BaseRequest.host
2020-09-09 20:58:42 +05:30
Aditya Hase
8feba5fa9b
fix(pdf): Cleanup temporary files after pdf generation
This was removed in https://github.com/frappe/frappe/pull/7358
2020-09-09 20:52:45 +05:30
Rushabh Mehta
8c8f7313f4
fix(minor): make utils explicit in safe_globals (#11408)
* fix(minor): make utils explicit in safe_globals

* fix(minor): import subprocess

* fix(minor): fix globals in safe_eval;

* fix(minor): import subprocess

* fix(minor): add test

* fix(minor): webhook.py

* fix(minor): document_type_mapping.py
2020-09-03 14:26:01 +05:30
Suraj Shetty
49aba26696 fix: Use non-pretty version of HTML for pdf generation 2020-07-14 16:36:24 +05:30
dependabot[bot]
bdb77ba521
chore(deps): bump bleach from 2.1.4 to 3.1.2 (#9779)
* 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>
2020-03-25 00:20:57 +05:30
Alirio Castro
23d3f0e63b
feat: Indicate orientation for PDF file (#9660)
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>
2020-03-16 17:31:28 +05:30