Advertisement
Guest User

Untitled

a guest
Aug 17th, 2017
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package {
  2.     import flash.display.DisplayObject;
  3.     import flash.display.Sprite;
  4.     import flash.display.StageAlign;
  5.     import flash.display.StageScaleMode;
  6.     import flash.events.Event;
  7.     import flash.events.MouseEvent;
  8.     import flash.filesystem.File;
  9.     import flash.filesystem.FileMode;
  10.     import flash.filesystem.FileStream;
  11.     import flash.utils.ByteArray;
  12.    
  13.     import org.alivepdf.display.Display;
  14.     import org.alivepdf.fonts.*;
  15.     import org.alivepdf.layout.*;
  16.     import org.alivepdf.pages.Page;
  17.     import org.alivepdf.pdf.PDF;
  18.     import org.alivepdf.saving.Method;
  19.    
  20.     import qnx.ui.buttons.CheckBox;
  21.     import qnx.ui.buttons.LabelButton;
  22.     import qnx.ui.text.TextInput;
  23.  
  24.     public class fishyPDFGen extends Sprite {
  25.         private var pdf:PDF;
  26.         private var file:File = File.documentsDirectory.resolvePath("../documents/");
  27.         private var newPage:Page;
  28.         private var myCoreFont:IFont;
  29.         private var suckaFish:TextInput;
  30.         private var fileName:TextInput;
  31.         private var randomInput:TextInput;
  32.         private var gimmieChex:CheckBox;
  33.         private var fs:FileStream;
  34.        
  35.         public function fishyPDFGen() {
  36.             super();
  37.            
  38.             // support autoOrients
  39.             stage.align = StageAlign.TOP_LEFT;
  40.             stage.scaleMode = StageScaleMode.NO_SCALE;
  41.            
  42.             drawInputs();
  43.         }
  44.         private function drawInputs():void {   
  45.             fileName = new TextInput();
  46.             fileName.prompt = "File Name";
  47.             fileName.setPosition(175, 100);
  48.             fileName.width = 625;
  49.             this.addChild(fileName);
  50.            
  51.             suckaFish = new TextInput();
  52.             suckaFish.prompt = "Sucka Fish!";
  53.             suckaFish.setPosition(175, 150);
  54.             suckaFish.width = 300;
  55.             this.addChild(suckaFish);
  56.            
  57.             randomInput = new TextInput();
  58.             randomInput.prompt = "RANDOM INPUT!";
  59.             randomInput.setPosition(500, 150);
  60.             randomInput.width = 300;
  61.             this.addChild(randomInput);
  62.            
  63.             gimmieChex = new CheckBox();
  64.             gimmieChex.label = "Join Mailings?";
  65.             gimmieChex.setPosition(175, 200);
  66.             gimmieChex.width = 200;
  67.             this.addChild(gimmieChex);
  68.            
  69.             var createPDF:LabelButton = new LabelButton();
  70.             createPDF.label = "Create PDF";
  71.             createPDF.setPosition(421, 250);
  72.             createPDF.addEventListener(MouseEvent.CLICK, generatePDF);
  73.             this.addChild(createPDF);
  74.         }
  75.         public function generatePDF(e:MouseEvent):void {
  76.             pdf = new PDF(Orientation.PORTRAIT, Unit.MM, Size.LETTER);
  77.             pdf.setDisplayMode(Display.FULL_PAGE, Layout.SINGLE_PAGE);
  78.             newPage = new Page(Orientation.PORTRAIT, Unit.MM, Size.LETTER);
  79.             pdf.addPage(newPage);
  80.             myCoreFont = new CoreFont(FontFamily.TIMES);
  81.             pdf.setFont(myCoreFont, 12);
  82.             pdf.addText("Suckafish: " + suckaFish.text, 10, 10);
  83.             pdf.addText("Bigger Input: " + randomInput.text, 10, 20);
  84.             pdf.addText("Join List: " + gimmieChex.selected, 10, 30);
  85.             fs = new FileStream();
  86.             fs.open(file.resolvePath(fileName.text + ".pdf"), FileMode.WRITE);
  87.            
  88.             var bytes:ByteArray = pdf.save(Method.LOCAL);
  89.             fs.writeBytes(bytes);
  90.             fs.close();
  91.            
  92.         }
  93.     }
  94. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement