3 Replies Latest reply on Apr 11, 2011 2:41 PM by Shravan P

    Adding a Header and Footer on PDF using Alive PDF

    BhaskerChari Level 4

      Hi All,

       

      I haven't  worked much on Alive PDF, I want some help from you Guys...

       

      I want a sample example or code as how to exactly add a Header and Footer on all pages using Alive PDF. I have gonethrough many examples on AlivePDF but I could not find a good solution as how to add exactly a Header and Footer for all the the pages on PDF.

       

      In Header I want to add a minimum a title , logo of the company and Name of the Employee.

       

      In Footer I want to add a Date printed and the Page no...

       

       

      Thanks in advance,

      Waiting for your replies...

       

      Bhasker

        • 1. Re: Adding a Header and Footer on PDF using Alive PDF
          BhaskerChari Level 4

          Any one there help guys....Any help is really appreciable...

           

          Message was edited by: BhaskerChari

          • 2. Re: Adding a Header and Footer on PDF using Alive PDF
            BhaskerChari Level 4

            Seems like no has done this....

            • 3. Re: Adding a Header and Footer on PDF using Alive PDF
              Shravan P

              Bhaskar,

               

              Try with this example.

               

              ---------------------------------------------------------

              PdfEx.mxml

              ---------------------------------------------------------

              <?xml version="1.0" encoding="utf-8"?>

              <mx:Application

               

              xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute"

              creationComplete="init()"

              >

               

              <mx:Script>

              <![CDATA[

               

              import mx.controls.Alert;

               

              import org.alivepdf.saving.Download;

               

              import mx.graphics.codec.JPEGEncoder;

               

               

              import mx.graphics.ImageSnapshot;

               

               

              import org.alivepdf.fonts.Style;

               

              import org.alivepdf.fonts.FontFamily;

               

              import org.alivepdf.saving.Method;

               

              import org.alivepdf.layout.Size;

               

              import org.alivepdf.layout.Unit;

               

              import org.alivepdf.layout.Orientation;

               

              import org.alivepdf.pdf.PDF;

               

               

              private function init():void{

              playout.addChild(new PrintHeader());

              playout.addChild(new Content());

              playout.addChild(

              }

               

               

               

              new PrintFooter());

              private function doPrint(event:MouseEvent):void{

              playout.includeInLayout=

              true;

              playout.visible =

              "true";

               

               

              var createPDF:PDF = new PDF(Orientation.PORTRAIT, Unit.MM, Size.A4);

               

              var image:ImageSnapshot = ImageSnapshot.captureImage(playout, 15, new JPEGEncoder());

               

              createPDF.addPage();

              createPDF.addImageStream(image.data, 0, 0, 500, 500);

               

              var ba:ByteArray = createPDF.save(Method.LOCAL);

               

              new FileReference().save(ba, "display.pdf");

              }

               

               

              ]]>

               

              </mx:Script>

               

               

              <mx:VBox id="playout" width="100%" visible="false" backgroundColor="#FFFFFF" includeInLayout="false">

               

              </mx:VBox>

               

              <mx:Button id="print" label="Print" click="doPrint(event)" />

              </mx:Application>

               

              ---------------------------------------------------------------------------------------

              PrintHeader.mxml

              ---------------------------------------------------------------------------------------

              <?xml version="1.0" encoding="utf-8"?>

              <mx:HBox

               

              xmlns:mx="http://www.adobe.com/2006/mxml" horizontalAlign="center" width="100%" verticalAlign="bottom" height="60">

               

              <mx:VBox horizontalAlign="center" verticalAlign="bottom" >

               

              <mx:Spacer height="5%"/>

               

              <mx:HRule/>

               

              <mx:Label text="Title" fontWeight="bold"/>

               

              </mx:VBox>

               

              </mx:HBox>

               

              ---------------------------------------------------------------------------------------

              Content.mxml

              ---------------------------------------------------------------------------------------

              <?xml version="1.0" encoding="utf-8"?>

              <mx:VBox

               

              xmlns:mx="http://www.adobe.com/2006/mxml" horizontalAlign="center" width="100%" verticalAlign="bottom" height="60">

               

              <mx:HBox width="50%" horizontalAlign="bottom" horizontalGap="0">

               

              <mx:Spacer height="5%"/>

               

              <mx:VRule/>

               

              <mx:Label text="body" fontWeight="bold"/>

               

              </mx:HBox>

              <mx:HBox width="50%" horizontalAlign="bottom" horizontalGap="0">

               

              <mx:Spacer height="5%"/>

               

              <mx:HRule/>

               

              <mx:Label text="body" fontWeight="bold"/>

               

              </mx:HBox>

               

              </mx:VBox>

               

              ---------------------------------------------------------------------------------------

              PrintFooter.mxml

              ---------------------------------------------------------------------------------------

              <?xml version="1.0" encoding="utf-8"?>

              <mx:HBox

               

              xmlns:mx="http://www.adobe.com/2006/mxml" horizontalAlign="center" width="100%" verticalAlign="bottom" height="60">

               

              <mx:VBox horizontalAlign="center" verticalAlign="bottom" >

               

              <mx:Spacer height="5%"/>

               

              <mx:HRule/>

               

              <mx:Label text="Page Number" fontWeight="bold"/>

               

              </mx:VBox>

               

              </mx:HBox>