2.0.0 • Published 3 years ago
@youngmayor/pidifier.js v2.0.0
PidifierJS
The official Node Package for pidifier v2
Table of Contents
Features
- Interact with the Pidifier API easily
- With a unified UI for pidifying a page, screenshotting page - full and preview (800px x 600px)
Browser Support
Latest ✔ | Latest ✔ | Latest ✔ | Latest ✔ | Latest ✔ | 11 ✔ |
Installing
- Using npm:
$ npm install @youngmayor/pidifier.js
Using jsDelivr CDN:
<script src="https://cdn.jsdelivr.net/npm/@youngmayor/pidifier.js@latest"></script>
Using unpkg CDN:
<script src="https://unpkg.com/@youngmayor/pidifier.js"></script>
Importing
In a node based application, you can import the package using commonJS as shown below
const PidifyJS = require('@youngmayor/pidifier.js'); // or import PidifyJS from '@youngmayor/pidifier.js';
It can also be linked to using any of the below CDNs
<script src="https://cdn.jsdelivr.net/npm/@youngmayor/pidifier.js@latest" async></script> <!-- or --> <script src="https://unpkg.com/@youngmayor/pidifier.js" async></script>
<!-- the package can now be accessed via window.PidifyJS -->
```
Usage
PidifyJS can be easily used to convert a web page to PDF as shown below.
const url = 'https://example.com'
// pidify a page
const demoSitePDF = await PidifyJS.pidify(url);
// screenshot a page
const demoSiteScreenshot = await PidifyJS.screenshot(url);
// preview-screenshot a page
const demoSitePreview = await PidifyJS.preview(url);
// check if pidification was successful and perform actions
// NOTE! All of the below methods are available to every method of pidification
// But demoSitePDF was used
if (demoSitePDF->success) {
// ... Pidification was successful
const demoSiteBase64 = demoSitePDF->getBase64(); // get the base64 encoding of the PDF
let demoSiteBlob = demoSitePDF->getBlob(); // get the Blob object of the PDF
const demoSiteDataURL = demoSitePDF->getDataURL(); // Get the Data URL of the PDF
demoSitePDF->download(filename); // download the PDF as `filename`
} else {
// ... Pidification failed
const demoSiteErrorMessage = demoSitePDF->getErrorMessage(); // get the error message
const demoSiteErrorStatusObject = demoSitePDF->getErrorStatus(); // get the error status message. it has two properties { status, statusText }
}