6 Replies Latest reply on Aug 23, 2011 4:38 AM by Kamil_Pullo

    Add Image in PDF with Alive PDF

    Kamil_Pullo

      Hi community, i need help to add a image in PDF with Alive PDF.

      I try it so:

       

      [Embed(source="bilder/PDFLogo.png", mimeType="application/octet-stream" )]

       

      protected var PDFLogos:Class;

      printPDF.addImageStream(new PDFLogos() as ByteArray,15,5,190,0);

       

      But they gives me an error when i compiling.

      When i try it so

       

      printPDF.addImageStream(new PDFLogos() as ByteArray,ColorSpace.DEVICE_RGB)

       

      then i can compile but when i click on the button then can´t download the pdf please help

        • 1. Re: Add Image in PDF with Alive PDF
          Daniel Naranjo

          Hi Kamil,

           

          Hello, I attached a piece of code we use, including statements, etc.. In my case, I captured all the content is a canvas to create a report of a bar chart or pie chart.

           

               import org.alivepdf.display.*;
               import org.alivepdf.fonts.*;
               import org.alivepdf.layout.*;
               import org.alivepdf.pdf.*;
               import org.alivepdf.saving.*;

           

          protected var pdf:PDF;

           

          // declared of logo or imagen on top of the PDF's document.
          [Embed(source="assets/logo.jpg", mimeType="application/octet-stream" )]
          protected var jpgBytes:Class;

          protected function savePDF(event:MouseEvent): void {
                  pdf = new PDF(Orientation.LANDSCAPE, Unit.MM, Size.LETTER);
                  pdf.setDisplayMode(Display.FULL_WIDTH);
                  pdf.addPage();
                  pdf.addImageStream(new jpgBytes() as ByteArray, 10, 10, 0, 0, 1);
                    
                  pdf.setFont(FontFamily.ARIAL, Style.NORMAL, 12);
                  pdf.addText("Grafico de Rata de Fallas", 100, 40); // title
                  pdf.addImage(imprimirRata, 50, 50, 200, 150); // captured canvas with charts
          //      pdf.addImage(leyendaImprimir, 50, 120, 20,20); // captured leyend of charts
                    
                  pdf.addText("RTP Software. Modulo de Score Card.", 10, 200); // header of the document
                  pdf.addText("Creado: " + new Date(), 180, 200); // Add the created date as a leyend or footer on document
                 
                  var fs:FileStream = new FileStream();
                  var file: File = File.desktopDirectory.resolvePath("rtp-ratadefallas.pdf"); // Name of the file
                  fs.open(file, FileMode.WRITE);
                  fs.writeBytes(pdf.save(Method.LOCAL));
                  fs.close();
                  Alert.show("El reporte ha sido generado", "Informacion"); // Confirmation message as a pop-up
                  }

           

           

           

          • 2. Re: Add Image in PDF with Alive PDF
            Kamil_Pullo Level 1

            thats the same that i write? but this not works don´t know why

            • 3. Re: Add Image in PDF with Alive PDF
              Daniel Naranjo Level 1

              Do you download the alivepdf.swc and unzip into "libs" folder? Go to: Project > Propeties > Flex Build Paths > "Library path" tab > Expand: "libs"

               

              Best regards,

               

              Daniel N.

              • 4. Re: Add Image in PDF with Alive PDF
                Kamil_Pullo Level 1

                hi, yes i have alivepdf.swc in libs folder. Print pdf is no problem i have only problem to add a image

                • 5. Re: Add Image in PDF with Alive PDF
                  123appi

                  Hi,

                   

                  Please go through this code.

                   

                  fileRefPDF = new PDF(Orientation.LANDSCAPE, Unit.INCHES, Size.TABLOID);

                  fileRefPDF.addPage();

                  fileRefPDF.addImage(component1.panelCan); // parameter of addImage method should be id or instance of image.

                  var bytes:ByteArray = fileRefPDF.save(Method.LOCAL);

                  var file:FileReference = new FileReference();

                  file.save(bytes,"Untitled.pdf");

                   

                   

                   

                  Thanks

                     Appi

                  • 6. Re: Add Image in PDF with Alive PDF
                    Kamil_Pullo Level 1

                    Thanks for answer. How i can make a instance of a image? I have only the image url in string there i get from my javascript.

                    Thanks

                    Kamil