Skip to content

pdf_document

This module contains class for the PDF document.

Classes
  • PdfDocument: A class representing a PDF document.

PdfDocument

Bases: Document

A class representing a PDF document.

Methods
  • convert_file(): A method for converting file.
Source code in backend/api/converter/document_converter/document/pdf_document.py
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
class PdfDocument(Document):
    """
    A class representing a PDF document.

    Methods:
        - `convert_file()`: A method for converting file.
    """

    def __init__(self, file: str, output: str) -> None:
        """Initialize the PdfDocument object.

        Args:
            file: A string representing the path of the file to be converted.
            output: A string representing the path of output file.
        """
        super().__init__(file, output)

    def convert_file(self) -> None:
        """Convert a html file to a PDF file using the pdfkit library."""
        options = {'encoding': 'UTF-8'}
        pdfkit.from_file(self._file, self._output, options=options)

__init__(file, output)

Initialize the PdfDocument object.

Parameters:

Name Type Description Default
file str

A string representing the path of the file to be converted.

required
output str

A string representing the path of output file.

required
Source code in backend/api/converter/document_converter/document/pdf_document.py
21
22
23
24
25
26
27
28
def __init__(self, file: str, output: str) -> None:
    """Initialize the PdfDocument object.

    Args:
        file: A string representing the path of the file to be converted.
        output: A string representing the path of output file.
    """
    super().__init__(file, output)

convert_file()

Convert a html file to a PDF file using the pdfkit library.

Source code in backend/api/converter/document_converter/document/pdf_document.py
30
31
32
33
def convert_file(self) -> None:
    """Convert a html file to a PDF file using the pdfkit library."""
    options = {'encoding': 'UTF-8'}
    pdfkit.from_file(self._file, self._output, options=options)