Giter Site home page Giter Site logo

api2pdf / api2pdf.node Goto Github PK

View Code? Open in Web Editor NEW
41.0 4.0 6.0 31 KB

Node 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

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

api2pdf.node's People

Contributors

apexdodge avatar mattpmoreno avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  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  avatar

api2pdf.node's Issues

Support for object params

Per Issue #1, I think it would make sense to modify methods to accept object parameters, or roll everything but the first parameter into 'options'.

So that this:

a2pClient.headlessChromeFromUrl('https://www.github.com', true, 'test.pdf', options)
    .then(function(result) {
        console.log(result); //successful api call
    }, function(rejected) {
        console.log(rejected); //an error occurred
    }
);

Becomes this:

a2pClient.headlessChromeFromUrl('https://www.github.com', options)
    .then(function(result) {
        console.log(result); //successful api call
    }, function(rejected) {
        console.log(rejected); //an error occurred
    }
);

or:

a2pClient.headlessChromeFromUrl('https://www.github.com', { inline: true, filename: "test.pdf", options: options })
    .then(function(result) {
        console.log(result); //successful api call
    }, function(rejected) {
        console.log(rejected); //an error occurred
    }
);

Request deprecation (dependency)

Hi,

Sadly, the dependency that you use to make requests to the api2pdf service, "[email protected]", is deprecated. We get warnings when installing your package, this will become a deal breaker sooner or later as it is no longer maintained.

You can see more details here:
request/request#3142

Any plans to replace it (or rewrite the code really) soon?

Thank you.

Using S3 for custom storage

I tried to convert html to pdf by enabling the custom storage to S3, but I got this error:

 SyntaxError: Unexpected token F in JSON at position 9
     at JSON.parse (<anonymous>)
     at IncomingMessage.<anonymous> (/usr/src/app/node_modules/api2pdf/index.js:205:25)
     at IncomingMessage.emit (node:events:525:35)
     at IncomingMessage.emit (node:domain:489:12)
     at endReadableNT (node:internal/streams/readable:1359:12)
     at processTicksAndRejections (node:internal/process/task_queues:82:21)

Any idea to solve this one?

How to pass the option value for headless chrome

Hi!

I am trying to pass the option value by executing this script:

var Api2Pdf = require('api2pdf');   
var a2pClient = new Api2Pdf('key');

var options =   {
    url: "link",
    inlinePdf: true,
    options: {
      landscape: true,
      printBackground: false,
    }
  }
a2pClient.headlessChromeFromUrl('link', options=options)
    .then(function(result) {
        console.log(result); //successful api call
    }, function(rejected) {
        console.log(rejected); //an error occurred
    }
);


But I get the following error:

{ success: false,
  error: 'Invalid JSON. Check your payload and validate your requests by following this tutorial: https://www.api2pdf.com/how-to-use-api2pdfs-swaggerhub-to-get-the-most-out-of-our-support-team/' }

Merge PDF example returns a link to XML garbage

Using the example you guys provided, the following is logged to the console...

{ pdf:
   'https://media.api2pdf.com/18e63c51-da7b-4ad7-87e8-b89fe229d61f?X-Amz-Expires=86400&response-content-disposition=attachment%3B%20filename%3D18e63c51-da7b-4ad7-87e8-b89fe229d61f.pdf&response-content-type=application%2Fpdf&X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=AKIAJSHKEFTKBQX2AUYQ/20191015/us-east-1/s3/aws4_request&X-Amz-Date=20191015T034611Z&X-Amz-SignedHeaders=host&X-Amz-Signature=df9c3a0a232e4f6cb351f7de686d805ea049fa76097d134bdbc746282683a5bb',
  mbIn: 0.015537261962890625,
  mbOut: 0.014382362365722656,
  cost: 0.00014894162432861329,
  success: true,
  error: null,
  responseId: '32b1ef72-f2bb-4fdc-b1b9-c5917049185b' }

The response says the PDF merge was successful, but if you click the link that is provided to access your new PDF, you get some XML garbage...

<Error>
<Code>SignatureDoesNotMatch</Code>
<Message>
The request signature we calculated does not match the signature you provided. Check your key and signing method.
</Message>
<AWSAccessKeyId>AKIAJSHKEFTKBQX2AUYQ</AWSAccessKeyId>
<StringToSign>
AWS4-HMAC-SHA256 20191015T032755Z 20191015/us-east-1/s3/aws4_request e04949d0843f9ff272497e8881f9a3afc3bb09afbcd1ed94dfdc7664cecf57bc
</StringToSign>
<SignatureProvided>
7781860c6ad7dd1c6fabad4a4444fd96864338da70977b107f4b5d65055974e9',
</SignatureProvided>
<StringToSignBytes>
41 57 53 34 2d 48 4d 41 43 2d 53 48 41 32 35 36 0a 32 30 31 39 31 30 31 35 54 30 33 32 37 35 35 5a 0a 32 30 31 39 31 30 31 35 2f 75 73 2d 65 61 73 74 2d 31 2f 73 33 2f 61 77 73 34 5f 72 65 71 75 65 73 74 0a 65 30 34 39 34 39 64 30 38 34 33 66 39 66 66 32 37 32 34 39 37 65 38 38 38 31 66 39 61 33 61 66 63 33 62 62 30 39 61 66 62 63 64 31 65 64 39 34 64 66 64 63 37 36 36 34 63 65 63 66 35 37 62 63
</StringToSignBytes>
<CanonicalRequest>
GET /2bb261a3-7bc5-4267-8e0b-ba323083aefd X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=AKIAJSHKEFTKBQX2AUYQ%2F20191015%2Fus-east-1%2Fs3%2Faws4_request&X-Amz-Date=20191015T032755Z&X-Amz-Expires=86400&X-Amz-SignedHeaders=host&response-content-disposition=inline%3B%20filename%3Dtest.pdf&response-content-type=application%2Fpdf host:media.api2pdf.com host UNSIGNED-PAYLOAD
</CanonicalRequest>
<CanonicalRequestBytes>
47 45 54 0a 2f 32 62 62 32 36 31 61 33 2d 37 62 63 35 2d 34 32 36 37 2d 38 65 30 62 2d 62 61 33 32 33 30 38 33 61 65 66 64 0a 58 2d 41 6d 7a 2d 41 6c 67 6f 72 69 74 68 6d 3d 41 57 53 34 2d 48 4d 41 43 2d 53 48 41 32 35 36 26 58 2d 41 6d 7a 2d 43 72 65 64 65 6e 74 69 61 6c 3d 41 4b 49 41 4a 53 48 4b 45 46 54 4b 42 51 58 32 41 55 59 51 25 32 46 32 30 31 39 31 30 31 35 25 32 46 75 73 2d 65 61 73 74 2d 31 25 32 46 73 33 25 32 46 61 77 73 34 5f 72 65 71 75 65 73 74 26 58 2d 41 6d 7a 2d 44 61 74 65 3d 32 30 31 39 31 30 31 35 54 30 33 32 37 35 35 5a 26 58 2d 41 6d 7a 2d 45 78 70 69 72 65 73 3d 38 36 34 30 30 26 58 2d 41 6d 7a 2d 53 69 67 6e 65 64 48 65 61 64 65 72 73 3d 68 6f 73 74 26 72 65 73 70 6f 6e 73 65 2d 63 6f 6e 74 65 6e 74 2d 64 69 73 70 6f 73 69 74 69 6f 6e 3d 69 6e 6c 69 6e 65 25 33 42 25 32 30 66 69 6c 65 6e 61 6d 65 25 33 44 74 65 73 74 2e 70 64 66 26 72 65 73 70 6f 6e 73 65 2d 63 6f 6e 74 65 6e 74 2d 74 79 70 65 3d 61 70 70 6c 69 63 61 74 69 6f 6e 25 32 46 70 64 66 0a 68 6f 73 74 3a 6d 65 64 69 61 2e 61 70 69 32 70 64 66 2e 63 6f 6d 0a 0a 68 6f 73 74 0a 55 4e 53 49 47 4e 45 44 2d 50 41 59 4c 4f 41 44
</CanonicalRequestBytes>
<RequestId>013E6BEC2FF0292D</RequestId>
<HostId>
LOhErUFwX/QsRpIurAmtaXtBzUDCA5H+ID3uMe2WuP5tR4OfneUyDnl0tR9svASJRA8yROBhZQY=
</HostId>
</Error>

headerHtml option not working

For wkhtmltopdf, I added a url 'https://geovea.com/pdf_header.html' as headerHtml option.
But it's not working. No any error, any other things are ok. and only the header is empty for each page. btw, the footerHtml is working.
any idea?


    const a2pClient = new Api2Pdf(process.env.REACT_APP_PDF_API);
    const { FileUrl } = await a2pClient.wkHtmlToPdf(
      $html.html(),
      {
        inline: false,
        filename: name + ".pdf",
        options: {
          headerHtml: 'https://geovea.com/pdf_header.html',
          marginBottom: 7,
          marginTop: 8,
          marginLeft: 7,
          marginRight: 7,
        }
      }
    );

How to use in TypeScript?

The advanced examples you give use Javascript named parameters like this:

var options = { orientation: 'landscape', pageSize: 'A4'};
a2pClient.wkhtmltopdfFromUrl('https://www.github.com', inline = true, filename = 'test.pdf', options = options).then(function(result) {
    console.log(result);
});

I'm trying to use this package in a TypeScript context where these types of parameters are not recognized. How should I use this library in a TypeScript context to obtain the same result?

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.