- Constant
- DestinationType
- EncodingType
- OpenType
- API
- open(success, fail, options)
- close(success, fail)
- getPage(success, fail, options)
- getPDFInfo(success, fail)
- getPageInfo(success, fail, pageNumber)
- changePreference(preference)
- Quick Example
- Example 1
{
DATA_BIN, // Return ArrayBuffer
DATA_URL, // Return base64 encoded string
FILE_URI // Return file path in native way
}
// example
PDFRenderer.DestinationType.FILE_URI
{
JPEG, // Return JPEG encoded image
PNG // Return PNG encoded image
}
// example
PDFRenderer.EncodingType.JPEG
{
PATH, // PDF path
BUFFER // PDF arraybuffer
}
// example
PDFRenderer.OpenType.PATH
- The example openFileObj's openType is default setting
- you don't nedd to pass openType and password except you want oepn from array buffer or password protected PDF.
- Every thing should be done after PDF opened.
Parameter | Type | Default | Description |
---|---|---|---|
success |
Function |
success callbcak | |
fail |
Function |
fail callback | |
options |
Object |
{} |
An object describing relevant specific options. |
Attribute | Type | Default | Description |
---|---|---|---|
content |
string |
Path or ArrayBuffer | |
openType |
PDFRenderer.OpenType |
OpenType.PATH |
Open from Path or ArrayBuffer |
password |
string |
PDF password |
Parameter | Type | Default | Description |
---|---|---|---|
data.numberOfPage |
int |
PDF page count | |
data.path |
string |
PDF path | |
data.name |
string |
PDF name |
var openFileObj = {
content: 'PDFRendererTest.pdf',
openType: PDFRenderer.OpenType.PATH,
password: '123'
};
PDFRenderer.open(function successCallBack(data) {
// data.numberOfPage
// data.path
// data.name
// do your stuff, start to getPage or something
}, failCallBack, openFileObj);
- close PDF when you finish.
Parameter | Type | Default | Description |
---|---|---|---|
success |
Function |
success callbcak | |
fail |
Function |
fail callback |
PDFRenderer.close(successCallback, failCallback);
- get image from PDF
Parameter | Type | Default | Description |
---|---|---|---|
success |
Function |
success callbcak | |
fail |
Function |
fail callback | |
options |
Object |
{} |
An object describing relevant specific options. |
PatchX, PatchY, PatchWidth, PatchHeight means you want to get a cut block from image.
Attribute | Type | Default | Description |
---|---|---|---|
page |
int |
which page image | |
width |
int |
page width | Image width |
height |
int |
page height | Image height |
patchX |
int |
0 | Patch x from image |
patchY |
int |
0 | Patch y from image |
patchWidth |
int |
width | Patch width |
patchHeight |
int |
height | Patch height |
quality |
int |
100 | Image quality |
encodingType |
PDFRenderer.EncondingType |
EncondingType.JPEG | |
destinationType |
PDFRenderer.DestinationType |
DestinationType.BIN | PDF type |
destinationPath |
string |
PDF path |
Parameter | Type | Default | Description |
---|---|---|---|
data |
string |
File path or base64 or arraybuffer |
var options = {
page: 1,
width: 800,
height: 600,
patchX: 0,
patchY: 0,
patchWidth: 800,
patchHeight: 600,
quality: 100,
encodingType: EncodingType.JPEG,
destinationType: DestinationType.FILE_URI,
destinationPath: '/PDF/example'
};
PDFRenderer.getPage(function successCallback(data) {
// data
}, failCallback, options);
- The PDF info
Parameter | Type | Default | Description |
---|---|---|---|
data.numberOfPage |
int |
PDF page count | |
data.path |
string |
PDF path | |
data.name |
string |
PDF name |
PDFRenderer.getPDFInfo(function successCallback(data) {
// data.numberOfPage
// data.path
// data.name
}, failCallback);
- get page info by giving page number
Parameter | Type | Default | Description |
---|---|---|---|
data.numberOfPage |
int |
PDF page count | |
data.width |
int |
Page width | |
data.height |
int |
Page height |
var pageNumber = 1;
PDFRenderer.getPageInfo(function successCallback(data) {
// data.numberOfPage
// data.width
// data.height
}, failCallback, pageNumber);
- The example preference is default setting, you can change it youself.
Parameter | Type | Default | Description |
---|---|---|---|
preference |
Object |
{} |
success callbcak |
Attribute | Type | Default | Description |
---|---|---|---|
openType |
PDFRenderer.OpenType |
OpenType.PATH |
Open from Path or ArrayBuffer |
quality |
int |
100 |
Image quality |
encodingType |
PDFRenderer.EncodingType |
EncodingType.JPEG |
Image format |
destinationType |
PDFRenderer.DestinationType |
DestinationType.DATA_BIN |
PDF type |
destinationPath |
string |
PDF path. |
var preference = {
openType: PDFRenderer.OpenType.PATH,
quality: 100,
encodingType: PDFRenderer.EncodingType.JPEG,
destinationType: PDFRenderer.DestinationType.DATA_BIN,
destinationPath: ''
};
PDFRenderer.changePreference(preference);
function fail(e) {
console.log(e);
};
PDFRenderer.open(function(pdf) {
console.log('PDF Info: ', pdf.name, pdf.path);
var i = pdf.numberOfPage,
success = function(data) {
console.log('Image output path', data);
};
while (i-- > 0) {
PDFRenderer.getPage(success, fail, {
page: i,
destinationType: PDFRenderer.DestinationType.FILE_URI
});
}
}, fail, {
content: 'PDFRendererTest.pdf'
});