Quantcast
Channel: Appcelerator Developer Center Q&A Tag Feed (print)
Viewing all articles
Browse latest Browse all 20

Print WebView or view local html file in DocumentViewer and print

0
0

I'm trying to generate some dynamic reports in my iPad app that i need to be able to print. The reports will contain images stored on the iPad, as it'll be operated offline on occassion.

I've managed to generate a local html file and open it in a DocumentViewer, but i can't get any images to display. Here's some example code:

var fobj = Ti.Filesystem.getFile(Ti.Filesystem.applicationDataDirectory, 'test.html');
var f = Ti.Filesystem.getFile(Ti.Filesystem.resourcesDirectory, 'images/test.jpg');
var imgsrc = Ti.Filesystem.resourcesDirectory + 'images/test.jpg';
 
var htmldata = '<h1>Hello World!</h1><br>' +
'<img alt="img1" src="' + imgsrc + '" width="300" height="200"><br>' +
'<img alt="img2" src="' + imgsrc.replace('file://', 'app://') + '" width="300" height="200"><br>' +
'<img alt="img3" src="app://Resources/images/test.jpg" width="300" height="200"><br>' +
'<img alt="img4" src="images/test.jpg" width="300" height="200"><br>' +
'<img alt="img5" src="' + f.nativePath + '" width="300" height="200"><br>' +
'<img alt="img6" src="https://static.appcelerator.com/images/header/appc_logo.png" width="300" height="200"><br>';
 
fobj.write(htmldata);
 
var win = Ti.UI.createWindow();
var webview = Ti.UI.createWebView({url:fobj.nativePath});
// var webview = Ti.UI.createWebView({html:htmldata});
win.add(webview);
win.open();
 
docViewer = Ti.UI.iPad.createDocumentViewer({url:fobj.nativePath});
docViewer.show();
The images show in my web view, but not in the document viewer.

Does anyone know how i can get this to work, or is there another method to allow me to print dynamically generated reports? I need to be able to open the reports in EuroSmartz PrintCentral app so i can print on a non-Airprint wireless printer.

I had been using the PDF Generator module but it's not great with wrapping text.


Viewing all articles
Browse latest Browse all 20

Latest Images

Trending Articles





Latest Images