Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/m1ga/ti.pdftools
PDF Tools for Titanium (Android)
https://github.com/m1ga/ti.pdftools
android titanium-mobile titanium-module titanum
Last synced: 24 days ago
JSON representation
PDF Tools for Titanium (Android)
- Host: GitHub
- URL: https://github.com/m1ga/ti.pdftools
- Owner: m1ga
- License: mit
- Created: 2021-07-17T12:43:55.000Z (over 3 years ago)
- Default Branch: main
- Last Pushed: 2022-08-30T10:26:50.000Z (over 2 years ago)
- Last Synced: 2024-05-02T05:13:07.244Z (8 months ago)
- Topics: android, titanium-mobile, titanium-module, titanum
- Language: Java
- Homepage:
- Size: 14.6 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Ti.PDFTools
Titanium module for using PdfBox on Android using https://github.com/TomRoush/PdfBox-Android
## Installation
```
ti.pdftools
```
## Usage
```javascript
var pdftools = require('ti.pdftools');// files
var f1 = Ti.Filesystem.getFile(Ti.Filesystem.resourcesDirectory, "1.pdf");
var f2 = Ti.Filesystem.getFile(Ti.Filesystem.resourcesDirectory, "2.pdf");var file = pdftools.merge([
f1, f2
]);/*
var f1 = Ti.Filesystem.getFile(Ti.Filesystem.resourcesDirectory, "image1.jpg");
var f2 = Ti.Filesystem.getFile(Ti.Filesystem.resourcesDirectory, "image2.png");var file = pdftools.imagesToPdf([
f1, f2
]);
*/// open merged PDF file
var intent = Ti.Android.createIntent({
action: Ti.Android.ACTION_VIEW,
type: "application/pdf",
data: file.nativePath
});
var open = Ti.Android.createIntentChooser(intent, "open pdf");
Ti.Android.currentActivity.startActivity(open);
```#### create a new PDF
```js
const win = Ti.UI.createWindow({});
const btn = Ti.UI.createButton({
title: "add"
});
btn.addEventListener("click", function() {
var pdftools = require('ti.pdftools');var page1 = {
format: "a3",
content: [{
text: "Hello",
x: 10,
y: 10,
fontSize: 20
},
{
text: "Titanium",
x: 10,
y: 30,
fontSize: 30
}
]
};var page2 = {
format: "a4",
content: [{
text: "Hello 2",
x: 10,
y: 10,
fontSize: 20
},
{
text: "Titanium 2",
x: 10,
y: 30,
fontSize: 30
}
]
};var file = pdftools.createPDF({
pages: [page1, page2]
});if (file != null) {
var intent = Ti.Android.createIntent({
action: Ti.Android.ACTION_VIEW,
type: "application/pdf",
data: file.nativePath
});
var open = Ti.Android.createIntentChooser(intent, "open pdf");
Ti.Android.currentActivity.startActivity(open);
}
})
win.add(btn);
win.open();
```#### Convert PDF to image
```js
var pdftools = require('ti.pdftools');
const win = Ti.UI.createWindow({});
const img = Ti.UI.createImageView({});var f1 = Ti.Filesystem.getFile(Ti.Filesystem.resourcesDirectory, "1.pdf");
pdftools.addEventListener("image", function(e) {
img.image = e.image;
})var file = pdftools.pdfToImage(f1);
win.add(img);
win.open();
```## Methods
method
description
parameter
return
merge
will merge multiple PDF into one
Array of PDF files
null or TiBlobimagesToPdf
will merge multiple images into a PDF
Array of image files
null or TiBlobcreatePDF
will create a new PDF
Array of page objects: pages: [page, page]
page object:{format: "a4", content: [{ text: "Hello", x: 10, y: 10, fontSize: 20}]}
null or TiBlobpdfToImage
will convert PDF pages to images. Fires the `image` event with `e.image`
File
-## Events
* `image`: returns `e.image` for every PDF page.
## Author
* Michael Gangolf (@MichaelGangolf / Web)