gdtiti / alivepdf

Automatically exported from code.google.com/p/alivepdf
0 stars 0 forks source link

alivePDF 1.4.4 and MDM Zinc 3.0 saving PDF with Image #70

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
Hi there,

I have a problem with alivePDF 1.4.4 and MDM Zinc 3.0 
I use alivePDF with Flash CS3 (AS3) 

Without an image added to the PDF everything work fine, here my example code:

// zinc lib
import mdm.*;

// alive lib
import org.alivepdf.pdf.PDF;
import org.alivepdf.images.ImageFormat;
import org.alivepdf.drawing.DashedLine;
import org.alivepdf.display.*
import org.alivepdf.layout.*;
import org.alivepdf.colors.*;
import org.alivepdf.transitions.Transition;
import org.alivepdf.fonts.FontFamily;
import org.alivepdf.transitions.Dimension;
import org.alivepdf.display.PageMode;
import org.alivepdf.fonts.Style;
import org.alivepdf.viewing.*;
import org.alivepdf.saving.Download;
import org.alivepdf.saving.Method;
import org.alivepdf.drawing.Blend;
import org.alivepdf.drawing.Caps;
import org.alivepdf.drawing.Joint;

//flash lib
import flash.utils.ByteArray;

mdm.Application.init(this, onInit);

function onInit():void {
        // start application...

    // create a simple PDF
    var myPDF:org.alivepdf.pdf.PDF = new org.alivepdf.pdf.PDF (
Orientation.PORTRAIT,
Unit.MM, Size.A4 );

    myPDF.setDisplayMode( Display.FULL_PAGE, Layout.SINGLE_PAGE ); 
    myPDF.setTitle("Test PDF Sheet");

    myPDF.addPage();
    myPDF.setFont( FontFamily.ARIAL, Style.BOLD );
    myPDF.setFontSize ( 24 );
    myPDF.addText ('Test PDF Sheet with alivePDF and ZINC', 25, 30);

    var pdfByteBuffer:ByteArray = myPDF.save ( Method.LOCAL);   
    // saves the new pdf in the same dir as the exe is. 
    mdm.FileSystem.saveFile("ZincPDFTest.pdf",pdfByteBuffer.toString());            

}

Put this code in the timeline 
(follow the instructions for installation etc on MDM Zinc Homepage)

if i add the line:
myPDF.addImage ( image, 0, 30, 0, 0, ImageFormat.JPG, 100, 1 );

this image is loaded with URLLoader before i add it into the pdf

after my "addText" line.

the application crashes and no pdf is written.
befor i used ZINC I used the same creation code from above with AIR 1.1
only the writing file stuff was different and taken form your example.
Within Air everythink works fine PDF with my text and image was flawless
created.

Original issue reported on code.google.com by tohkli...@googlemail.com on 24 Jul 2008 at 2:32

GoogleCodeExporter commented 9 years ago
Ok I solved the problem,
here my example how it works savinging an alivePDF with MDM Zinc:

replace the line from above:
mdm.FileSystem.saveFile("ZincPDFTest.pdf",pdfByteBuffer.toString());    

with the following code:

var dataString = "";
//converts the byteArray into the format needed by MDM BinaryFile
for (var i=0; i< pdfByteBuffer; i++) {
    if (i>0) {
        dataString = dataString +"|";
    }
    dataString = dataString + pdfByteBuffer[i]; 
}

// set data
mdm.FileSystem.BinaryFile.setData(dataString);
// now write the file on your HD
mdm.FileSystem.BinaryFile.writeData("ZincPDFTestBinary.pdf");

and now it works even with included image data.

Original comment by tohkli...@googlemail.com on 25 Jul 2008 at 8:37

GoogleCodeExporter commented 9 years ago
Hi,

Happy it works now :)

Do you think of any features AlivePDF could have to make life easier for you 
guys
working with Zinc ?

let me know !

best,

Thibault

Original comment by thibault.imbert on 26 Jul 2008 at 7:59

GoogleCodeExporter commented 9 years ago
[deleted comment]
GoogleCodeExporter commented 9 years ago
hi there,

worked. But went to open the newly created .pdf and I get an error saying .pdf 
couldn't be parsed!!! any ideas 
guys.

thanks

Dan

Original comment by hucklebo...@gmail.com on 6 Apr 2009 at 2:35

GoogleCodeExporter commented 9 years ago
Hello, 

Bow from SlideRocket here!
I am using this solution as well, and I noticed a small error in the 'for' 
control
statement definition.

In the line

for (var i=0; i< pdfByteBuffer; i++) {

the middle boolean expression should be 

i < pdfByteBuffer.length 

This could be one reason why the resulting PDF file is 'unreadable'. because its
EMPTY! The loop never executes :/.

Original comment by barcher4...@gmail.com on 7 Nov 2009 at 12:10

GoogleCodeExporter commented 9 years ago
Hey there, Bow again!

Sadly, this solution does NOT work well for large PDF files or any Large 
ByteArray,
since you have to loop through it byte by byte using ActionScript. A 6 page PDF 
with
images (hi res), for example will lock up flash player for about 1 minute and a 
half
while it loops through the byte array. 

This solution is NOT scalable unfortunately :/.

Original comment by barcher4...@gmail.com on 7 Nov 2009 at 12:15