Code Monkey home page Code Monkey logo

web-to-pdf's Introduction

Web to PDF Converter

Easily create beautiful PDFs using your favorite Javascript and CSS framework!

Created and maintained by PDFTron.

This project is still in development and should not be used in a production environment! It has not been tested in all use cases.

We are very interested in seeing how people use this tool. If you have any questions, comments or would just like to tell us how you're using it, please feel free to open a ticket!

Features

  • ๐Ÿ’ฅ JS is fully supported, meaning you can use your favorite frameworks to generate your PDF.
  • ๐Ÿ”„ Comes with a powerful content replacement system that allows for dynamic content.
  • ๐Ÿ”ข Insert page numbers in your pages dynamically.
  • ๐Ÿ’ƒ Full SCSS support
  • ๐Ÿ‘ธ Support for headers and footers
  • ๐Ÿ”— Support for reusuable HTML chunks
  • ๐ŸŽฅ Real time mode with hot reloading, meaning you can build your PDF in real time
  • ๐ŸŒ Support for rendering remote pages (You can even inject your own css and js!)
  • ๐Ÿšฆ Queueing system so you can render 1000's of PDFs with a single script.
  • ๐Ÿ‘ Much more!

Roadmap

  • Examples (external repos?) of usage with other frameworks
  • Splitting of non-list content on page break
  • Support for form inputs

Installation

npm i @pdftron/web-to-pdf

Example

const Renderer = require('@pdftron/web-to-pdf');

const r = new Renderer({ dirname: __dirname });

const htmlString = `
  <html>
    <head>
      <link rel='stylesheet' href='style.scss'>
    </head>
    <body>
      <div class='Page'>
        Page1: {{myText}}
      </div>

      <div class='Page'>
        Page2: Goodbye world!
      </div>
    </body>
  </html>
`;

r.render({
  templateSource: htmlString,
  contentSource: {
    myText: "Hello world!"
  },
  outputName: 'example'
});

// Pdf will be rendered at ./outputs/example.pdf !

See more examples here.

Documentation

Real time PDF Building

With a few changes to your options you can enable real time PDF building! See the docs for more info.

Development

git clone https://github.com/PDFTron/web-to-pdf.git
cd web-to-pdf
npm i

There are examples you can test on in the examples folder. These examples are run via scripts in package.json

Contributing

Before created a PR, please make sure tests pass:

npm run test

If you would like to contribute but aren't sure how, please open a ticket saying you would like to contribute.

Feel free to add tests you feel needed.

Caveats

  • Creation of PDF input fields is not supported (not supported by chromium).

web-to-pdf's People

Contributors

lbittner-pdftron avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

web-to-pdf's Issues

Cannot install the module vuejs, update webpack?

Describe the bug
cannot npm install the module
To Reproduce
npm i @pdftron/web-to-pdf

Expected behavior
install normally

Screenshots

>npm i @pdftron/web-to-pdf
npm WARN deprecated [email protected]: This module relies on Node.js's internals and will break at some point. Do not use it, and update to [email protected].
npm WARN deprecated [email protected]: The package has been renamed to `open`
npm WARN deprecated [email protected]: Please update to minimatch 3.0.2 or higher to avoid a RegExp DoS issue
npm WARN deprecated [email protected]: Please update to minimatch 3.0.2 or higher to avoid a RegExp DoS issue
npm WARN deprecated [email protected]: please upgrade to graceful-fs 4 for compatibility with current and future versions of Node.js
npm WARN deprecated [email protected]: Chokidar 2 does not receive security updates since 2019. Upgrade to chokidar 3 with 15x fewer dependencies
npm WARN deprecated [email protected]: Chokidar 2 does not receive security updates since 2019. Upgrade to chokidar 3 with 15x fewer dependencies
npm WARN deprecated [email protected]: Please update to minimatch 3.0.2 or higher to avoid a RegExp DoS issue
npm WARN deprecated [email protected]: gulp-util is deprecated - replace it, following the guidelines at https://medium.com/gulpjs/gulp-util-ca3b1f9f9ac5
npm WARN deprecated [email protected]: Version no longer supported. Upgrade to @latest
npm WARN deprecated [email protected]: core-js@<3.4 is no longer maintained and not recommended for usage due to the number of issues. Because of the V8 engine whims, feature detection in old core-js versions could cause a slowdown up to 100x even if nothing is polyfilled. Please, upgrade your dependencies to the actual version of core-js.
npm ERR! code 1
npm ERR! path (...)\node_modules\@pdftron\web-to-pdf
npm ERR! command failed
npm ERR! command C:\WINDOWS\system32\cmd.exe /d /s /c npm i node-sass live-server --save
npm ERR! npm ERR! code ERESOLVE
npm ERR! npm ERR! ERESOLVE unable to resolve dependency tree
npm ERR! npm ERR!
npm ERR! npm ERR! While resolving: @pdftron/[email protected]
npm ERR! npm ERR! Found: [email protected]
npm ERR! npm ERR! node_modules/webpack
npm ERR! npm ERR!   dev webpack@"^4.16.0" from the root project
npm ERR! npm ERR!
npm ERR! npm ERR! Could not resolve dependency:
npm ERR! npm ERR! peer webpack@"^3.1.0" from [email protected]
npm ERR! npm ERR! node_modules/extract-text-webpack-plugin
npm ERR! npm ERR!   dev extract-text-webpack-plugin@"^3.0.2" from the root project
npm ERR! npm ERR!
npm ERR! npm ERR! Fix the upstream dependency conflict, or retry
npm ERR! npm ERR! this command with --force, or --legacy-peer-deps
npm ERR! npm ERR! to accept an incorrect (and potentially broken) dependency resolution.
npm ERR! npm ERR!
npm ERR! npm ERR! See (...)\npm-cache\eresolve-report.txt for a full report.
npm ERR!
npm ERR! npm ERR! A complete log of this run can be found in:
npm ERR! npm ERR!     (...)\npm-cache\_logs\2022-04-07T17_28_29_028Z-debug-0.log

npm ERR! A complete log of this run can be found in:
npm ERR!     (...)\npm-cache\_logs\2022-04-07T17_28_10_528Z-debug-0.log

Ability to merge multiple HTML sources into one PDF

A use case was brought up where someone wanted to scrape multiple web pages, and combine them into a single PDF.

This would be useful for things like documentation, textbooks, etc.

This should be pretty easy to implement by accepting an array of sources for templateSource.

unable to run with Typescript App

Hi,

I am trying the react sample code in my React-Typescript app and I encountered the following error:

./node_modules/@pdftron/web-to-pdf/dist/web-to-pdf.js 1:0
Module parse failed: Unexpected character '#' (1:0)
File was processed with these loaders:

  • ./node_modules/babel-loader/lib/index.js
    You may need an additional loader to handle the result of these loaders.
    (Source code omitted for this binary file)

Could you please let me know how to resolve the error..

Thanks in Advance,

cannot generate pdf with styles option in real-time example

Describe the bug
I cannot generate a pdf when I add styles option.

This bug can be reproduced using one of the examples provided (real-time example)

To Reproduce
paste this code into examples/real-time/options.js

module.exports = () => {
  const footer = `
    <div class="footer">
      <span>span 1</span>
      <span class="class1">span 2</span>
      <span class="class2">span3 | {{pageNumber}}</span>
    </div>
  `;

  const html = () => {
    return `
      <div class="Split">
        <p>Hello Page 1</p>
      </div>
      <div class="Split">
        <p>Hello Page 2</p>
      </div>
    `
  }

  return {
    templateSource: html,
    outputName: 'real-time',
    pageClass: 'Split',
    chunks: {
      footer
    }
  };
}

run npx babel-node examples/real-time/index.js => works fine!

add styles option

...
styles: [
  `
   .Split {
     color: red;
	 
     p { color: green; }
   }
  `
]
...

this also works fine!

close the current task and then try again with styles option => error!

in my case I get this error:

(node:2927) UnhandledPromiseRejectionWarning: Error: no parsers registered for: "
    "
    at parse (/Users/bboydflo/dev/personal/web-to-pdf/node_modules/snapdragon/lib/parser.js:473:15)
    at Parser.parse (/Users/bboydflo/dev/personal/web-to-pdf/node_modules/snapdragon/lib/parser.js:477:24)
    at Snapdragon.parse (/Users/bboydflo/dev/personal/web-to-pdf/node_modules/snapdragon/index.js:122:28)
    at Snapdragon.<anonymous> (/Users/bboydflo/dev/personal/web-to-pdf/node_modules/micromatch/lib/utils.js:47:45)
    at parse (/Users/bboydflo/dev/personal/web-to-pdf/node_modules/micromatch/index.js:739:26)    at memoize (/Users/bboydflo/dev/personal/web-to-pdf/node_modules/micromatch/index.js:859:13)
    at Function.micromatch.parse (/Users/bboydflo/dev/personal/web-to-pdf/node_modules/micromatch/index.js:745:10)
    at create (/Users/bboydflo/dev/personal/web-to-pdf/node_modules/micromatch/index.js:686:44)
    at /Users/bboydflo/dev/personal/web-to-pdf/node_modules/micromatch/index.js:695:16
    at memoize (/Users/bboydflo/dev/personal/web-to-pdf/node_modules/micromatch/index.js:859:13)
(node:2927) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handle
d with .catch(). (rejection id: 1)
(node:2927) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

Expected behavior
I'm want to be able to generate a report with above options.

Desktop (please complete the following information):

  • OS: macOS Catalina
  • Browser: Firefox Developer Edition

Additional context
In summary: I am able to generate a pdf if I don't add styles from the beginning but it fails if I do.

add suport for images in html and css

Is your feature request related to a problem? Please describe.
I want to use images both as img tags inside html template and as a css background.

Describe the solution you'd like
I would like to be able to position images everywhere on the page and the option to stretch an image to fill the whole page.

Additional context
Some examples for the above features would be really nice.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.