Skip to content

Latest commit

 

History

History

README.md

pdf

Pdf - JavaScript client for pdf The PDF conversion API 'conversion2pdf' converts image, office and PDF files to (searcheable) PDF files. The flow is generally as follows: 1. First create a job using the /conversion2pdf/jobs POST endpoint. You will get back a job response that contains a job with its associated settings. 2. Upload one or more images/files using the /conversion2pdf/jobs/{jobId}/streams/multipart POST endpoint. You can also add stream locations from the storage API . You will get back the update job response that contains a job with its associated settings. Currently you can only merge spreadsheets with spreadsheet, documents with documents and images/pdfs with images/pdfs 3. Start the job from a PUT request to the /conversion2pdf/jobs/{jobid} endpoint, with the Job and Settings JSON as request body. The conversion to PDF will now start. The OCR setting is only applicable to images, since other files will always be searchable. 4. Check the job status from the /conversion2pdf/jobs/{jobid} GET endpoint until the status has changed to DONE or ERROR. Messaging using a websocket will be available as an alternative in a future version 5. Retrieve the PDF file using the /conversion2pdf/jobs/{jobid}/streams/result GET endpoint. This will return the PDF file only when the status is DONE. In other cases it will return the Job Response JSON (with http code 202 instead of 200) Interactive testing: A web based test console is available in the <a href="https://store.sphereon.com\">Sphereon API Store This SDK is automatically generated by the Swagger Codegen project:

  • API version: 1.1
  • Package version: 1.1
  • Build package: io.swagger.codegen.languages.JavascriptClientCodegen For more information, please visit https://sphereon.com

Installation

npm

To publish the library as a npm, please follow the procedure in "Publishing npm packages".

Then install it via:

npm config set registry http://nexus.qa.sphereon.com/repository/sphereon-public-npm/
npm install @sphereon/pdf --save
Local development

To use the library locally without publishing to a remote npm registry, first install the dependencies by changing into the directory containing package.json (and this README). Let's call this JAVASCRIPT_CLIENT_DIR. Then run:

npm install

Next, link it globally in npm with the following, also from JAVASCRIPT_CLIENT_DIR:

npm link

Finally, switch to the directory you want to use your pdf from, and run:

npm link /path/to/<JAVASCRIPT_CLIENT_DIR>

You should now be able to require('pdf') in javascript files from the directory you ran the last command above from.

For browser

The library also works in the browser environment via npm and browserify. After following the above steps with Node.js and installing browserify with npm install -g browserify, perform the following (assuming main.js is your entry file, that's to say your javascript file where you actually use this library):

browserify main.js > bundle.js

Then include bundle.js in the HTML pages.

Webpack Configuration

Using Webpack you may encounter the following error: "Module not found: Error: Cannot resolve module", most certainly you should disable AMD loader. Add/merge the following section to your webpack config:

module: {
  rules: [
    {
      parser: {
        amd: false
      }
    }
  ]
}

Getting Started

Please follow the installation instruction and execute the following JS code:

var Pdf = require('pdf');

var defaultClient = Pdf.ApiClient.instance;

// Configure OAuth2 access token for authorization: oauth2schema
var oauth2schema = defaultClient.authentications['oauth2schema'];
oauth2schema.accessToken = "YOUR ACCESS TOKEN"

var api = new Pdf.Conversion2PDFApi()

var jobid = "jobid_example"; // {String} jobid

var stream = "/path/to/file.txt"; // {File} The (additional) binary image or PDF (file/inputstream) to convert to PDF

var opts = { 
  'fileName': "fileName_example" // {String} Optional input file name.
};

var callback = function(error, data, response) {
  if (error) {
    console.error(error);
  } else {
    console.log('API called successfully. Returned data: ' + data);
  }
};
api.addInputFile(jobid, stream, opts, callback);

Documentation for API Endpoints

All URIs are relative to https://gw.api.cloud.sphereon.com/pdf/1.1

Class Method HTTP request Description
Pdf.Conversion2PDFApi addInputFile POST /conversion2pdf/jobs/{jobid}/streams/multipart Upload a file
Pdf.Conversion2PDFApi addInputStreamLocations POST /conversion2pdf/jobs/{jobid}/streams/location Add Input Stream Location(s)
Pdf.Conversion2PDFApi createJob POST /conversion2pdf/jobs Create a PDF conversion job
Pdf.Conversion2PDFApi deleteJob DELETE /conversion2pdf/jobs/{jobid} Delete a job manually
Pdf.Conversion2PDFApi getJob GET /conversion2pdf/jobs/{jobid} Job definition and state
Pdf.Conversion2PDFApi getJobs GET /conversion2pdf/jobs Get all jobs
Pdf.Conversion2PDFApi getStream GET /conversion2pdf/jobs/{jobid}/streams/result Get the current result stream
Pdf.Conversion2PDFApi submitJob PUT /conversion2pdf/jobs/{jobid} Submit PDF job for processing

Documentation for Models

Documentation for Authorization

oauth2schema

  • Type: OAuth
  • Flow: application
  • Authorization URL:
  • Scopes:
    • global: accessEverything