0.3.0 • Published 2 years ago

@archireport/react-native-static-html-to-pdf v0.3.0

Weekly downloads
-
License
MIT
Repository
github
Last release
2 years ago

react-native-static-html-to-pdf

Convert static html file to pdf

This library is inspired by react-native-html-to-pdf. It takes a static html file as parameter (whereas react-native-html-to-pdf takes a string as argument).

It takes a screenshot of the page before redirection to target. So you need to add in your html file the following script at the end of the execution of your js

window.location.href = 'http://finishload.com';

The returned value is the path of the generated pdf file

Installation

npm install @archireport/react-native-static-html-to-pdf

Usage

import { generatePdf } from '@archireport/react-native-static-html-to-pdf';

// ...

const pathOfGeneratedPdf = await generatePdf({
  path: `${DocumentDirectoryPath}/public/index.html`,
  target: 'http://finishload.com',
  documentName: 'file.pdf',
  width: 612,
  height: 792,
});

where

paramdescriptionexample
pathpath to your html file (it must be under documents)${DocumentDirectoryPath}/index.html (DocumentDirectoryPath is provided by react-native-fs)
targeturl used to indicate that js execution is finishedhttp://finishload.com
documentNamename of the generated pdf (in cache directory)file.pdf
widthwidth of the generated pdf612
heightheight of the generated pdf792

Contributing

See the contributing guide to learn how to contribute to the repository and the development workflow.

License

MIT