A powerful EPUB to PDF converter that processes EPUB files and converts them into high-quality, readable PDFs using jsPDF
. This package is especially useful for anyone looking to convert EPUB files programmatically within their JavaScript/TypeScript projects.
- Converts EPUB files to PDF format.
- Handles images, styles, and text formatting.
- Preserves the Table of Contents without splitting across pages.
- Lightweight and fast, built on modern JavaScript libraries (
jsPDF
,JSZip
,html-to-text
).
To use this package, you need to install it via npm:
npm install bookracy-convertor
You can import the buildPDFConvertor
function and pass the URL of the EPUB file along with a button element. The PDF will be generated when the button is clicked.
import { buildPDFConvertor } from 'bookracy-convertor';
// Get the button and the EPUB URL
const button = document.getElementById('generate-pdf');
const bookUrl = 'https://example.com/path/to/book.epub';
// Initialize the convertor
buildPDFConvertor(bookUrl, button);
bookUrl
(string): The URL of the EPUB file to convert.button
(HTMLElement): The button element that will trigger the conversion on click.
When the button is clicked, the PDF will be generated and automatically downloaded.
- Node.js v14 or later.
- Browser environment with DOM manipulation (works with most modern browsers).
First, clone the repository and install dependencies:
git clone https://github.com/yourusername/bookracy-convertor.git
cd bookracy-convertor
npm install
npm run dev
This will start a Vite development server to preview and test your changes.
npm run build
This will compile and bundle the code for production use.
Make sure to keep the code linted and formatted:
npm run lint
npm run lint:fix # Automatically fix issues
You can test the conversion function by simulating the button click event in a browser.
- Start the development server using
npm run dev
. - Access the browser and test the button that triggers the conversion.
- You can also test individual parts by inspecting logs, such as EPUB fetching, PDF generation, etc.
For formal tests (unit tests, etc.), Jest or Mocha can be integrated into the project. (Note: Tests are not included in this version but can be added in the future.)
We welcome contributions! Please read the CONTRIBUTING.md file for more details on how to contribute to this project.
This project is licensed under the MIT License. See the LICENSE file for details.
Feel free to open issues on the GitHub repository or submit pull requests for improvements.
If you find a bug in the project, please open an issue with a detailed description of the problem and steps to reproduce it. Make sure to mention the platform and environment you’re using (e.g., operating system, Node.js version, browser, etc.).
If you have a feature idea, please and describe the feature in detail. We’re always open to new suggestions and ideas.
Please respect others and be kind in your contributions. Harassment or rude behavior will not be tolerated. Let’s make this project a great space for collaboration! 😊
Thank you for contributing!
In addition to the usage and contribution guidelines, here are more detailed testing steps for the project:
- Start Development Server:
npm run dev
- Access the browser, trigger the conversion by clicking the button, and observe the PDF download.
- Add
console.log
statements to verify that key processes (e.g., fetching the EPUB, generating PDF pages, handling styles) are working as expected.
- You can integrate testing frameworks like Jest or Mocha for unit tests on functions such as
fetchFile
,handleEpub
, or the PDF creation logic. - Add tests to ensure functions behave correctly for different EPUB files (e.g., with or without Table of Contents, with different image formats, etc.).