header
ask question
Click here to ask Question Now Its free No registration required. Flash, Flex, Flash Media Server, ActionScript,Adobe Air. Most questions receive a response in an hour.
Poornima
Points:0
Posts:0

12/1/2011 3:48:44 AM

Title: printing html content to pdf in flex


Hi,

In my application there are multiple windows in which html documents are opened......

Now i want to give the user to print the html document....

Suppose
---------------------------
<mx:HTML id="myHtml" location="C://test.html" width="100%" height="70%"/>


I thought of not using native print API because it cannot handle complex printing...
SO i have moved on using alive pdf to generate pdf and then print....is this right.

Can u suggest me right option for printing.....?????????

This is a simple example i am using

The content in html component should be exactly same i.e same font size, family, style etc
while printing how to achieve this pls help me out if i am wrong in any ways......



<?xml version="1.0" encoding="utf-8"?>
<s:WindowedApplication xmlns:fx="http://ns.adobe.com/mxml/2009" 
					   xmlns:s="library://ns.adobe.com/flex/spark" 
					   xmlns:mx="library://ns.adobe.com/flex/mx">
	<fx:Declarations>
		<!-- Place non-visual elements (e.g., services, value objects) here -->
	</fx:Declarations>
	
	<fx:Script>
		<![CDATA[
			import org.alivepdf.display.Display;
			import org.alivepdf.fonts.FontFamily;
			import org.alivepdf.fonts.Style;
			import org.alivepdf.layout.Orientation;
			import org.alivepdf.layout.Size;
			import org.alivepdf.layout.Unit;
			import org.alivepdf.pdf.PDF;
			import org.alivepdf.saving.Download;
			import org.alivepdf.saving.Method;
			
		private function hw():void{
			var o : Object = myHtml.htmlLoader.window.document.getElementsByTagName("html")[0];
			trace( o.textContent );
			trace( o.innerText );
			trace( o.innerHTML );	
			var str:String =  o.innerText ;
			var p:PDF = new PDF(Orientation.PORTRAIT, Unit.MM, Size.A4);
			p.setDisplayMode (Display.FULL_PAGE);
			p.addPage(); 
			p.setFont(FontFamily.ARIAL); 
			p.writeText(10,str); 
			savePdf(p, "hw.pdf");
			//p.save( Method.REMOTE, "http://alivepdf.bytearray.org/?p=440", Download.ATTACHMENT, "test.pdf" );
		}
		
		private function savePdf(p:PDF, fileName:String):void{
		var ba:ByteArray = p.save(Method.LOCAL);
		var fs:FileStream = new FileStream();
		var f:File = File.desktopDirectory.resolvePath(fileName);
		fs.open(f, FileMode.WRITE);
		try{
		fs.writeBytes(ba);
		} catch (e:*){}
		fs.close();
		}
			
	]]>
</fx:Script>
	
	<s:VGroup width="100%" height="100%">
		<mx:Button label="Hello World!!!" click="hw()"/>
		<mx:HTML id="myHtml" location="C://test.html" width="100%" height="70%"/>
	</s:VGroup> 
	
</s:WindowedApplication>






Post your Reply
Name  

Email

Type your Reply or Answer

Are you human? What is 3+3 



Members Login

Email  
Password
Forgot Password





This website focus on: Flash | Flex | FMS | RED5 | WOWZA | Flash Media Server | Adobe AIR | ActionScript,Flash Solutions | Flash Question | Flash Answers | Flash Developers | Flash Problem, Flash Help, Flash bugs, Flash workaround | Flash Blog | Flex Question Answers | Flash Forum | Flex Development | Actionscript development | Flash development | Adobe AIR development
Copyright © 2008 AskMeFlash.com. All rights reserved. Privacy Policy | Terms & Conditions