문제

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");
}
도움이 되었습니까?

해결책

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.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top