Giter Site home page Giter Site logo

api2pdf / api2pdf.python Goto Github PK

View Code? Open in Web Editor NEW
21.0 3.0 2.0 39 KB

Python client library for the Api2Pdf.com REST API - Convert HTML to PDF, URL to PDF, Office Docs to PDF, Merge PDFs, HTML to Image, URL to Image, HTML to Docx, HTML to Xlsx, PDF to HTML, Thumbnail preview of office files

Home Page: https://www.api2pdf.com

License: MIT License

Python 100.00%
pdf pdf-generation html-to-pdf url-to-pdf merge-pdf word-to-pdf wkhtmltopdf headless-chrome libreoffice aws-lambda

api2pdf.python's People

Contributors

apexdodge avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

api2pdf.python's Issues

Internal server error

On the heroku log it shows TypeError: The view function did not return a valid response. The return type must be a string, dict, tuple, Response instance, or WSGI callable, but it was a Api2PdfResponse.

PDF Signature Not Found

Hi, been trying to merge some links into one pdf and I'm using the python sdk.

def convert_and_merge_pdf(links):
    print("About to convert")
    a2p_client = Api2Pdf('xxxx-xxxxx-xxxxxx')
    options = {
        'pageSize': 'A4'
    }
    merge_result = a2p_client.merge(links)
    print(merge_result)
    return merge_result

this functions take a list of url for pdf conversion and merging but i get this error

- Headers: {'Authorization': 'xxx-xxx-xxx'}
- Endpoint: https://v2018.api2pdf.com/merge
- Payload:
{'urls': ['http://bloom.pagekite.me/payroll/view_slip/953a75aa-e61f-4c43-a6f4-2edce97a2b56', 'http://bloom.pagekite.me/payroll/view_slip/b310bb2d-241c-4ec5-a15b-bd012b03906b', 'http://bloom.pagekite.me/payroll/view_slip/e46d8c2b-8cea-4106-b38e-0f
b7eb7cf11c'], 'inlinePdf': False}
---- API2PDF RESPONSE ----
{'mbIn': 0.0, 'mbOut': 0.0, 'cost': 0.000394077, 'success': False, 'error': 'Unexpected error: PDF header signature not found., (StackTrace:    at iTextSharp.text.pdf.PrTokeniser.CheckPdfHeader()\n   at iTextSharp.text.pdf.PdfReader.ReadPdf()\n
 at InvokePdfMerge.PdfMerger.Merge(IReadOnlyCollection`1 pdfUrls, String fileName, Boolean inlinePdf, Double& inputMb, Double& outputMb) in C:\\git\\Api2PdfLambda\\Api2PdfLambda\\InvokePdfMerge\\PdfMerger.cs:line 41\n   at InvokePdfMerge.PdfMerge
Function.Handler(MergeRequest input) in C:\\git\\Api2PdfLambda\\Api2PdfLambda\\InvokePdfMerge\\PdfMergeFunction.cs:line 24)', 'responseId': 'ccdfe6ca-1508-4993-9a34-8b817980dae9'}

Thanks for your help

Issue when trying to download a file (typo)

When I generate a PDF or image using:

image_api_response = a2p_client.Chrome.html_to_image(html, file_name=image_filename)
pdf_api_response = a2p_client.Chrome.html_to_pdf(html,file_name=pdf_filename,)

To download the file I try to use image_api_response.download_pdf() or pdf_api_response.download_pdf() I get the following error:

File "/usr/local/lib/python3.8/site-packages/api2pdf/api2pdf.py", line 158, in download_pdf
    if self.result['success']:

The immediate fix:

if self.result['success']:

should reference Success not success

I also recommend a change in this method's name since it isn't only used to download images. Perhaps download_file.

Host a Lambda Layer

I think it could be helpful to provide a "Layer version ARN" for people that are using lambda.

Makes it easy to attach to a project without having to maintain a lambda layer.

Header and footer not displayed in generated pdf

Hi, I'm currently working on implementing a header and footer in my document, but when calling the HeadlessChrome api with the following code, I get back a PDF with no header or footer.

        margin_x = 0.75
        chrome_options = {
            "marginLeft": margin_x,
            "marginRight": margin_x,
            "marginTop": margin_x,
            "marginBottom": margin_x,
            "displayHeaderFooter": True,
            "headerTemplate": "<span>TestHeader</span>",
            "footerTemplate": "<span>TestFooter</span>",
        }
        response = client.HeadlessChrome.convert_from_html(content, **chrome_options)

I've gone over the docs and it looks like everything is correct here. Am I missing something here?

Can not import Api2Pdf

Hello ๐Ÿ‘‹

I'm trying to run the doc example but I keep getting an import error when I try to run the script ImportError: cannot import name 'Api2Pdf' from 'api2pdf'


here's the script I'm trying to run

from api2pdf import Api2Pdf

a2p_client = Api2Pdf('my_api_key')

api_response = a2p_client.HeadlessChrome.convert_from_html('<p>Hello, World</p>')
print(api_response.result)

version: pip freeze gives me api2pdf==0.0.11

thaaanks a lot for your help ๐Ÿ˜

Spaces in a2p_client.HeadlessChrome.convert_from_html breaks filename

When calling:

from api2pdf import Api2Pdf
a2p_client = Api2Pdf('token')
html = "<html code>"
res = a2p_client.HeadlessChrome.convert_from_html(html, file_name='Devis FOO.pdf')

The returned PDF carries as name all characters prior to the first space in file_name. Here, it is:

Devis

without the end of the file_name nor the PDF file extension.

Is this a known bug ?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.