Select to view content in your preferred language

How to Improve the quality of PDF

863
0
01-26-2012 04:17 AM
ionarawilson1
Deactivated User
Hello guys,

I am very new to Flex and Action Script and I am working to finish a project that other person created. The problem that I am having now is how to create good quality PDFs. The website has a map, charts and an advanced data grid, all connected and all interactive.  There are many tabs on the Advanced Data Grid that need to be displayed in many tables in the PDF. Do you guys have any suggestions on how I can improve the quality of the image? II dont need to have the map or the chart (although it would be nice to have at least the charts) but I need to have the tables. Do  yo have any suggestions to improve it? The PDF just does not look good at all. Here is the excerpt from the mxml containing all the code to create the PDF:

//add the image to a displayObject     //

 
   private function createImgForPDF(source:IBitmapDrawable):DisplayObject {
   
    var imgObj:SWFLoader = new SWFLoader();
    var bmData:BitmapData;
   
    var hBox:HBox = new HBox();       
   
    bmData = ImageSnapshot.captureBitmapData(source);
   
    imgObj.height = bmData.height;
    imgObj.width = bmData.width;
   
    var bitmap:Bitmap = new Bitmap(bmData);
    imgObj.source = bitmap;
   
    //add the image to a displayObject
    //if not, no image appears on the PDF
    hBox.width = bmData.height;
    hBox.height = bmData.width;
    hBox.addChild(imgObj);
   
    return imgObj;
   
   }     
  
  
   private function doPrintPDF():void {    
   
    CursorManager.setBusyCursor();
   
    var myPDF:PDF = new PDF(Orientation.LANDSCAPE, Unit.MM, Size.LETTER);
    myPDF.setDisplayMode(Display.FULL_WIDTH);
    //changed the display from display.default
   
    [Embed(source="assets/TFS Logo.jpg", mimeType="application/octet-stream" )]
    var jpgBytes:Class;
   
    myPDF.addPage();            
    myPDF.setFont(FontFamily.ARIAL, "B", 14);
    myPDF.addText("Texas Forestry Economic Impacts Analysis Report by County", 10, 10);
   
    myPDF.lineStyle(new RGBColor (0x000000), 1, .3, 1,CapsStyle.SQUARE, JointStyle.MITER );
    //myPDF.drawRect(new Rectangle (10,12,85,115));  
   
   
    /* mainMap.scaleBarVisible = false;
    mainMap.zoomSliderVisible = false;
    mainMap.panArrowsVisible = false;      
   
    myPDF.addImage(mainMap,10,27,85,100,"JPG",400,1,ResizeMode.NONE,BlendMode.NORMAL,true,"");
    mainMap.zoomSliderVisible = true;
    mainMap.scaleBarVisible = true;
    mainMap.panArrowsVisible = false;
     */
    myPDF.setFont(FontFamily.ARIAL, "B",9);
   
    myPDF.addText("Industry Output (million $)", 105, 20); 
    var displayObjectChart:DisplayObject;
    displayObjectChart = createImgForPDF(demoChart);
    myPDF.addImage(displayObjectChart,10,25,150,90,"PNG",300,1,ResizeMode.NONE,BlendMode.NORMAL,true,"");
   
    var displayObjectChartLen:DisplayObject;
    displayObjectChartLen = createImgForPDF(demoLegend);
    myPDF.addImage(displayObjectChartLen,230,110,35,5,"PNG",300,1,ResizeMode.NONE,BlendMode.NORMAL,true,"");   
   
    myPDF.addText("Employment (jobs)", 190, 20);   
    var displayObjectChart0:DisplayObject;
    displayObjectChart0 = createImgForPDF(demoChart0);
    myPDF.addImage(displayObjectChart0,10,120,200,90,"PNG",300,1,ResizeMode.NONE,BlendMode.NORMAL,true,"");
   
   /*  var displayObjectChartLen0:DisplayObject;
    displayObjectChartLen0 = createImgForPDF(demoLegend0);
    myPDF.addImage(displayObjectChartLen0,195,120,40,10,"PNG",300,1,ResizeMode.NONE,BlendMode.NORMAL,true,"");  */
   
    myPDF.addPage();
    myPDF.setFont(FontFamily.ARIAL, "B",9);
   
    myPDF.addText("Forestry", 10, 50);   
    var displayObjectGrid:DisplayObject;
    displayObjectGrid = createImgForPDF(resultsGrid);
    myPDF.addImage(displayObjectGrid,10,25,240,130,"PNG",300,1,ResizeMode.NONE,BlendMode.NORMAL,true,"");
   
    myPDF.setFont(FontFamily.ARIAL, "B", 7);   
    myPDF.addText("Page 1 of 3", 130, 205); 
    myPDF.addImageStream(new jpgBytes() as ByteArray, 225,195,40,15,1);
   
    myPDF.addPage();
    myPDF.setFont(FontFamily.ARIAL, "B", 9);
   
    var displayObjectGridL:DisplayObject;
    tn.selectedIndex = 1;
    tn.validateNow();
    displayObjectGridL = createImgForPDF(Logging);   
   
    var displayObjectGridPP:DisplayObject;
    tn.selectedIndex = 2;
    tn.validateNow();
    displayObjectGridPP = createImgForPDF(PrimaryP);
   
    var displayObjectGridPS:DisplayObject;
    tn.selectedIndex = 3;
    tn.validateNow();
    displayObjectGridPS = createImgForPDF(PrimaryS);   
   
    myPDF.addText("Logging", 10, 10);   
    myPDF.addImage(displayObjectGridL,10,15,180,50,"PNG",300,1,ResizeMode.NONE,BlendMode.NORMAL,true,"");
   
    myPDF.addText("Primary Paper and Paperboard Products", 10, 72);   
    myPDF.addImage(displayObjectGridPP,10,77,180,50,"PNG",300,1,ResizeMode.NONE,BlendMode.NORMAL,true,"");
   
    myPDF.addText("Primary Solid Wood Products", 10, 132);   
    myPDF.addImage(displayObjectGridPS,10,137,180,50,"PNG",300,1,ResizeMode.NONE,BlendMode.NORMAL,true,"");
   
    myPDF.setFont(FontFamily.ARIAL, "B", 7);   
    myPDF.addText("Page 2 of 3", 130, 205); 
    myPDF.addImageStream(new jpgBytes() as ByteArray, 225,195,40,15,1);
   
    myPDF.addPage();
    myPDF.setFont(FontFamily.ARIAL, "B", 9);
   
    var displayObjectGridSP:DisplayObject;
    tn.selectedIndex = 4;
    tn.validateNow();
    displayObjectGridSP = createImgForPDF(SecondaryP);   
   
    var displayObjectGridSS:DisplayObject;
    tn.selectedIndex = 5;
    tn.validateNow();
    displayObjectGridSS = createImgForPDF(SecondaryS);
   
    var displayObjectGridT:DisplayObject;
    tn.selectedIndex = 6;
    tn.validateNow();
    displayObjectGridT = createImgForPDF(Totals);   
   
    myPDF.addText("Secondary Paper and paperboard Products", 10, 10);   
    myPDF.addImage(displayObjectGridSP,10,15,180,50,"PNG",300,1,ResizeMode.NONE,BlendMode.NORMAL,true,"");
   
    myPDF.addText("Secondary Solid Wood Products", 10, 72);   
    myPDF.addImage(displayObjectGridSS,10,77,180,50,"PNG",300,1,ResizeMode.NONE,BlendMode.NORMAL,true,"");
   
    myPDF.addText("Totals", 10, 132);   
    myPDF.addImage(displayObjectGridT,10,137,180,50,"PNG",300,1,ResizeMode.NONE,BlendMode.NORMAL,true,""); 
   
    myPDF.setFont(FontFamily.ARIAL, "B", 7);   
    myPDF.addText("Page 3 of 3", 130, 205); 
    myPDF.addImageStream(new jpgBytes() as ByteArray, 225,195,40,15,1);
   
    CursorManager.removeBusyCursor();
   
    var bytes:ByteArray = myPDF.save(Method.LOCAL, Download.ATTACHMENT);
    var f:FileReference = new FileReference();
    f.save(bytes,"TexasForestryEconomicImpactReportbyCounty.pdf");
   
   
   
   
   }[ATTACH=CONFIG]11447[/ATTACH]
Tags (2)
0 Kudos
0 Replies