Select to view content in your preferred language

PDFWidget for 2.1

2439
19
10-20-2010 10:13 AM
by Anonymous User
Not applicable
Original User: philipp37

BrianO had created a PDFWidget for 1.3 (http://forums.arcgis.com/threads/12142-FSV-1.3-My-version-of-PDF-Widget-using-AlivePDF?highlight=pri...).

I have ported this to 2.1.  I have commented out the portrait orientation option since the map image does not yet scale properly.  That leaves landscape by default and it too is getting cut-off (see attached) on the bottom - so if anyone knows how to scale this properly please respond here!

I was receiving an 'Alpha channel not supported for now' error - you need to replace the logo.jpg (referenced on line 99 of the mxml) with your logo that has no alpha channel (I got mine to work by exporting the logo from photoshop....) - not sure what is going on here exactly.
0 Kudos
19 Replies
by Anonymous User
Not applicable
Original User: philipp37

Oh ya...you need to include the AlivePDF.swc library in your build path.  I've attached the latest AlivePDF.swc here (0.1.5 RC).  Don't forget to also add PDFWidget.mxml to the modules for building...
0 Kudos
philippschnetzer
Frequent Contributor
I don't think there is much that can be done in terms of scaling the image without distortion...sometimes the image will just not fill up the entire pdf.  So I modified the placement of the titleblock and map.  Now the titleblock is at the top and the map below...that way the map can never overlap the titleblock.  If interested copy the code below and replace everything below '//create a landscape map' in the PDFWidget.mxml posted above...



else  //create a landscape map
    {
     //create landscape letter-size pdf and set margins
     landPDF=new PDF(Orientation.LANDSCAPE,Unit.MM,Size.LETTER);
     landPDF.setDisplayMode(Display.FULL_PAGE,Layout.SINGLE_PAGE);
     landPDF.setMargins(2,2,2,2);
     landPDF.addPage();
     
    
     //add PDF document metadata--most people never notice but give credit where due
     //and create a "well-formed" pdf document
     landPDF.setTitle(txtTitle.text);
     landPDF.setSubject(pdfSubject);
     landPDF.setAuthor(pdfAuthor);
     landPDF.setKeywords(pdfKeywords);
     landPDF.setCreator(pdfCreator);
     
     //draw neat line
     //landPDF.drawRect(new Rectangle(2,2,275,212));
     
     //draw title block rectangle
     landPDF.drawRect(new Rectangle(3,3,273,32));
     
     //add logo image
     landPDF.addImageStream(new myLogoJPG() as ByteArray,"DeviceRGB",null,3,5,40,0,0,1,Blend.NORMAL,null);
     
     //add title text entered in widget input
     landPDF.setFont(timesboldFont,22);
     landPDF.addText(txtTitle.text,50,10);
     
     //add subtitle text entered in widget input
     landPDF.setFont(timesFont,16);
     landPDF.addText(txtSubtitle.text,50,17);
     
     //add some disclaimer text
     var landDisclaimerLine1:String="DISCLAIMER: This map is for informational purposes and has not been prepared for, nor is it suitable for legal, surveying, or engineering purposes. Users of this information ";
     var landDisclaimerLine2:String="should review or consult the primary data and information sources to ascertain the usability of the information. The XXXXXXXXXXXXXX makes no warranty or ascertain ";
     var landDisclaimerLine3:String="the usability of the information. The XXXXXXXXXXXXX makes no warranty or guarantee as to the content, accuracy, timeliness, or completeness of any of the data";
     var landDisclaimerLine4:String="provided, and assumes no legal responsibility for the information contained hereon.";
     landPDF.setFont(arialFont,8);
     landPDF.addText(landDisclaimerLine1,50,21);
     landPDF.addText(landDisclaimerLine2,50,24);
     landPDF.addText(landDisclaimerLine3,50,27);
     landPDF.addText(landDisclaimerLine4,50,30);
     
     //add copyright text
     landPDF.setFont(arialFont,9);
     landPDF.addText(copyright,50,33);
 
           //add print timestamp
           landPDF.setFont(arialFont,8);
     var nowLand:String = getCurrentDateTime();
     landPDF.addText("Printed: " + nowLand,5,7);
     
     //add the map
              var rsLand:Resize=new Resize("FitToPage","left");
              landPDF.addImage(map,rsLand,2,35,0,0,0,1,false,ImageFormat.JPG,100,Blend.NORMAL,null);
              
     //save the pdf
              const fileReferenceLand:FileReference = new FileReference();
     fileReferenceLand.save(landPDF.save(Method.LOCAL,"",Download.INLINE,"landPDF.pdf"),"map.pdf");
     
    }
  
   }
   
  ]]> 
</fx:Script>
<viewer:WidgetTemplate id="wTemplate"  height="190" width="300">
  <mx:ViewStack id="viewStack" width="100%" height="100%" creationPolicy="all">
    <mx:VBox width="100%" height="100%" verticalGap="10" paddingTop="10">
      <mx:Form id="frmPrint" verticalScrollPolicy="off" paddingBottom="0" width="100%" height="100%">
        <mx:FormItem label="{titleLabel}" styleName="WidgetText" width="100%">
          <mx:TextInput id="txtTitle" text="{title}" /> 
        </mx:FormItem>
        <mx:FormItem label="{subtitleLabel}" styleName="WidgetText" width="100%">
          <mx:TextInput id="txtSubtitle" text="{subtitle}" /> 
        </mx:FormItem>
        <!--mx:FormItem label="Label"-->
          <mx:ToggleButtonBar id="pgOrient" selectedIndex="-1" itemClick="setPageOrientation(event);">
           <mx:dataProvider>
            <fx:Array>
             <!--fx:String>Portrait</fx:String-->
             <!--fx:String>Landscape</fx:String-->
            </fx:Array> 
           </mx:dataProvider>
          </mx:ToggleButtonBar>
        <!--/mx:FormItem-->
        <mx:HBox horizontalAlign="center" width="100%">
          <mx:Button label="{submitLabel}" click="makePDF(event)" />    
        </mx:HBox>
    <mx:Spacer width="100%" height="1" />
    <s:Label  text="         Be patient while PDF is building..."  fontStyle="normal" fontSize="12" />
      </mx:Form>
    </mx:VBox>
   </mx:ViewStack>
 </viewer:WidgetTemplate>
</viewer:BaseWidget>
0 Kudos
by Anonymous User
Not applicable
Original User: thejones23

This is a print sample that Mark H put together. I find it to be a very nice utility for trimming the map to get the print size correct. There are a few different pieces to get this to work but I would recommend downloading it and looking at the code to see how he trims the map. I use some of this code on my site and it has been very helpful for sizing the map correctly. Technically you don't need all of the pieces and you can just call his PrintMapUtil.as to return your map as a bitmap.


http://resources.esri.com/arcgisserver/apis/flex/index.cfm?fa=codeGalleryDetails&scriptID=16778
0 Kudos
philippschnetzer
Frequent Contributor
Thanks, I will look into that.

On a different note...is it possible to ensure the background colour set in the viewer gets exported to the PDF?

In my config.xml I have added a sixth element which designates the background colour....

<stylecolors>0xCCCCCC,0x777777,0x555555,0x333333,0xCCCCCC,0xBED2FF</stylecolors>

....but this does not make it onto the PDF.

Thanks!
0 Kudos
by Anonymous User
Not applicable
Original User: rscheitlin

Philipp,

   I have found that you have to explicitly set the map objects background color before you take the snapshot.
0 Kudos
NadeemShaukat
Deactivated User
Oh ya...you need to include the AlivePDF.swc library in your build path.  I've attached the latest AlivePDF.swc here (0.1.5 RC).  Don't forget to also add PDFWidget.mxml to the modules for building...


Philipp,

I have downloaded the source code for PDF Widget and incorporated the AlivePDF.swc to libs. The widget is implemented error free, but does not proceed further after I click on the "Generate PDF" button.

Could you post the latest widget source code?

nshaukat
0 Kudos
by Anonymous User
Not applicable
Original User: philipp37

nshaukat

I haven't made any changes to the code that you have already implemented.  Did you add the PDFWidget.mxml to the 'modules'?  Also, once you click the 'Generate PDF' button there is no progress bar to let you know how long the process will take....for me it has been running anywhere from 5 seconds to about 25 seconds....
0 Kudos
AnshulMantri
New Contributor
Philipp,

Thanks for the post..

Regards

Anshul
0 Kudos
by Anonymous User
Not applicable
Original User: philipp37

If anyone could chime in with the method on how to include certain widgets (ie, Roberts Dynamic Legend widget) on the resulting PDF that would be much appreciated.  Export to PDF is great but certain maps simply require a legend to be printed (ie, zoning maps).

Thanks for any help!
0 Kudos