Skip to content

Instantly share code, notes, and snippets.

@rajubd49
Created April 16, 2015 13:19
Show Gist options
  • Save rajubd49/3818b6fd00f211038551 to your computer and use it in GitHub Desktop.
Save rajubd49/3818b6fd00f211038551 to your computer and use it in GitHub Desktop.
Image to PDF convertor-screenshot to pdf - Appcelerator Titanium
var PDF = require('bencoding.pdf');
var converters = PDF.createConverters();
var win = Ti.UI.createWindow({ backgroundColor:'#fff'});
var vwContent = Ti.UI.createView({
top:0, layout:'vertical'
});
win.add(vwContent);
vwContent.add(Ti.UI.createView({
height:'50%', backgroundColor:'green', width:Ti.UI.FILL
}));
vwContent.add(Ti.UI.createView({
height:'50%', backgroundColor:'red', width:Ti.UI.FILL
}));
var goButton = Ti.UI.createButton({
title:'Make Screenshot a PDF', bottom:10, left:10, right:10, height:80
});
win.add(goButton);
goButton.addEventListener('click',function(e){
Ti.Media.takeScreenshot(function(event){
alert('ok');
var image = event.media;
var pdfBlob = converters.convertImageToPDF(image,100);
var pdfFile = Ti.Filesystem.getFile(Ti.Filesystem.applicationDataDirectory, 'text.pdf');
pdfFile.write(pdfBlob);
});
});
win.open();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment