Reputation: 31
i'm pulling my hair out. need to print html generated invoices from a distant server, using
the print class, event if bitmap is set as false, will render the invoice a bitmap. at least the text is blurry and not usable. alivepdf could be a solution but i need to print straight, not save the pdf locally. i don't even understand, giving the fact this print class sucks badly, flex won't allow a simple javascript print function from the remote page.
i beg for some help here !
thank you
Upvotes: 0
Views: 1401
Reputation: 42332
Why don't you use the browser to print?
Here's an example:
Put this in your index.html template:
<script language="JavaScript">
function printPage(htmlPage)
{
var w = window.open("about:blank");
w.document.write(htmlPage);
w.print();
w.close();
}
</script>
Put this in your Flex Project. What you're doing is checking to see if you have access to ExternalInterface to have access to the browser. Then you're going to use the ExternalInterface static method of "call" to call the javascript:
import mx.controls.Alert;
import flash.external.ExternalInterface;
public static function PrintHtmlPage(pHtmlPage:String):void
{
if (ExternalInterface.available)
{
try
{
ExternalInterface.call("printPage",pHtmlPage);
}
catch (error:SecurityError) { Alert.show("Security Error"); }
catch (error:Error) { Alert.show("Error");}
}
else { Alert.show("ExternalInterface not avalible");}
}
Now the user can print clean html from their browser!
http://cookbooks.adobe.com/post_How_to_print_in_Flex_using_browser_capabilities-11468.html
EDIT:
If you are using AIR and need to do this, you can try using AlivePDF and following this tutorial:
Upvotes: 1