Select to view content in your preferred language

Generating PDF with AlivePDF

2857
7
02-14-2011 08:14 AM
MelonyBarrett
Occasional Contributor
I've been using the Flex Map Printing Utility by Mark Hoyland (http://arcscripts.esri.com/details.asp?dbid=16778) for the past year, and it works great.  I especially like the fact that it will clip the map to a different extent based on the page orientation. 

I would like to add a PDF button to the PrintPreview that allows the user to save the same layout into a PDF.  I have gathered from other posts that he and others are using the AlivePDF library to accomplish this.  I now have the AlivePDF library and can generate a PDF, but I'm having trouble using the suggestion from a thread from Mark Hoyland http://forums.esri.com/Thread.asp?c=158&f=2421&t=296597(see the March 17, 2010 post).  The post from Mark says he does the following, but not where:

var myBitmapData:BitmapData = Bitmap(mapImage.content).bitmapData;
myPDF.addImage(new Bitmap(myBitmapData),rectangle.x,rectangle.y,image.width,image.height, ImageFormat.JPG, 75);


It just doesn't seem like I have all of the pieces in the same place at one time in order to send the images or objects to be made into a PDF.  So far, I've made the same mistakes as my predecessors in the forums (like getting low quality, small versions of the layout or map in a PDF), but still can't figure out the solution.

I can't figure out how I'm supposed to link up PrintMapUtil.as with the PDF code.  Am I supposed to:

  1. Add something to PrintMapUtil.as to get the layout as BitmapData and then generate the PDF there, OR

  2. Make new MXML layouts for PDFs and call the trimmedMap function from those, OR

  3. Add the PDF generating functions to the PrintPreview.mxml.


Can someone point me in the right direction?
Tags (2)
0 Kudos
7 Replies
MarkHoyland
Frequent Contributor
Hi Melony,

Here is a modified version of my Print example. This one has included a PDF button on the PrintPreview.

Previously the map layouts eg A5_Portrait.mxml were based on Canvas.
All layouts now need to be based on my new MXML Component PrintLayoutCanvas (which is based on Canvas).
PrintLayoutCanvas has some functions which the layouts need to generate the PDF. The two functions are overriden in the layouts.
One of the functions returns an AlivePDF pdf object. You set up the pdf 'layout' in each layout.

I have also updated the two layouts (A5_Portrait, and A5_Landscape to be actually A5 in size. My original example had them at A6 size!)

The .zip file can be imported into flex as an archive project. You might need to go to project - clean, once it has been imported.

I hope this all makes sense.
0 Kudos
MelonyBarrett
Occasional Contributor
Thanks, Mark!!  I now have it working!

When I first started trying to figure this out using info gleaned from the forums, I kept getting errors at .addImage, not enough arguments or incorrect argument, or maybe something to do with the BitmapData.  So, when I put the components you sent in the project, it happened again.  Well, I noticed that the ArcGIS API for Flex library in your project was only at 1.3, so I thought maybe the AlivePDF.swc could be older, too (I had been trying to use the most recent).  At any rate, I substituted the .swc that you sent in the project, and it all worked!  Finally, I with it working, i as able to tweak the layouts to be letter size, and I am overjoyed to be done with this part of my app! 

Maybe I'll figure out later how the AlivePDF library changed, but for now I'm satisfied with being done.

Thanks again, and I hope this helps some other PDF latecomers!  
Melony
0 Kudos
MarkHoyland
Frequent Contributor
Yes, The version of AlicePDF included with this sample is 0.1.4.9
The latest download of AlivePDF is 0.1.5RC

You can use the latest AlivePDF but you will have to redo the AlivePDF code in the layout templates.
This sample is really just to show the concept.
0 Kudos
MGSethe
Deactivated User
I have been following this thread , and i hit the block at changing the Layout page size .I am using Mark Hoylard Flex Map Printing Utility  suggestion from http://forums.esri.com/Thread.asp?c=158&f=2421&t=296597. I am using  AlivePDF is 0.1.5RC

Can any one please help me to port this nice tool to AlivePDF is 0.1.5RC?
God bless!!!!
0 Kudos
AlexJones
Emerging Contributor
Are you trying to port this app as is to the newer version of AlivePDF or are you trying to use it in the viewer for flex?
0 Kudos
MGSethe
Deactivated User
Are you trying to port this app as is to the newer version of AlivePDF or are you trying to use it in the viewer for flex?


I am trying to use it in the Viewer for Flex : 2.3.1 with AlivePDF  0.1.5RC. Api

It seems like i have to change the Code in the Layout pages as well.

Can you help with that?
0 Kudos
AlexJones
Emerging Contributor
Attached is a zip file with a basic conversion of M. Hoylands application as a flex widget. It has the previews and templates and is in flexviewer 2.x and the Alive PDF 0.1.5RC. You will need to adjust the pdf code, but most likely want to change the layout and functionality anyway . Although it does generate a pdf the measurements appear to be a bit off. So you will need to adjust the x and y or something. I apologize but I cant get into that part right now. I might be able to pick it up again towards the end of the week or next week. Add all of these files to to the widgets folder, change the config file, and add as a module to the project. Let me know if you have any questions, but try to post viewer questions in the Viewer forum
0 Kudos