Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Adobe AIR Development

Reply
Developer
JohnPinkerton
Posts: 350
Registered: ‎01-21-2011
My Device: Curve 8900 (Personal) / Bold 9650 (Work)
Accepted Solution

Generating PDF Based on Input

I'm working on creating an app for internal use at work. Users will input a variety of information using drop downs, checkboxes, text inputs, some sketching areas and even use the camera. This information will then need to be generated into a PDF. The project is being done in ActionScript.

 

I've found AlivePDF and purePDF, however it seems like these are geared towards generating a PDF client side based on predefined static input.

 

I would not be opposed to a solution that would run on a server back at the Corporate office, and generate the PDF.

 

Goal would be to find something either free or very inexpensive as this project is for a non-profit agency.

 

Any suggestions? Thanks in advance!

Developer
jtegen
Posts: 6,541
Registered: ‎10-27-2010
My Device: HTC One, PlayBook, LE Z10, DE Q10

Re: Generating PDF Based on Input

I've used AlivePDF and it does a very good job in generating PDF files. It is free. If you are a PHP backend, there is FPDF (http://www.fpdf.org/). Does a good job too. Personally, I would lean towards AlivePDF (or client side generation) unless there is just so much data that needs to be accessed on a corporate server, but even then, pulling that down to the client is one possible solution.
Developer
jtegen
Posts: 6,541
Registered: ‎10-27-2010
My Device: HTC One, PlayBook, LE Z10, DE Q10

Re: Generating PDF Based on Input

Looked at the API for purePDF. Seems very complete. Possibly more complete than AlivePDF. When I start needing this again, I will probably evaluate purePDF to see if it is better than AlivePDF.
Developer
JohnPinkerton
Posts: 350
Registered: ‎01-21-2011
My Device: Curve 8900 (Personal) / Bold 9650 (Work)

Re: Generating PDF Based on Input

jtegen, I'm actually working on setting up a test ActionScript Mobile Project (dang can we just call that ASMP from now on?! hehe) with AlivePDF.

Have you used it with the QNX components, or attached pictures/sketches to it?
Developer
jtegen
Posts: 6,541
Registered: ‎10-27-2010
My Device: HTC One, PlayBook, LE Z10, DE Q10

Re: Generating PDF Based on Input

AlivePDF is just an API to generate a PDF file. QNX should have no impact on it. Not certain about images. Cannot recall if it can take a raw bitmap or it took mx:Image.
New Developer
Adam_Cochran
Posts: 13
Registered: ‎05-11-2011
My Device: Developer - Non-User

Re: Generating PDF Based on Input

I am actually building such an app right now for a client. Since the app will be a private one (as it requires a server to run the conversion for your clients) we'll make the code open source one our clients needs are satisfied. Send me your email address and I'll keep you updated on this. (This goes for anyone)

Developer
JohnPinkerton
Posts: 350
Registered: ‎01-21-2011
My Device: Curve 8900 (Personal) / Bold 9650 (Work)

Re: Generating PDF Based on Input

[ Edited ]

Here's some quick and dirty code I made just as a test app. Build in some if statements to prompt user for a new name (or overwrite) if file exists, but works!

 

package {
	import flash.display.DisplayObject;
	import flash.display.Sprite;
	import flash.display.StageAlign;
	import flash.display.StageScaleMode;
	import flash.events.Event;
	import flash.events.MouseEvent;
	import flash.filesystem.File;
	import flash.filesystem.FileMode;
	import flash.filesystem.FileStream;
	import flash.utils.ByteArray;
	
	import org.alivepdf.display.Display;
	import org.alivepdf.fonts.*;
	import org.alivepdf.layout.*;
	import org.alivepdf.pages.Page;
	import org.alivepdf.pdf.PDF;
	import org.alivepdf.saving.Method;
	
	import qnx.ui.buttons.CheckBox;
	import qnx.ui.buttons.LabelButton;
	import qnx.ui.text.TextInput;
	
	public class fishyPDFGen extends Sprite {
		private var pdf:PDF;
		private var file:File = File.documentsDirectory;
		private var newPage:Page;
		private var myCoreFont:IFont;
		private var suckaFish:TextInput;
		private var fileName:TextInput;
		private var randomInput:TextInput;
		private var gimmieChex:CheckBox;
		private var fs:FileStream;
		
		public function fishyPDFGen() {
			super();
			
			// support autoOrients
			stage.align = StageAlign.TOP_LEFT;
			stage.scaleMode = StageScaleMode.NO_SCALE;
			
			drawInputs();
		}
		private function drawInputs():void {   
			fileName = new TextInput();
			fileName.prompt = "File Name";
			fileName.setPosition(175, 100);
			fileName.width = 625;
			this.addChild(fileName);
			
			suckaFish = new TextInput();
			suckaFish.prompt = "Sucka Fish!";
			suckaFish.setPosition(175, 150);
			suckaFish.width = 300;
			this.addChild(suckaFish);
			
			randomInput = new TextInput();
			randomInput.prompt = "RANDOM INPUT!";
			randomInput.setPosition(500, 150);
			randomInput.width = 300;
			this.addChild(randomInput);
			
			gimmieChex = new CheckBox();
			gimmieChex.label = "Join Mailings?";
			gimmieChex.setPosition(175, 200);
			gimmieChex.width = 200;
			this.addChild(gimmieChex);
			
			var createPDF:LabelButton = new LabelButton();
			createPDF.label = "Create PDF";
			createPDF.setPosition(421, 250);
			createPDF.addEventListener(MouseEvent.CLICK, generatePDF);
			this.addChild(createPDF);
		}
		public function generatePDF(e:MouseEvent):void {
			pdf = new PDF(Orientation.PORTRAIT, Unit.MM, Size.LETTER);
			pdf.setDisplayMode(Display.FULL_PAGE, Layout.SINGLE_PAGE);
			newPage = new Page(Orientation.PORTRAIT, Unit.MM, Size.LETTER);
			pdf.addPage(newPage);
			myCoreFont = new CoreFont(FontFamily.TIMES);
			pdf.setFont(myCoreFont, 12);
			pdf.addText("Suckafish: " + suckaFish.text, 10, 10);
			pdf.addText("Bigger Input: " + randomInput.text, 10, 20);
			pdf.addText("Join List: " + gimmieChex.selected, 10, 30);
			fs = new FileStream();
			fs.open(file.resolvePath(fileName.text + ".pdf"), FileMode.WRITE);
			
			var bytes:ByteArray = pdf.save(Method.LOCAL);
			fs.writeBytes(bytes);
			fs.close();
			
		}
	}
}