Skip to content

Conversation

@JordiBForgeFlow
Copy link
Member

@JordiBForgeFlow JordiBForgeFlow commented Apr 21, 2017

Report Paper Wkhtmltopdf Params

This module allows you to add new parameters for a paper format which are
then forwarded to wkhtmltopdf command as arguments.

Usage

  • Go to Settings and press 'Activate the developer mode (with assets)'

  • Go to Settings - Technical - Reports - Paper Format

  • Change the parameter 'Disable Smart Shrinking'.

  • Add additional parameters indicating the command argument name (remember to
    add prefix -- or -) and value.

@JordiBForgeFlow
Copy link
Member Author

This is a migration of the module created by @mlaitinen, from https://github.com/avoinsystems/report_paper_params

@pedrobaeza
Copy link
Member

You should credit him in the commit author.

@JordiBForgeFlow JordiBForgeFlow force-pushed the 10.0-add-report_paper_wkhtmltopdf_params branch from 11e9fe4 to 1d4cda1 Compare April 21, 2017 22:28
@mlaitinen
Copy link

Thanks @jbeficent for creating the PR. I've been extremely busy lately and this has been on my todo list.

@JordiBForgeFlow JordiBForgeFlow force-pushed the 10.0-add-report_paper_wkhtmltopdf_params branch 2 times, most recently from e4ae996 to 38ef37f Compare April 21, 2017 22:42
@JordiBForgeFlow
Copy link
Member Author

@pedrobaeza Done! @mlaitinen Thanks to you!! That's what we're here for, to help each other :)

@JordiBForgeFlow JordiBForgeFlow force-pushed the 10.0-add-report_paper_wkhtmltopdf_params branch from 656dfd7 to 648f35a Compare April 21, 2017 23:08
Copy link

@elicoidal elicoidal left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please reconsider the scope of the module features

===============================

This module allows you to add new parameters for a paper format which are
then forwarded to wkhtmltopdf command as arguments.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you explain the param you are tweaking and the advantage of modifying it?

Usage
=====

* Go to *Settings* and press 'Activate the developer mode (with assets)'

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

usually better enumerated list for procedures ("#. ")

* Change the parameter 'Disable Smart Shrinking'.

* Add additional parameters indicating the command argument name (remember to
add prefix -- or -) and value.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you provide an example and/or a link to the param list?


* Go to *Settings - Technical - Reports - Paper Format*

* Change the parameter 'Disable Smart Shrinking'.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why smart shrinking is so special? (I know: it fitted your needs)
My point is why having a module for this special attribute and allow then to have another free text for whatever attributes you want to add.
I would rather have it without the checkbox for smart-shrinking (then you just have to set up the module for your own usage) or with all options available for any (or most of) the good options that wkhtml2pdf can offer.
Option 1 is more flexible and lighter and more prone to errors
Option 2 avoids Odoo crashing controlling the input (which somehow I kinda prefer)

What do you think?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will properly update documentation. smart shrinking is important when you intend to have a layout that conforms to certain alignment. It is very common whenever you need to conform the PDF to a predefined layoyut (e.g. checks, official forms,...).

It is specifically proposed because it is the most common use case where you need to add a parameter to wkhtmltopdf.

As for the free parameters, they are only supposed to be used by admin users.

The options available are:
`Global Options:
--collate Collate when printing multiple copies
(default)
--no-collate Do not collate when printing multiple
copies
--cookie-jar Read and write cookies from and to the
supplied cookie jar file
--copies Number of copies to print into the pdf
file (default 1)
-d, --dpi Change the dpi explicitly (this has no
effect on X11 based systems) (default 96)
-H, --extended-help Display more extensive help, detailing
less common command switches
-g, --grayscale PDF will be generated in grayscale
-h, --help Display help
--htmldoc Output program html help
--image-dpi When embedding images scale them down to
this dpi (default 600)
--image-quality When jpeg compressing images use this
quality (default 94)
--license Output license information and exit
-l, --lowquality Generates lower quality pdf/ps. Useful to
shrink the result document space
--manpage Output program man page
-B, --margin-bottom Set the page bottom margin
-L, --margin-left Set the page left margin (default 10mm)
-R, --margin-right Set the page right margin (default 10mm)
-T, --margin-top Set the page top margin
-O, --orientation Set orientation to Landscape or Portrait
(default Portrait)
--page-height Page height
-s, --page-size Set paper size to: A4, Letter, etc.
(default A4)
--page-width Page width
--no-pdf-compression Do not use lossless compression on pdf
objects
-q, --quiet Be less verbose
--read-args-from-stdin Read command line arguments from stdin
--readme Output program readme
--title The title of the generated pdf file (The
title of the first document is used if not
specified)
--use-xserver Use the X server (some plugins and other
stuff might not work without X11)
-V, --version Output version information and exit

Outline Options:
--dump-default-toc-xsl Dump the default TOC xsl style sheet to
stdout
--dump-outline Dump the outline to a file
--outline Put an outline into the pdf (default)
--no-outline Do not put an outline into the pdf
--outline-depth Set the depth of the outline (default 4)

Page Options:
--allow Allow the file or files from the specified
folder to be loaded (repeatable)
--background Do print background (default)
--no-background Do not print background
--bypass-proxy-for Bypass proxy for host (repeatable)
--cache-dir Web cache directory
--checkbox-checked-svg Use this SVG file when rendering checked
checkboxes
--checkbox-svg Use this SVG file when rendering unchecked
checkboxes
--cookie Set an additional cookie (repeatable),
value should be url encoded.
--custom-header Set an additional HTTP header (repeatable)
--custom-header-propagation Add HTTP headers specified by
--custom-header for each resource request.
--no-custom-header-propagation Do not add HTTP headers specified by
--custom-header for each resource request.
--debug-javascript Show javascript debugging output
--no-debug-javascript Do not show javascript debugging output
(default)
--default-header Add a default header, with the name of the
page to the left, and the page number to
the right, this is short for:
--header-left='[webpage]'
--header-right='[page]/[toPage]' --top 2cm
--header-line
--encoding Set the default text encoding, for input
--disable-external-links Do not make links to remote web pages
--enable-external-links Make links to remote web pages (default)
--disable-forms Do not turn HTML form fields into pdf form
fields (default)
--enable-forms Turn HTML form fields into pdf form fields
--images Do load or print images (default)
--no-images Do not load or print images
--disable-internal-links Do not make local links
--enable-internal-links Make local links (default)
-n, --disable-javascript Do not allow web pages to run javascript
--enable-javascript Do allow web pages to run javascript
(default)
--javascript-delay Wait some milliseconds for javascript
finish (default 200)
--keep-relative-links Keep relative external links as relative
external links
--load-error-handling Specify how to handle pages that fail to
load: abort, ignore or skip (default
abort)
--load-media-error-handling Specify how to handle media files
that fail to load: abort, ignore or skip
(default ignore)
--disable-local-file-access Do not allowed conversion of a local file
to read in other local files, unless
explicitly allowed with --allow
--enable-local-file-access Allowed conversion of a local file to read
in other local files. (default)
--minimum-font-size Minimum font size
--exclude-from-outline Do not include the page in the table of
contents and outlines
--include-in-outline Include the page in the table of contents
and outlines (default)
--page-offset Set the starting page number (default 0)
--password HTTP Authentication password
--disable-plugins Disable installed plugins (default)
--enable-plugins Enable installed plugins (plugins will
likely not work)
--post Add an additional post field (repeatable)
--post-file Post an additional file (repeatable)
--print-media-type Use print media-type instead of screen
--no-print-media-type Do not use print media-type instead of
screen (default)
-p, --proxy Use a proxy
--radiobutton-checked-svg Use this SVG file when rendering checked
radiobuttons
--radiobutton-svg Use this SVG file when rendering unchecked
radiobuttons
--resolve-relative-links Resolve relative external links into
absolute links (default)
--run-script Run this additional javascript after the
page is done loading (repeatable)
--disable-smart-shrinking Disable the intelligent shrinking strategy
used by WebKit that makes the pixel/dpi
ratio none constant
--enable-smart-shrinking Enable the intelligent shrinking strategy
used by WebKit that makes the pixel/dpi
ratio none constant (default)
--stop-slow-scripts Stop slow running javascripts (default)
--no-stop-slow-scripts Do not Stop slow running javascripts
--disable-toc-back-links Do not link from section header to toc
(default)
--enable-toc-back-links Link from section header to toc
--user-style-sheet Specify a user style sheet, to load with
every page
--username HTTP Authentication username
--viewport-size <> Set viewport size if you have custom
scrollbars or css attribute overflow to
emulate window size
--window-status Wait until window.status is equal to this
string before rendering page
--zoom Use this zoom factor (default 1)

Headers And Footer Options:
--footer-center Centered footer text
--footer-font-name Set footer font name (default Arial)
--footer-font-size Set footer font size (default 12)
--footer-html Adds a html footer
--footer-left Left aligned footer text
--footer-line Display line above the footer
--no-footer-line Do not display line above the footer
(default)
--footer-right Right aligned footer text
--footer-spacing Spacing between footer and content in mm
(default 0)
--header-center Centered header text
--header-font-name Set header font name (default Arial)
--header-font-size Set header font size (default 12)
--header-html Adds a html header
--header-left Left aligned header text
--header-line Display line below the header
--no-header-line Do not display line below the header
(default)
--header-right Right aligned header text
--header-spacing Spacing between header and content in mm
(default 0)
--replace Replace [name] with value in header and
footer (repeatable)

TOC Options:
--disable-dotted-lines Do not use dotted lines in the toc
--toc-header-text The header text of the toc (default Table
of Contents)
--toc-level-indentation For each level of headings in the toc
indent by this length (default 1em)
--disable-toc-links Do not link from toc to sections
--toc-text-size-shrink For each level of headings in the toc the
font is scaled by this factor (default
0.8)
--xsl-style-sheet Use the supplied xsl style sheet f`

Contributors
------------

* Miku Laitinen <[email protected]>

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

contribution for the original author

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

He is the original author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍


def _build_wkhtmltopdf_args(self, paperformat,
specific_paperformat_args=None):
# noinspection PyUnresolvedReferences,PyProtectedMember

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not clear: remove or improve

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is actually very interesting, when you work with PyCharm, Will remove warning messages.

name = fields.Char(
'Name',
required=True,
help='The command argument name. Remember to add prefix -- or -'

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

back to my previous comment, there is no control of the input: flexible but dangerous.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What kind of validation would you suggest?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I propose that we add not validation. The documentation provides enough details on how to properly set it up.

@JordiBForgeFlow
Copy link
Member Author

@mlaitinen @elicoidal I have removed the field disable_smart_shrinking, and updated the documentation to use as an example how to add the parameter --disable-smart-shrinking. This makes the module generic for anyone to use it the way they want.

I have tested and works for me very well.

@pedrobaeza
Copy link
Member

A possible validation is to call from @api.constrains method the command line with that arguments over a sample blank HTML file provided with this module. This way, you have dynamic argument checking depending on the wkhtmltopdf version you deploy in your system.

@JordiBForgeFlow
Copy link
Member Author

@pedrobaeza thanks for the suggestion. I have implemented a small html. When the parameters are wrong it will not render a PDF, and then we raise an error to the user.

@JordiBForgeFlow JordiBForgeFlow force-pushed the 10.0-add-report_paper_wkhtmltopdf_params branch from f0ed298 to e1f7e68 Compare April 26, 2017 12:22
Copy link
Contributor

@LoisRForgeFlow LoisRForgeFlow left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good one! 👍

@JordiBForgeFlow JordiBForgeFlow force-pushed the 10.0-add-report_paper_wkhtmltopdf_params branch from c3bbb40 to 5e6cc95 Compare April 26, 2017 13:06
@JordiBForgeFlow JordiBForgeFlow force-pushed the 10.0-add-report_paper_wkhtmltopdf_params branch from 5e6cc95 to 3f656a5 Compare April 26, 2017 13:24
@dreispt
Copy link
Member

dreispt commented Apr 26, 2017

I wonder if this shouldn't rather be hosted at OCA/reporting-engine ?

@JordiBForgeFlow
Copy link
Member Author

@dreispt Yes, would be better there... @pedrobaeza your thoughts?

@pedrobaeza
Copy link
Member

I agree, and renamed without "paper" part and without plural: report_wkhtmltopdf_param

@JordiBForgeFlow
Copy link
Member Author

@pedrobaeza You kill me, man.... I have this already deployed in a production environment.

@pedrobaeza
Copy link
Member

hehe, but it's easy from a shell command:

from openupgradelib import openupgrade

openupgrade.update_module_names([('report_paper_wkhtmltopdf_params', 'report_wkhtmltopdf_param')])

Another option is to rename column, uninstall module, rename again, and install the new one.

You already knew before the no plural in module names convention...

@JordiBForgeFlow
Copy link
Member Author

ok... will do that

@dreispt
Copy link
Member

dreispt commented Apr 26, 2017

Can't you bump module version and provide a migration script in the module? (Not that I have done that myself...)

@pedrobaeza
Copy link
Member

Not for module renamings.

SiesslPhillip pushed a commit to grueneerde/OCA-server-tools that referenced this pull request Nov 20, 2024
…obaeza-bump-minor

Syncing from upstream OCA/server-tools (14.0-ocabot-merge-pr-2198-by-pedrobaeza-bump-minor)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants