Skip to content

Commit 3f797e7

Browse files
committed
Update README with the pdfGeneration Lib
1 parent aa6fb5d commit 3f797e7

1 file changed

Lines changed: 71 additions & 2 deletions

File tree

README.md

Lines changed: 71 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,9 @@ Titanium Native Module (Android) and libraries for generating PDF files based on
1515
* `pdfGeneration.js` depends on [mustache.js](https://github.com/janl/mustache.js) for parsing templates.
1616
* For iOS, [NappPDFCreator](https://github.com/viezel/NappPDFCreator) is recommended
1717

18-
## Basic Usage
18+
##PDFCreator Module
19+
20+
### Basic Usage
1921
1. Make sure you have the module dependency added on `tiapp.xml`
2022

2123
```xml
@@ -36,7 +38,7 @@ Titanium Native Module (Android) and libraries for generating PDF files based on
3638
* `generatePDFWithHTML()` - Parses some HTML string and creates a PDF file from it. Use `XMLWorker` for it. PDF files have the best quality but not all HTML/CSS properties are supported yet.
3739
* `generatePDFwithWebView()` - Takes a screenshot from a given `Ti.UI.WebView` and divides the resulting image into several pages. PDF files have medium quality and use a lot of space on disk, but supports all the HTML/CSS properties available.
3840

39-
## Example
41+
### Example
4042
```javascript
4143
var PdfCreator = require('com.propelics.pdfcreator');
4244

@@ -71,3 +73,70 @@ webview.addEventListener('load', function (e) {
7173

7274
webview.url = 'www.apple.com';
7375
```
76+
77+
## PDFGeneration lib
78+
79+
### Basic Usage
80+
* This lib is intended to handle the common use cases for the PDF module creation. Therefore it depends on the `PDFCreator` module.
81+
* Add `pdfGeneration.js` and `mustache.js` under `app/lib` (for Alloy projects).
82+
* 2 functions are included to generate the PDF files
83+
* `generateWithWebView()` - Generates a PDF file based on an HTML File using a webview to load it's data. **It does NOT use `PDFCreator.generatePDFwithWebView()`**
84+
* `generatePDFWithTemplate()` - Generates a PDF file based on an HTML Template, will load using `mustache.js`
85+
* Both functions take a set of options to generate the PDF.
86+
* `htmlFile` - File object to load that includes the HTML file to parse
87+
* `data` - Dictionary with data to be parsed inside the HTML before generating the PDF
88+
* `sucessCallback` - Function called when the PDF gets generated
89+
* `failCallback` - Function called if an error occurs
90+
91+
### Example
92+
```javascript
93+
var PdfGeneration = require('pdfGeneration');
94+
95+
// Workaround to load images
96+
var imageFile = Ti.Filesystem.getFile(Ti.Filesystem.resourcesDirectory, 'image.jpg');
97+
var imgTemp = Ti.Filesystem.createTempFile();
98+
imgTemp.write(imageFile.read());
99+
100+
PdfGeneration.generateWithWebView({
101+
// Name of the PDF file to create
102+
pdfFileName : 'webview',
103+
// File containing the html to load
104+
htmlFile : Ti.Filesystem.getFile(Ti.Filesystem.resourcesDirectory, 'webview.html'),
105+
// A view to contain the Webview (should be inside an opened Window)
106+
wrapper : $.index,
107+
// Data to parse
108+
data : {
109+
customerName : 'John Doe',
110+
image : imgTemp.resolve().replace('file:', '')
111+
},
112+
successCallback : function (_data) {
113+
// The PDF was created
114+
},
115+
failCallback : function (_data) {
116+
// An error occured
117+
}
118+
});
119+
120+
PdfGeneration.generatePDFWithTemplate({
121+
// Name of the PDF file to create
122+
pdfFileName : 'template',
123+
// File containing the html to load
124+
htmlFile : Ti.Filesystem.getFile(Ti.Filesystem.resourcesDirectory, 'template.html'),
125+
// Data to parse
126+
data : {
127+
customerName : 'John Doe',
128+
image : imgTemp.resolve().replace('file:', '')
129+
},
130+
successCallback : function (_data) {
131+
// The PDF was created
132+
},
133+
failCallback : function (_data) {
134+
// An error occured
135+
}
136+
});
137+
```
138+
139+
### Notes for loaing PDF files
140+
* In order to load images, the absolute path for the images is needed under the `src` attribute.
141+
* CSS styles should be loaded within the HTML file.
142+
* Only the system fonts are supported. If the `font-face` includes an specific name, it will take more time to load that using `serif` or `sans-serif`

0 commit comments

Comments
 (0)