Top Related Projects
Quick Overview
The pdfh5
project is a Python library that provides a simple and efficient way to extract text and images from PDF files and convert them into HTML5 format. It is designed to be a lightweight and easy-to-use tool for developers who need to work with PDF data in their applications.
Pros
- Cross-platform compatibility: The library is written in Python, which makes it compatible with a wide range of operating systems, including Windows, macOS, and Linux.
- Efficient PDF processing: The library uses a fast and reliable PDF parsing library, which allows it to process PDF files quickly and accurately.
- Customizable output: The library allows users to customize the output HTML5 format, including the ability to specify the layout, styling, and metadata.
- Easy integration: The library is easy to integrate into existing Python-based projects, with a simple and intuitive API.
Cons
- Limited PDF feature support: The library may not support all the features and functionality of PDF files, such as complex layouts, annotations, or interactive elements.
- Dependency on external libraries: The library relies on several external libraries, which may increase the complexity of the installation and setup process.
- Potential performance issues: Depending on the size and complexity of the PDF files being processed, the library may experience performance issues, especially when processing large or complex documents.
- Limited documentation: The project's documentation may be limited, which could make it more difficult for new users to get started with the library.
Code Examples
Here are a few examples of how to use the pdfh5
library:
from pdfh5 import PDF2HTML
# Convert a PDF file to HTML5
pdf = PDF2HTML('input.pdf')
html = pdf.convert()
with open('output.html', 'w') as f:
f.write(html)
This code converts the input.pdf
file to an HTML5 format and saves the result to the output.html
file.
from pdfh5 import PDF2HTML
# Extract text from a PDF file
pdf = PDF2HTML('input.pdf')
text = pdf.get_text()
print(text)
This code extracts the text content from the input.pdf
file and prints it to the console.
from pdfh5 import PDF2HTML
# Extract images from a PDF file
pdf = PDF2HTML('input.pdf')
images = pdf.get_images()
for i, image in enumerate(images):
image.save(f'image_{i}.png')
This code extracts all the images from the input.pdf
file and saves them as individual PNG files.
Getting Started
To get started with the pdfh5
library, follow these steps:
- Install the library using pip:
pip install pdfh5
- Import the
PDF2HTML
class from thepdfh5
module:
from pdfh5 import PDF2HTML
- Create a
PDF2HTML
object and use its methods to process a PDF file:
# Convert a PDF file to HTML5
pdf = PDF2HTML('input.pdf')
html = pdf.convert()
with open('output.html', 'w') as f:
f.write(html)
- Customize the output by passing additional arguments to the
convert()
method:
# Customize the output HTML5
pdf = PDF2HTML('input.pdf')
html = pdf.convert(layout='grid', metadata={'title': 'My PDF Document'})
with open('output.html', 'w') as f:
f.write(html)
- Explore the other methods provided by the
PDF2HTML
class, such asget_text()
andget_images()
, to extract specific content from the PDF file.
For more detailed information and advanced usage, please refer to the project's documentation.
Competitor Comparisons
PDF Reader in JavaScript
Pros of pdf.js
- More comprehensive and feature-rich PDF rendering solution
- Widely adopted and battle-tested in production environments
- Extensive documentation and community support
Cons of pdf.js
- Larger file size and potentially higher resource usage
- Steeper learning curve for implementation and customization
- May be overkill for simple PDF viewing needs
Code Comparison
pdf.js:
pdfjsLib.getDocument('path/to/document.pdf').promise.then(function(pdf) {
pdf.getPage(1).then(function(page) {
var scale = 1.5;
var viewport = page.getViewport({ scale: scale });
// Render page
});
});
pdfh5:
new Pdfh5('#demo', {
pdfurl: 'path/to/document.pdf',
zoomEnable: true,
scrollEnable: true
});
Summary
pdf.js offers a more robust and feature-complete solution for PDF rendering, with extensive community support and documentation. However, it may be more complex to implement and have a larger footprint. pdfh5 provides a simpler, more lightweight option for basic PDF viewing needs, but with fewer advanced features and less widespread adoption.
Client/server side PDF printing in pure JavaScript
Pros of pdfmake
- Client-side PDF generation in pure JavaScript, allowing for dynamic PDF creation in browsers
- Extensive documentation and examples, making it easier for developers to get started
- Supports complex layouts, tables, and styling options for creating professional-looking documents
Cons of pdfmake
- Larger file size compared to pdfh5, which may impact load times for web applications
- Steeper learning curve due to its more comprehensive feature set
- Limited support for existing PDF manipulation (primarily focused on PDF creation)
Code Comparison
pdfmake:
var docDefinition = {
content: [
'Hello world',
{ text: 'Styled text', style: 'header' },
{ table: { body: [['Column 1', 'Column 2'], ['Value 1', 'Value 2']] } }
]
};
pdfMake.createPdf(docDefinition).download();
pdfh5:
var pdfh5 = new Pdfh5('#demo', {
pdfurl: './path/to/your.pdf'
});
pdfh5.renderPdf();
The code comparison shows that pdfmake is focused on creating PDFs from scratch using JavaScript objects, while pdfh5 is primarily used for rendering existing PDFs in the browser.
A JavaScript PDF generation library for Node and the browser
Pros of PDFKit
- More comprehensive PDF creation capabilities, allowing for complex document generation
- Better documentation and wider community support
- Supports both server-side (Node.js) and client-side (browser) usage
Cons of PDFKit
- Larger file size and potentially higher resource usage
- Steeper learning curve for beginners due to more advanced features
- Primarily focused on PDF creation rather than viewing
Code Comparison
PDFKit (PDF creation):
const PDFDocument = require('pdfkit');
const doc = new PDFDocument();
doc.pipe(fs.createWriteStream('output.pdf'));
doc.text('Hello, world!');
doc.end();
PDFH5 (PDF viewing):
var pdfh5 = new Pdfh5('#demo', {
pdfurl: './test.pdf'
});
pdfh5.renderPdf(1);
Key Differences
- PDFKit is primarily for creating PDFs, while PDFH5 focuses on viewing PDFs in browsers
- PDFKit offers more control over PDF content and structure
- PDFH5 provides a simpler API for displaying PDFs in web applications
- PDFKit has broader platform support, including server-side usage
- PDFH5 is more lightweight and easier to integrate for basic PDF viewing needs
Client-side JavaScript PDF generation for everyone.
Pros of jsPDF
- More comprehensive PDF creation capabilities, including text, images, and vector graphics
- Wider browser compatibility and no external dependencies
- Larger community and more frequent updates
Cons of jsPDF
- Steeper learning curve due to more complex API
- Larger file size, which may impact page load times
- Limited built-in support for viewing PDFs in the browser
Code Comparison
pdfh5:
var pdfh5 = new Pdfh5('#demo', {
pdfurl: './path/to/pdf'
});
jsPDF:
var doc = new jsPDF();
doc.text('Hello world!', 10, 10);
doc.save('a4.pdf');
Summary
pdfh5 is primarily focused on PDF viewing within the browser, offering a simpler API for basic PDF display. jsPDF, on the other hand, provides a more powerful toolkit for creating PDFs from scratch, with extensive options for content manipulation. While pdfh5 excels in quick PDF viewing integration, jsPDF is better suited for applications requiring dynamic PDF generation and complex document creation.
Convert
designs to code with AI
Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.
Try Visual CopilotREADME
pdfh5.js
1ãæé®é¢å¯ä»¥å Q群å¨è¯¢ï¼ææ¯äº¤æµç¾¤ï¼ä¹å¯ä»¥æ¢è®¨ææ¯ï¼å¦æå¾®ä¿¡ç¾¤å¯ä»¥é®ç¾¤ä¸»æå ¥å¾®ä¿¡ç¾¤
2ãå¦æææ¥éï¼è¯·å¤å¶exampleè¿è¡ï¼ç¶åå¯¹ç §ç¸å ³æä»¶ï¼ä»¥åpackage.jsonï¼ç¼ºä»ä¹è¡¥ä»ä¹
3ã妿ææäºå使¾ç¤ºä¸äºï¼é£å¯è½æ¯pdf.js缺å°ç¸å ³ååºè§£æï¼å¯ä»¥å°è¯æ´æ¹cMapUrlï¼å»ºè®®å»å®æ¹å°åæ¾çæ¬
4ã妿IOSä¸pdfæ¾ç¤ºä¸äºï¼å®åå´å¯ä»¥ï¼å¯è½æ¯pdf精度è¿é«å¯¼è´ï¼Safariæµè§å¨canvas渲æç»å¶å¾ç宽é«ä¸è½è¶ è¿16777216ï¼è¶ è¿ä¼ä¸æ¾ç¤º
reactãvueåå¯ä½¿ç¨
example/testæ¯vue使ç¨ç¤ºä¾
example/vue3demoæ¯vue3使ç¨ç¤ºä¾
example/vite4vue3æ¯vite4+vue3+ts使ç¨ç¤ºä¾
example/react-testæ¯react使ç¨ç¤ºä¾
æ´æ°ä¿¡æ¯
- 2024.02.29 æ´æ°ï¼ ä¿®å¤é¨åbugsã
pdfh5å¨çº¿é¢è§ ï¼å»ºè®®ä½¿ç¨è°·ææµè§å¨F12ææºæ¨¡å¼æå¼é¢è§ï¼
å¿«é使ç¨ï¼æä¸¤ç§æ¹å¼ï¼
ä¸ãscriptæ ç¾å¼å ¥æ¹å¼ï¼éä¸è½½æ¬é¡¹ç®æä»¶å¤¹css/pdfh5.cssãjså æææä»¶ï¼
- 1.å¼å ¥css
<link rel="stylesheet" href="css/pdfh5.css" />
- 2.å建div
<div id="demo"></div>
- 3.便¬¡å¼å ¥jsï¼éå¼ç¨æ¬é¡¹ç®çjs,ä¸è¦å¼ç¨å®æ¹çpdf.js,jqueryå¯ä»¥å¼ç¨å ¶å®ççï¼
<script src="js/pdf.js" type="text/javascript" charset="utf-8"></script>
<script src="js/pdf.worker.js" type="text/javascript" charset="utf-8"></script>
<script src="js/jquery-2.1.1.min.js" type="text/javascript" charset="utf-8"></script>
<script src="js/pdfh5.js" type="text/javascript" charset="utf-8"></script>
- 4.å®ä¾å
var pdfh5 = new Pdfh5('#demo', {
pdfurl: "./default.pdf"
});
äºãnpmå®è£ æ¹å¼ï¼éåºäºvueï¼, reactä½¿ç¨æ¹æ³ç±»ä¼¼vueï¼example/react-testæ¯react使ç¨ç¤ºä¾ï¼
- 1.å®è£
npm install pdfh5
- 2.使ç¨
<template>
<div id="app">
<div id="demo"></div>
</div>
</template>
<script>
import Pdfh5 from "pdfh5";
export default {
name: 'App',
data() {
return {
pdfh5: null
};
},
mounted() {
//å®ä¾å
this.pdfh5 = new Pdfh5("#demo", {
pdfurl: "../../static/test.pdf",
// cMapUrl:"https://unpkg.com/pdfjs-dist@3.8.162/cmaps/",
// responseType: "blob" // blob arraybuffer
});
//çå¬å®æäºä»¶
this.pdfh5.on("complete", function (status, msg, time) {
console.log("ç¶æï¼" + status + "ï¼ä¿¡æ¯ï¼" + msg + "ï¼èæ¶ï¼" + time + "毫ç§ï¼æ»é¡µæ°ï¼" + this.totalNum)
//ç¦æ¢æå¿ç¼©æ¾
this.pdfh5.zoomEnable(false);
})
}
}
</script>
<style>
@import "pdfh5/css/pdfh5.css";
*{
padding: 0;
margin: 0;
}
html,body,#app {
width: 100%;
height: 100%;
}
</style>
- 注æï¼å¦æcsså¼ç¨æ¥éçè¯ï¼æä¸é¢çæ¹å¼å¼ç¨ã
import Pdfh5 from "pdfh5";
import "pdfh5/css/pdfh5.css";
APIæ¥å£æ¹æ³
å®ä¾å
- pdfh5å®ä¾åçæ¶åä¼ ä¸¤ä¸ªåæ°ï¼selectoréæ©å¨ï¼optionsé ç½®é¡¹åæ°ï¼ä¼è¿åä¸ä¸ªpdfh5å®ä¾å¯¹è±¡ï¼å¯ä»¥ç¨æ¥æä½pdfï¼çå¬ç¸å ³äºä»¶
var pdfh5 = new Pdfh5(selector, options);
åæ°åç§° | ç±»å | åå¼ | æ¯å¦å¿ é¡» | ä½ç¨ |
---|---|---|---|---|
selector | String | - | â | pdfh5ç容å¨éæ©å¨ |
options | Object | - | à | pdfh5çé ç½®é¡¹åæ° |
optionsé ç½®é¡¹åæ°å表
- 示ä¾ï¼ é ç½®é¡¹åæ° pdfurl
var pdfh5 = new Pdfh5('#demo', {
pdfurl: "./default.pdf"
});
åæ°åç§° | ç±»å | åå¼ | ä½ç¨ |
---|---|---|---|
pdfurl | String | - | pdfå°å |
responseType | String | blob ã arraybuffer é»è®¤ blob | 请æ±pdfæ°æ®æ ¼å¼ |
URIenable | Boolean | trueãfalseï¼ é»è®¤false | trueå¼å¯å°åæ fileåæ° |
data | Array(arraybuffer) | - | pdfæä»¶æµ ï¼ä¸pdfurläºéä¸(äºè¿å¶PDFæ°æ®ã使ç¨ç±»ååæ°ç»ï¼Uint8Arrayï¼å¯ä»¥æé«å å使ç¨çã妿PDFæ°æ®æ¯BASE64ç¼ç çï¼è¯·å 使ç¨atobï¼ï¼å°å ¶è½¬æ¢ä¸ºäºè¿å¶å符串ã) |
renderType | String | "canvas"ã"svg"ï¼é»è®¤"canvas" | pdfæ¸²ææ¨¡å¼ |
pageNum | Boolean | trueãfalseï¼ é»è®¤true | æ¯å¦æ¾ç¤ºå·¦ä¸è§é¡µç |
backTop | Boolean | trueãfalseï¼ é»è®¤true | æ¯å¦æ¾ç¤ºå³ä¸è§åå°é¡¶é¨æé® |
maxZoom | Number | æå¤§åæ°3 | æå¿ç¼©æ¾æå¤§åæ° |
scale | Number | æå¤§æ¯ä¾5ï¼é»è®¤1.5 | pdf渲æçæ¯ä¾ |
scrollEnable | Boolean | trueãfalseï¼ é»è®¤true | æ¯å¦å 许pdfæ»å¨ |
zoomEnable | Boolean | trueãfalseï¼ é»è®¤true | æ¯å¦å 许pdfæå¿ç¼©æ¾ |
cMapUrl | String | " | è§£æpdfæ¶ï¼ç¹æ®æ åµä¸æ¾ç¤ºå®æ´åä½çcmapsæä»¶å¤¹è·¯å¾ï¼ä¾å¦ cMapUrl:"https://unpkg.com/pdfjs-dist@2.0.943/cmaps/" |
limit | Number | é»è®¤0 | éå¶pdfå è½½æå¤§é¡µæ° |
logo | Object | {src:"pdfh5.png",x:10,y:10,width:40,height:40}srcæ°´å°å¾çè·¯å¾ï¼å»ºè®®ä½¿ç¨pngéæå¾çï¼ï¼widthæ°´å°å®½åº¦ï¼heightæ°´å°é«åº¦ï¼ä»¥æ¯é¡µpdfå·¦ä¸è§ä¸º0ç¹ï¼xãy为åç§»å¼ã é»è®¤false | ç»æ¯é¡µpdfæ·»å æ°´å°logoï¼canvas模å¼ä¸ä½¿ç¨ï¼ |
goto | Number | é»è®¤0 | å è½½pdf跳转å°ç¬¬å 页 |
textLayer | Boolean | trueãfalseï¼ é»è®¤false | æ¯å¦å¼å¯textLayerï¼å¯ä»¥å¤å¶ææ¬ï¼canvas模å¼ä¸ä½¿ç¨ï¼ãå¤äºæµè¯é¶æ®µï¼ä½ç½®å移严éã |
background | Object | {color:"#fff",image:"url('pdfh5.png')",repeat:"no-repeat",position:"left top",size:"40px 40px"}ï¼åcssçbackground屿§è¯æ³ç¸åï¼é»è®¤false | æ¯å¦å¼å¯èæ¯å¾æ¨¡å¼ |
pdf请æ±ç¤ºä¾
new Pdfh5('#demo', {
pdfurl: "git.pdf",
// responseType: "blob" // blob arraybuffer
});
- pdfæä»¶æµæè bufferå·²ç»å¾å°ï¼å¦ä½æ¸²æ
new Pdfh5('#demo', {
data: blob, //blob arraybuffer
});
methods æ¹æ³å表
- 示ä¾ï¼ æ¯å¦å 许pdfæ»å¨
pdfh5.scrollEnable(true) //å
许pdfæ»å¨
pdfh5.scrollEnable(false) //ä¸å
许pdfæ»å¨
æ¹æ³å | ä¼ å | ä¼ ååå¼ | ä½ç¨ |
---|---|---|---|
scrollEnable | Boolean | trueãfalseï¼ é»è®¤true | æ¯å¦å 许pdfæ»å¨(éè¦å¨pdfå è½½å®æå使ç¨) |
zoomEnable | Boolean | trueãfalseï¼ é»è®¤true | æ¯å¦å 许pdfæå¿ç¼©æ¾(éè¦å¨pdfå è½½å®æå使ç¨) |
show | Function | 带ä¸ä¸ªåè°å½æ° | pdfh5æ¾ç¤º |
hide | Function | 带ä¸ä¸ªåè°å½æ° | pdfh5éè |
reset | Function | 带ä¸ä¸ªåè°å½æ° | pdfh5è¿å |
destroy | Function | 带ä¸ä¸ªåè°å½æ° | pdfh5鿝 |
on | (String, Function) | Stringï¼çå¬çäºä»¶åï¼Functionï¼çå¬çäºä»¶åè° | onæ¹æ³ç嬿æäºä»¶ |
goto | Number | Number:è¦è·³è½¬çpdfé¡µæ° | pdf跳转å°ç¬¬å 页ï¼pdfå è½½å®æå使ç¨ï¼ |
download | (String, Function) | Stringï¼ä¸è½½pdfçåç§°ï¼é»è®¤download.pdfï¼Functionï¼ä¸è½½å®æåçåè° | ä¸è½½pdf |
onæ¹æ³ç嬿æäºä»¶-äºä»¶åå表
- 示ä¾ï¼ çå¬pdfåå¤å¼å§æ¸²æï¼æ¤æ¶å¯ä»¥æ¿å°pdfæ»é¡µæ°
pdfh5.on("ready", function () {
console.log("æ»é¡µæ°ï¼" + this.totalNum)
})
äºä»¶å | åè° | ä½ç¨ |
---|---|---|
init | Function | çå¬pdfh5å¼å§åå§å |
ready | Function | çå¬pdfåå¤å¼å§æ¸²æï¼æ¤æ¶å¯ä»¥æ¿å°pdfæ»é¡µæ° |
error | Function(msg,time) | çå¬å 载失败ï¼msgä¿¡æ¯ï¼timeèæ¶ |
success | Function(msg,time) | çå¬pdf渲ææåï¼msgä¿¡æ¯ï¼timeèæ¶ |
complete | Function(status, msg, time) | çå¬pdfå è½½å®æäºä»¶ï¼å è½½å¤±è´¥ãæ¸²ææåé½ä¼è§¦åãstatusæä¸¤ç§ç¶æsuccessåerror |
render | Function(currentNum, time, currentPageDom) | çå¬pdf渲æè¿ç¨ï¼currentPageDomå½åå è½½çpdfçdom,currentNumå½åå è½½çpdf页æ°, |
zoom | Function(scale) | çå¬pdf缩æ¾ï¼scaleç¼©æ¾æ¯ä¾ |
scroll | Function(scrollTop,currentNum) | çå¬pdfæ»å¨ï¼scrollTopæ»å¨æ¡é«åº¦,currentNumå½å页ç |
backTop | Function | çå¬åå°é¡¶é¨æé®çç¹å»äºä»¶åè° |
zoomEnable | Function(flag) | çå¬å 许缩æ¾ï¼flagï¼trueï¼false |
scrollEnable | Function(flag) | çå¬å 许æ»å¨ï¼flagï¼trueï¼false |
show | Function | çå¬pdfh5æ¾ç¤º |
hide | Function | çå¬pdfh5éè |
reset | Function | çå¬pdfh5è¿å |
destroy | Function | çå¬pdfh5鿝 |
æèµæ¦å
- JayLin ï¿¥6.66
- éä»å ï¿¥6.67
- åè ï¿¥8.80
- ææ¯å¤ªé³ ï¿¥29.99
- *å°æ³¢ ï¿¥1.00
- *é« Â¥9.99
- *æ Â¥9.99
- *å ï¿¥19.99
- *ç· Â¥5.00
- *è¶ Â¥20.00
- 3*Y ¥5.00
- *é³ Â¥5.00
- **é Â¥5.00
- A*r ¥1.23
- *客 ¥5.00
- *è¿ Â¥66.66
- *辰 ¥30.00
- *é» Â¥6.66+Â¥5.00
- **ç¦ Â¥6.66
- *ð Â¥6.66+Â¥1.00
- *é³ Â¥10.00
- èªéä¸ Â¥16.66+Â¥16.00
- *ç Â¥6.66
- *人 ¥5.00
- *ã Â¥5.20
- å*) Â¥5.00
- *1 ¥15.00
- *è¾ Â¥16.66+Â¥8.80
- *å Â¥10.00
- **强 ¥58.88
- E*y ¥6.60
- J*u ¥13.00
- A*a ¥50.00
- *ä¸ Â¥8.80
- j*y ¥9.99
- *å® Â¥6.66
- *æ¶ ï¿¥1.00
- *. ï¿¥10.00
- *⺠¥6.66
- *é¸ ï¿¥6.66
- a*r ï¿¥20.00
- æ¨æ§¿(**è) ï¿¥50.00
Top Related Projects
Convert
designs to code with AI
Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.
Try Visual Copilot