2

I have an app that is built from Flash CS5.5, exported using AIR3.1 and distributed through the Enterprise setup from Apple (allows me to bypass appstore approval).

I'm now trying to have a PDF (generated using AlivePDF) exported somehow into the iPad, either into iBooks or just have it opened in Safari.

This is what I'm using for my desktop version of the app. Although the scripting is very messy it gets the job done. I just don't know how to convert this over and make it work on an iPad

//Populate listbox component from array

function noEmpty(item:*, index:int, array:Array):Boolean{
  return item != undefined;
}

for(var i:int = 0; i < MovieClip(root).selectedProducts.length; i++) {
    if(MovieClip(root).selectedProducts[i] != undefined){
        selectedProductsText.dataProvider.addItem({label: MovieClip(root).selectedProducts[i]});
    }
}

var myTextFormat:TextFormat = new TextFormat();
myTextFormat.size = 20;
myTextFormat.font = "Arial";
myTextFormat.color = 0x000000;
myTextFormat.leftMargin = 30;
selectedProductsText.rowHeight = 40;

selectedProductsText.setRendererStyle("textFormat", myTextFormat);

//AlivePDF, generate PDF

import org.alivepdf.pdf.PDF;
import org.alivepdf.layout.Orientation;
import org.alivepdf.layout.Size;
import org.alivepdf.layout.Unit;
import org.alivepdf.display.Display;
import org.alivepdf.saving.Method;
import org.alivepdf.fonts.FontFamily;
import org.alivepdf.fonts.Style;
import org.alivepdf.colors.RGBColor;
import com.adobe.images.*;

function convertString(_value:String):String
{
 var returnString:String = "";
 var _chr:String = String.fromCharCode(13);
 var tempArray:Array = _value.split(_chr);
 for(var i:uint = 0; i < tempArray.length; i++)
  {
   returnString += tempArray[i] + "\n";
  }   
  return returnString;
}

var pdf:PDF = new PDF(); 

pdf.setDisplayMode (Display.REAL);     
pdf.addPage(); 

pdf.writeText(7, convertString(  MovieClip(root).selectedProducts.filter(noEmpty).join('\n')    ));

var buffer:ByteArray = pdf.save(Method.LOCAL); 
var file:FileReference = new FileReference(); 

//save PDF button

btnPdf.addEventListener( MouseEvent.CLICK, generatePDF );

function generatePDF ( e:MouseEvent )
{
    file.save(buffer, "Product Selection List.pdf");
}
user1172903
  • 101
  • 1
  • 11
  • What part doesn't work specifically on ios? (Off-topic but I couldn't find a private message option on stack overflow): How has Air 3 for ios worked for you? I've been considering giving it a try myself. – user1103976 May 04 '12 at 03:57
  • user1103976: Just the fact that I have no idea where to store a file on an iDevice. Apple aren't very open with their OS, everything is a pain in the ass. AIR3 on the iOS seems to run ok though. It's the only means I have of developing apps without learning Objective C. Performance isn't as great as a desktop/laptop obviously, but if you keep it optimised it's not too bad. – user1172903 May 08 '12 at 01:15

1 Answers1

0

Having done some work with AIR for iOS I would say your issue will be that you need to change how the file is saved and stored on the device.

You need to save the file to the apps storage directory with something like this that I used to store a jpg image:

f = File.documentsDirectory.resolvePath(imagename+".jpg");      
stream = new FileStream();
stream.open(f, FileMode.WRITE);                                         
j = new JPGEncoder(80);     
bytes = new ByteArray();
bytes = j.encode(snapShot.bitmapData);
stream.writeBytes(bytes, 0, bytes.bytesAvailable);
stream.close();

I'm not sure how or if it's even possible through AIR to send the pdf to iBooks. You could use StageWebView within your app though to display the PDF.

crooksy88
  • 3,849
  • 1
  • 24
  • 30
  • Thanks, that helps somewhat. I didn't think it was possible either but I was just hoping someone might prove me wrong. – user1172903 May 08 '12 at 01:16