14.3.119. crate_anon.crateweb.extra.pdf

crate_anon/crateweb/extra/pdf.py


Copyright (C) 2015, University of Cambridge, Department of Psychiatry. Created by Rudolf Cardinal (rnc1001@cam.ac.uk).

This file is part of CRATE.

CRATE is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

CRATE is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with CRATE. If not, see <https://www.gnu.org/licenses/>.


Assistance functions for working with PDFs.

class crate_anon.crateweb.extra.pdf.CratePdfPlan(*args, **kwargs)[source]

Specializes cardinal_pythonlib.pdf.PdfPlan for our default header/footer.

__init__(*args, **kwargs) None[source]
Parameters
  • is_html – use HTML mode?

  • html – for HTML mode, the main HTML

  • header_html – for HTML mode, an optional page header (in HTML)

  • footer_html – for HTML mode, an optional page footer (in HTML)

  • wkhtmltopdf_filename – filename of the wkhtmltopdf executable

  • wkhtmltopdf_options – options for wkhtmltopdf

  • is_filename – use file mode?

  • filename – for file mode, the filename of the existing PDF on disk

Use either is_html or is_filename, not both.

crate_anon.crateweb.extra.pdf.get_pdf_from_html_with_django_settings(html: str, header_html: Optional[str] = None, footer_html: Optional[str] = None, wkhtmltopdf_filename: Optional[str] = None, wkhtmltopdf_options: Optional[Dict[str, Any]] = None, debug_content: bool = False, debug_options: bool = False, fix_pdfkit_encoding_bug: Optional[bool] = None) bytes[source]

Applies our settings.WKHTMLTOPDF_OPTIONS and then makes a PDF from the supplied HTML.

See the arguments to cardinal_pythonlib.pdf.make_pdf_from_html().

Returns

a binary PDF

crate_anon.crateweb.extra.pdf.make_pdf_on_disk_from_html_with_django_settings(html: str, header_html: Optional[str] = None, footer_html: Optional[str] = None, wkhtmltopdf_filename: Optional[str] = None, wkhtmltopdf_options: Optional[Dict[str, Any]] = None, output_path: Optional[str] = None, debug_content: bool = False, debug_options: bool = False, fix_pdfkit_encoding_bug: Optional[bool] = None) bool[source]

Applies our settings.WKHTMLTOPDF_OPTIONS and then makes a PDF from the supplied html and stores it in the file named by output_path.

See the arguments to cardinal_pythonlib.pdf.make_pdf_from_html().

Returns

success?

crate_anon.crateweb.extra.pdf.serve_html_or_pdf(html: str, viewtype: str) django.http.response.HttpResponse[source]

Serves some HTML as HTML or after converting it to a PDF in our letter style. For development.

Parameters
  • html – contents

  • viewtype"pdf" or "html"

crate_anon.crateweb.extra.pdf.serve_pdf_from_html(html: str, offered_filename: str = 'test.pdf', **kwargs) django.http.response.HttpResponse[source]

Converts HTML into a PDF and serves it.

Parameters