Commit graph

112 commits

Author SHA1 Message Date
Ejaaz Khan
5f99434f52 fix: import function/module inside inside fucntion 2025-09-29 23:09:25 +05:30
Ejaaz Khan
964dd6c034 feat: Chrome PDF generator
Co-authored-by: maharshivpatel <maharshivpatel@users.noreply.github.com>
2025-09-29 12:15:51 +05:30
Akhil Narang
36ccf32ab3
fix: don't try to scan encrypted PDFs
Also fix reversed logic of JS check

Signed-off-by: Akhil Narang <me@akhilnarang.dev>
2025-09-10 15:44:09 +05:30
sokumon
5e21a2e2ab fix: relax the logic 2025-09-02 14:54:55 +05:30
sokumon
fd29103149 fix: make the checking more robust 2025-08-29 13:13:19 +05:30
sokumon
ca5831b1a8 fix: better function name, check before writing the file 2025-08-29 13:13:19 +05:30
sokumon
577ba89c28 fix(XSS): verify pdf content before uploading 2025-08-29 13:13:19 +05:30
Maharshi Patel
463d1f2b05 fix: code changes as pdf_generator is now select field 2025-02-14 17:04:13 +05:30
Maharshi Patel
61aabd00af chore: renamed arg name and cleanup
- fixed chrome_pdf_backend arg by making it int and using it to properly override which pdf generator (chrome / wkhtmltopdf) to use.
- renamed new_pdf_backend to chrome_pdf_backend.
- added chrome_pdf_backend arg in local.from_dict to avoid passing it 4-5 functions deep
2025-02-12 13:24:50 +05:30
Maharshi Patel
dd037f54ea feat(minor): add pdf backend hook
added new_pdf_backend hook to run alternate get_pdf function from other apps e.g. print designer.
2025-02-01 19:47:29 +05:30
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