pdf2html-jk-temporary
Version:
PDF to HTML or Text conversion using Apache Tika. Also generate PDF thumbnail using Apache PDFBox.
115 lines (95 loc) • 2.86 kB
Markdown
[](https://www.npmjs.com/package/pdf2html)
[](https://www.npmjs.org/package/pdf2html)
[](https://travis-ci.org/shebinleo/pdf2html)
[](https://www.npmjs.org/package/pdf2html)
pdf2html helps to convert PDF file to HTML or Text using [Apache Tika](https://tika.apache.org/). This module also helps to generate thumbnail image for PDF file using [Apache PDFBox](https://pdfbox.apache.org/).
via yarn:
```
yarn add pdf2html
```
via npm:
```
npm install --save pdf2html
```
**Java runtime environment (JRE) is required to run this module.**
### Usage
```javascript
const pdf2html = require('pdf2html')
pdf2html.html('sample.pdf', (err, html) => {
if (err) {
console.error('Conversion error: ' + err)
} else {
console.log(html)
}
})
```
```javascript
pdf2html.text('sample.pdf', (err, text) => {
if (err) {
console.error('Conversion error: ' + err)
} else {
console.log(text)
}
})
```
```javascript
pdf2html.pages('sample.pdf', (err, htmlPages) => {
if (err) {
console.error('Conversion error: ' + err)
} else {
console.log(htmlPages)
}
})
```
```javascript
const options = { text: true }
pdf2html.pages('sample.pdf', options, (err, textPages) => {
if (err) {
console.error('Conversion error: ' + err)
} else {
console.log(textPages)
}
})
```
```javascript
pdf2html.meta('sample.pdf', (err, meta) => {
if (err) {
console.error('Conversion error: ' + err)
} else {
console.log(meta)
}
})
```
```javascript
pdf2html.thumbnail('sample.pdf', (err, thumbnailPath) => {
if (err) {
console.error('Conversion error: ' + err)
} else {
console.log(thumbnailPath)
}
})
```
```javascript
const options = { page: 1, imageType: 'png', width: 160, height: 226 }
pdf2html.thumbnail('sample.pdf', options, (err, thumbnailPath) => {
if (err) {
console.error('Conversion error: ' + err)
} else {
console.log(thumbnailPath)
}
})
```
Sometimes downloading the dependencies might be too slow or unable to download in a HTTP proxy environment. Follow the step below to skip the dependency downloads.
```bash
cd node_modules/pdf2html/vendor
wget https://dlcdn.apache.org/pdfbox/2.0.26/pdfbox-app-2.0.26.jar
wget https://dlcdn.apache.org/tika/2.3.0/tika-app-2.3.0.jar
```