How to HTML to PDF in JavaScript using Cloud API (low level)

  • Home
  • /
  • Articles
  • /
  • How to HTML to PDF in JavaScript using Cloud API (low level)

Use the sample source code below to convert HTML to PDF in JavaScript using ByteScout Cloud API (low level).

It is also possible to convert PDF to HTML in JavaScript.

POST endpoint:

https://bytescout.io/v1/pdf/convert/from/html

Code Sample:

var Bytescoutio = require('bytescoutio');
var defaultClient = Bytescoutio.ApiClient.instance;

// Configure API key authorization: api_key
var api_key = defaultClient.authentications['api_key'];
api_key.apiKey = "YOUR API KEY"
// Uncomment the following line to set a prefix for the API key, e.g. "Token" (defaults to null)
//api_key.apiKeyPrefix['x-api-key'] = "Token"

var api = new Bytescoutio.DefaultApi()

var text = ; // {Text} HTML data to convert to PDF.

var opts = { 
  'name': name_example // {String} File name for the generated result.
};

var callback = function(error, data, response) {
  if (error) {
    console.error(error);
  } else {
    console.log('API called successfully. Returned data: ' + data);
  }
};
api.pdfConvertFromHtmlPost(text, opts, callback);
prev
next