Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Services/PDF #12

Merged
merged 1 commit into from
Jun 28, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
82 changes: 41 additions & 41 deletions docs/source/Services/Pdf_Type.rst
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,18 @@ margin

**Attributes:**

| **top**: str or int or float
| Top margin, accepts values labeled with units. Defaults to `0`.
| **top**: Optional[str or int or float]
| [Optional] Top margin, accepts values labeled with units. Defaults to `0`.


| **right**: str or int or float
| **right**: Optional[str or int or float]
| Right margin, accepts values labeled with units. Defaults to `0`.

| **bottom**: str or int or float
| Bottom margin, accepts values labeled with units. Defaults to `0`.
| **bottom**: Optional[str or int or float]
| [Optional] Bottom margin, accepts values labeled with units. Defaults to `0`.

| **left**: str or int or float
| Left margin, accepts values labeled with units. Defaults to `0`.
| **left**: Optional[str or int or float]
| [Optional] Left margin, accepts values labeled with units. Defaults to `0`.


.. _options:
Expand All @@ -29,47 +29,47 @@ options

**Attributes:**

| **displayHeaderFooter**: bool
| Display header and footer. Defaults to `false`.
| **displayHeaderFooter**: Optional[bool]
| [Optional] Display header and footer. Defaults to `false`.

| **footerTemplate**: str
| HTML template for the print footer. Should use the same format as the `headerTemplate`.
| **footerTemplate**: Optional[str]
| [Optional] HTML template for the print footer. Should use the same format as the `headerTemplate`.

| **format**: str
| Paper format. If set, takes priority over `width` or `height` options. Defaults to 'Letter'.
| **format**: Optional[str]
| [Optional] Paper format. If set, takes priority over `width` or `height` options. Defaults to 'Letter'.

| **headerTemplate**: str
| HTML template for the print header. Should be valid HTML markup with following classes used to inject printing values
| **headerTemplate**: Optional[str]
| [Optional] HTML template for the print header. Should be valid HTML markup with following classes used to inject printing values
| into them:
| - `'date'` formatted print date
| - `'title'` document title
| - `'url'` document location
| - `'pageNumber'` current page number
| - `'totalPages'` total pages in the document

| **height**: str or int or float
| Paper height, accepts values labeled with units.
| **height**: Optional[str or int or float]
| [Optional] Paper height, accepts values labeled with units.

| **landscape**: bool
| Paper orientation. Defaults to `false`.
| **landscape**: Optional[bool]
| [Optional] Paper orientation. Defaults to `false`.

| **margin**: :ref:`margin`
| Paper margins, defaults to none.
| **margin**: Optional[:ref:`margin`]
| [Optional] Paper margins, defaults to none.

| **pageRanges**: str
| Paper ranges to print, e.g., '1-5, 8, 11-13'. Defaults to the empty string, which means print all pages.
| **pageRanges**: Optional[str]
| [Optional] Paper ranges to print, e.g., '1-5, 8, 11-13'. Defaults to the empty string, which means print all pages.

| **preferCSSPageSize**: bool
| Give any CSS `@page` size declared in the page priority over what is declared in `width` and `height` or `format`options. Defaults to `false`, which will scale the content to fit the paper size.
| **preferCSSPageSize**: Optional[bool]
| [Optional] Give any CSS `@page` size declared in the page priority over what is declared in `width` and `height` or `format`options. Defaults to `false`, which will scale the content to fit the paper size.

| **printBackground**: bool
| Print background graphics. Defaults to `false`.
| **printBackground**: Optional[bool]
| [Optional] Print background graphics. Defaults to `false`.

| **scale**: int or float
| Scale of the webpage rendering. Defaults to `1`. Scale amount must be between 0.1 and 2.
| **scale**: Optional[int or float]
| [Optional] Scale of the webpage rendering. Defaults to `1`. Scale amount must be between 0.1 and 2.

| **width**: str or int or float
| Paper width, accepts values labeled with units.
| **width**: Optional[str or int or float]
| [Optional] Paper width, accepts values labeled with units.


.. _PDFParams:
Expand All @@ -79,18 +79,18 @@ PDFParams

**Attributes:**

| **html**: str
| HTML as string
| **html**: Optional[str]
| [Optional] HTML as string

| **base64**: str
| HTML on base64 format
| **base64**: Optional[str]
| [Optional] HTML on base64 format

| **fileName**: str
| File name of pdf. Without filename, it will generate base64 response With filename it will generate pdf binary
| **fileName**: Optional[str]
| [Optional] File name of pdf. Without filename, it will generate base64 response With filename it will generate pdf binary

| **url**: str
| Generate pdf from URL
| **url**: Optional[str]
| [Optional] Generate pdf from URL

| **options**: :ref:`options`
| PDF Custom Options
| **options**: Optional[:ref:`options`]
| [Optional] PDF Custom Options

51 changes: 28 additions & 23 deletions src/tagoio_sdk/modules/Services/PDF.py
Original file line number Diff line number Diff line change
@@ -1,27 +1,32 @@
from typing import TypedDict, Union
from typing import Optional, TypedDict, Union

import requests

from tagoio_sdk.common.tagoio_module import TagoIOModule


class PDFResult(TypedDict):
status: bool
result: str


class margin(TypedDict):
top: Union[str, int, float]
top: Optional[Union[str, int, float]]
"""
Top margin, accepts values labeled with units. Defaults to `0`.
"""

right: Union[str, int, float]
right: Optional[Union[str, int, float]]
"""
Right margin, accepts values labeled with units. Defaults to `0`.
"""

bottom: Union[str, int, float]
bottom: Optional[Union[str, int, float]]
"""
Bottom margin, accepts values labeled with units. Defaults to `0`.
"""

left: Union[str, int, float]
left: Optional[Union[str, int, float]]
"""
Left margin, accepts values labeled with units. Defaults to `0`.
"""
Expand All @@ -32,19 +37,19 @@ class options(TypedDict):
PDF Custom Options
"""

displayHeaderFooter: bool
displayHeaderFooter: Optional[bool]
"""
Display header and footer. Defaults to `false`.
"""
footerTemplate: str
footerTemplate: Optional[str]
"""
HTML template for the print footer. Should use the same format as the `headerTemplate`.
"""
format: str
format: Optional[str]
"""
Paper format. If set, takes priority over `width` or `height` options. Defaults to 'Letter'.
"""
headerTemplate: str
headerTemplate: Optional[str]
"""
HTML template for the print header. Should be valid HTML markup with following classes used
to inject printing values
Expand All @@ -56,70 +61,70 @@ class options(TypedDict):
- `'pageNumber'` current page number
- `'totalPages'` total pages in the document
"""
height: Union[str, int, float]
height: Optional[Union[str, int, float]]
"""
Paper height, accepts values labeled with units.
"""
landscape: bool
landscape: Optional[bool]
"""
Paper orientation. Defaults to `false`.
"""
margin: margin
margin: Optional[margin]
"""
Paper margins, defaults to none.
"""
pageRanges: str
pageRanges: Optional[str]
"""
Paper ranges to print, e.g., '1-5, 8, 11-13'. Defaults to the empty string, which means print
all pages.
"""
preferCSSPageSize: bool
preferCSSPageSize: Optional[bool]
"""
Give any CSS `@page` size declared in the page priority over what is
declared in `width` and `height` or `format`options.
Defaults to `false`, which will scale the content to fit the paper size.
"""
printBackground: bool
printBackground: Optional[bool]
"""
Print background graphics. Defaults to `false`.
"""
scale: Union[int, float]
scale: Optional[Union[int, float]]
"""
Scale of the webpage rendering. Defaults to `1`. Scale amount must be between 0.1 and 2.
"""
width: Union[str, int, float]
width: Optional[Union[str, int, float]]
"""
Paper width, accepts values labeled with units.
"""


class PDFParams(TypedDict):
html: str
html: Optional[str]
"""
HTML as string
"""
base64: str
base64: Optional[str]
"""
HTML on base64 format
"""
fileName: str
fileName: Optional[str]
"""
File name of pdf
Without filename, it will generate base64 response
With filename it will generate pdf binary
"""
url: str
url: Optional[str]
"""
Generate pdf from URL
"""
options: options
options: Optional[options]
"""
PDF Custom Options
"""


class PDFService(TagoIOModule):
def generate(self, params: PDFParams) -> str:
def generate(self, params: PDFParams) -> PDFResult:
"""
Generate a PDF from html, url or base64
"""
Expand Down