0

I'm creating an ADOBE AIR application.

I have some text boxes and labels in my Hbox. I want to generate a pdf and have to add that hbox into that pdf ..lot of people telll about alivepdf . I searched ,but have not seen a demo..If you have any idea ,Please share me ,or advice me..Thanks

Naju
  • 1,541
  • 7
  • 27
  • 59
  • 1
    See http://blog.unthinkmedia.com/2008/09/05/exporting-pdfs-in-flex-using-alivepdf/ for a demo. Please keep in mind that it is fairly easy to generate PDFs in Flash, but viewing them is next to impossible. – Josh Jan 31 '13 at 16:05
  • @Apocalyptic0n3 Is viewing PDF's in flash really impossible? I recently did some unrelated work on an app that had a feature to let the user view PDF's. The PDF viewer was quite a fancy, full featured component. It was used in an AIR app, perhaps that is what made it possible? – Sunil D. Jan 31 '13 at 17:29
  • 1
    @SunilD. Any chance you could tell me how it was done? I've tried unsuccessfully to do it through any route that did not use StageWebView (iOS only) or HTMLLoader (desktop only, sluggish performance, requires Acrobat). It's possible... sorta. You have to use native applications to do it, unless you convert the PDF to a SWF (like you would for FlexPaper) – Josh Jan 31 '13 at 18:16
  • @Apocalyptic0n3 sorry I worked on that project briefly as a consultant, we were adding new functionality and I never took a look at that part of the code. I think you're right, they must have integrated the desktop AIR app with Acrobat (which might explain why that component was so "feature rich" and could zoom, and do other fancy things). Thanks for explaining! – Sunil D. Jan 31 '13 at 18:21

1 Answers1

0

I think it could help you.

This are my Air-application and the PDF-file.

enter image description here

enter image description here

//source

<?xml version="1.0" encoding="utf-8"?>
<s:WindowedApplication xmlns:fx="http://ns.adobe.com/mxml/2009" 
                   xmlns:s="library://ns.adobe.com/flex/spark" 
                   xmlns:mx="library://ns.adobe.com/flex/mx">
<fx:Script>
    <![CDATA[
        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;

        protected function onBtnGeneratePDF(event:MouseEvent):void
        {
            var pdf:PDF = new PDF( Orientation.PORTRAIT, Unit.MM, Size.A4 ); 
            pdf.setDisplayMode( Display.FULL_PAGE, Layout.SINGLE_PAGE );

            var newPage:Page = new Page ( Orientation.PORTRAIT, Unit.MM, Size.A4 );
            pdf.addPage( newPage );

            pdf.addText("This is my PDF from AdobeFlex", 5, 10);

            pdf.addImage(hgMain, null, 5, 10);

            var fs:FileStream = new FileStream();  
            var file:File = File.desktopDirectory.resolvePath("testPage.pdf");   
            fs.open(file, FileMode.WRITE);   
            var bytes:ByteArray = pdf.save(Method.LOCAL);   
            fs.writeBytes(bytes);   
            fs.close();
        }
    ]]>
</fx:Script>

<s:HGroup id="hgMain" x="10" y="10" width="439" height="161">
    <s:Label text="MyLabel_01"/>
    <s:TextArea width="133" height="116" contentBackgroundColor="#E6B3B3" fontStyle="italic"
                text="MyTextArea"/>
    <s:Label fontWeight="bold" text="MyLabel_02"/>
    <s:TextArea width="127" height="69" contentBackgroundColor="#CED4F2" fontSize="15"
                fontWeight="bold" text="MyTextArea"/>
</s:HGroup>
<s:Button x="10" y="179" label="Generate PDF" click="onBtnGeneratePDF(event)"/>

</s:WindowedApplication>
Anton
  • 4,544
  • 2
  • 25
  • 31