Created
August 11, 2021 08:48
-
-
Save hansemannn/0daa788b9afdfb34a476a669b9b7ae07 to your computer and use it in GitHub Desktop.
Titanium - iOS: Create a PDF from an image
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import TiPDFMerge from 'ti.pdfmerge'; | |
const win = Ti.UI.createWindow({ | |
backgroundColor: '#fff' | |
}); | |
const btn = Ti.UI.createButton({ | |
title: 'Trigger' | |
}); | |
btn.addEventListener('click', () => { | |
// Create an image with green background and red border (to check if it matches the bounds) | |
const img = Ti.UI.createView({ backgroundColor: 'red', width: 2000, height: 1000 }); | |
img.add(Ti.UI.createView({ width: 1800, height: 800, backgroundColor: 'green' })); | |
// Generate the PDF | |
const pdf = TiPDFMerge.pdfFromImage({ image: img.toImage() }); | |
// Save it to a file | |
const file = Ti.Filesystem.getFile(Ti.Filesystem.applicationCacheDirectory, 'test.pdf'); | |
file.write(pdf); | |
// Print the path for debugging purposes | |
console.warn(file.nativePath); | |
}); | |
win.add(btn); | |
win.open(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment