How To Create PDF in Flex 3

1. Creating PDF in Flex 3, Here is the Application code

Pre Requeste:# AlivePdf.swc [ include in ur Flex Project By dropping into libs folder ] Download AlivePDF

You can find answer in this post, for the question ” How to create PDF from Flex 3″ or “By Capturing Screen How to create PDF from Flex 3″

<?xml version=”1.0″ encoding=”utf-8″?>
<mx:Application xmlns:mx=”; layout=”absolute”>

import org.alivepdf.saving.Download;
import org.alivepdf.saving.Method;
import org.alivepdf.layout.Size;
import org.alivepdf.layout.Unit;
import org.alivepdf.layout.Orientation;
import org.alivepdf.pdf.PDF;
import org.alivepdf.pages.Page;
import org.alivepdf.images.ResizeMode;
import org.alivepdf.images.ImageFormat;

private var myPDF:PDF ;

private function GeneratePDF(event:MouseEvent):void{
myPDF = new PDF(Orientation.PORTRAIT, Unit.MM, Size.A4);
var newPage:Page=new Page(Orientation.PORTRAIT, Unit.MM, Size.A4);
myPDF.addImage(testPanel, 5 ,5, testPanel.width,testPanel.height, ImageFormat.PNG, 0, 1, ResizeMode.FIT_TO_PAGE);, “http://localhost:8080/FlexPDF/servlet/ScreenShotPDFServlet&#8221;, Download.INLINE, “myPDF.pdf”);
// You can modify the code to position the captured image in generated PDF

<mx:Panel x=”20″ y=”10″ width=”250″ height=”200″ layout=”absolute” id=”testPanel” title=”testPanel”>
<mx:Button x=”84″ y=”128″ label=”Generate PDF” click=”GeneratePDF(event);”/>


2. Here is Java Servlet Code, which generates PDF …


import javax.servlet.ServletException;
import javax.servlet.ServletInputStream;
import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class ScreenShotPDFServlet extends HttpServlet {

public ScreenShotPDFServlet() {

public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
doPost(request, response);

public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {

response.setHeader(“Content-disposition”,”inline; filename=myPDF.pdf” );

int contentLength = request.getContentLength();
byte[] byteArray = new byte[contentLength];
ServletOutputStream sos = response.getOutputStream();
ServletInputStream  sis  = request.getInputStream();


3. web.xml  entry of the servlet




1. This  servlet generates PDF from flex client with the captured ScreenShot ..

2. GET method called From Flex Client


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s