html-to-pdf-package
v1.0.1
Published
A simple npm package to convert HTML content to PDF files using Puppeteer.
Downloads
80
Maintainers
Readme
#HTML to PDF Package A simple npm package to convert HTML content into PDF files using Puppeteer.
##Features
- Converts HTML content to PDF files.
- Supports HTML strings and HTML files.
- Easy-to-use API.
##Installation To install the package, use npm: npm install html-to-pdf-package
##Usage ###Convert HTML String to PDF const { htmlToPdf } = require('html-to-pdf-package'); const htmlContent = 'Hello, World!This is a sample PDF generated from HTML.'; htmlToPdf(htmlContent, 'output.pdf') .then(() => { console.log('PDF generated successfully!'); }) .catch(error => { console.error('Error generating PDF:', error); });
###Convert HTML File to PDF const { convertHtmlFileToPdf } = require('html-to-pdf-package'); convertHtmlFileToPdf('sample.html', 'output-file.pdf') .then(() => { console.log('PDF generated from HTML file successfully!'); }) .catch(error => { console.error('Error generating PDF from file:', error); });
##API ###htmlToPdf(htmlContent, outputPath)
- Parameters:
- htmlContent (string): The HTML content to convert to PDF.
- outputPath (string): The path where the generated PDF will be saved.
- Returns: A promise that resolves when the PDF has been successfully generated. ###convertHtmlFileToPdf(htmlFilePath, outputPath)
- Parameters:
- htmlFilePath (string): The path to the HTML file to convert to PDF.
- outputPath (string): The path where the generated PDF will be saved.
- Returns: A promise that resolves when the PDF has been successfully generated. ##Contributing We welcome contributions to improve this package. To contribute:
- Fork the repository.
- Create a new branch (git checkout -b feature-branch).
- Make your changes and commit them (git commit -am 'Add new feature').
- Push your branch (git push origin feature-branch).
- Create a pull request.
Contact
If you have any questions or need support, please contact Yash Kainth.
Acknowledgements
- Puppeteer: The library used for converting HTML to PDF.