AIR生成PDF(不通过打印机)

新建air project,引入AlivePDF.swc 可在http://alivepdf.bytearray.org下载

  1. "1.0" encoding="utf-8"?>
  2. "http://www.adobe.com/2006/mxml" layout="absolute">
  3.     
  4.         
  5.         
  6.             import org.alivepdf.pdf.PDF;
  7.             import org.alivepdf.layout.Orientation;
  8.             import org.alivepdf.layout.Size;
  9.             import org.alivepdf.layout.Unit;
  10.             import org.alivepdf.display.Display;
  11.             import org.alivepdf.saving.Method;
  12.             import org.alivepdf.fonts.FontFamily;
  13.             import org.alivepdf.fonts.Style;
  14.             import org.alivepdf.colors.RGBColor;
  15.             import org.alivepdf.layout.Layout;
  16.             import org.alivepdf.images.ImageFormat;
  17.             import org.alivepdf.images.ResizeMode;
  18.             
  19.             public function generatePDF ( e:MouseEvent ):void
  20.             {
  21.             
  22.             var myPDF:PDF = new PDF ( Orientation.PORTRAIT, Unit.MM, Size.LETTER );
  23.         
  24.             myPDF.setDisplayMode( Display.FULL_PAGE, Layout.SINGLE_PAGE );
  25.             
  26.             myPDF.addPage();
  27.             
  28.             // add a background image
  29.             myPDF.addImage(dc_main,1,1,0,0,ImageFormat.JPG ,100,160,ResizeMode.FIT_TO_PAGE,BlendMode.DARKEN,false,"");
  30.             
  31.             
  32.             myPDF.setFont( FontFamily.HELVETICA, Style.BOLD );
  33.             myPDF.setFontSize ( 18 );
  34.             myPDF.setXY( 1040 );
  35.             myPDF.addMultiCell ( 3001"This is my PDF Headline" );
  36.             
  37.             // add text message
  38.         
  39.             myPDF.setFont( FontFamily.HELVETICA, Style.BOLD );
  40.             myPDF.setFontSize ( 14 );
  41.             myPDF.setXY( 1050 );
  42.             myPDF.addMultiCell ( 3004"This is my text....lots of text..." );
  43.             
  44.             // save PDF to the desktop
  45.             var f : FileStream = new FileStream();
  46.             var file : File = File.desktopDirectory.resolvePath("C:/MyPDF.pdf");
  47.             f.open( file, FileMode.WRITE);
  48.             var bytes : ByteArray = myPDF.save(Method.LOCAL);
  49.             f.writeBytes(bytes);
  50.             f.close();       
  51.             }
  52.    
  53.         ]]>
  54.     
  55.             "0" click="generatePDF(event)" label="Generate PDF" id="generate_btn" />
  56.  
  57.         "absolute" title="Draw On Me" backgroundColor="#ffffff" borderThicknessBottom="10" left="20" right="20" top="20" bottom="20">
  58.             "0" y="0" width="100%" height="100%" backgroundColor="#ffffff">
  59.                 "265" y="242" text="nihao"/>
  60.                 "79" y="97" id="dc_main" source="assets/LC_bottom_558x120.jpg"/>
  61.                 
  62.             
  63.  
  64.         



你可能感兴趣的:(air)