?
Solved

Build pdf downloader in Flex/As3 through java container

Posted on 2011-03-25
13
Medium Priority
?
482 Views
Last Modified: 2012-05-11
Hi there,

I need help in building a pdf downloader in flex for a webpage that has java script handling the pdf presentation in page. The exact page is like this: link

I have this class for downloading simple stuff but the thing is: I want it to be able to download the pdf from that page so that I can, in future, automatize it to crawl for all pages. Can anyone help me build the code in flex/as3 for the pdf downloading?



THanks in advance!
package classes
	{
		import flash.display.Sprite;
		import flash.net.FileReference;
		import flash.net.URLRequest;
		import flash.net.URLRequestMethod;
		import flash.net.URLVariables;
		
		public class DownloadFileExample extends Sprite
		{
			private var fileToDownload:FileReference;
			public function DownloadFileExample()
			{
				var request:URLRequest = new URLRequest();
				request.url = "http://www.in.gov.br/visualiza/index.jsp?data=25/03/2011&jornal=1&pagina=2&totalArquivos=224";
				request.method = URLRequestMethod.GET;
				request.data = new URLVariables("id=2");
				fileToDownload = new FileReference();
				try
				{
					fileToDownload.download(request, "file2.pdf");
				}
				catch (error:Error)
				{
					trace("Unable to download file.");
				}
			}
		}
	}

Open in new window

0
Comment
Question by:C_Schlottfeldt
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 8
  • 5
13 Comments
 
LVL 29

Expert Comment

by:dgofman
ID: 35219625
Do you want to download and save on disk or open via Google Docs / Adobe Viewer or open in the Flash Player?
0
 
LVL 29

Expert Comment

by:dgofman
ID: 35219677
I know two products for working with PDF file

1) import PDF file http://www.adobe.com/products/flashpaper/
2) generate PDF file http://alivepdf.bytearray.org/

Check both
David
0
 

Author Comment

by:C_Schlottfeldt
ID: 35223599
I want to download and save on disk, like a download manager.... pdf is just a format of the file to download in this case....
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 29

Expert Comment

by:dgofman
ID: 35223630
0
 

Author Comment

by:C_Schlottfeldt
ID: 35223666
The code works just as the one above, the problem is that I cant download the file because the file is called directly by a javascript function (I think...). To see it try the link : http://www.in.gov.br/imprensa/visualiza/index.jsp?jornal=1&pagina=1&data=25/03/2011
0
 
LVL 29

Expert Comment

by:dgofman
ID: 35223757
Hi C_Schlottfeldt,
The link what you are providing is not a PDF file, looks like its servlet.
And on the server side they are implementing validation to download outside the domain.

Example:

<html><head><title>INPDFViewer (application/pdf Object)</title></head><body marginwidth="0" marginheight="0"><embed height="100%" width="100%" name="plugin" src="http://www.in.gov.br/servlet/INPDFViewer?jornal=1&pagina=1&data=25/03/2011&captchafield=firistAccess" type="application/pdf"></body></html>

This how its loading PDF file on the web, if you will create HTML file and try to login from your domain you will get Errors.

Nothing wrong in your ActionScript code but you need to know FTP path to PDF file.

Sorry,
David
0
 
LVL 29

Expert Comment

by:dgofman
ID: 35223784
Open in the browser your link and save on the desktop.
Open HTML page using any browsers

Lista de erros:

- Sessão expirada ou tentativa de acesso direto ao componente.
0
 

Author Comment

by:C_Schlottfeldt
ID: 35223882
I saw that error too. Do you know if there is any way to find out the FTP path to the pdf considering the information above ??
0
 
LVL 29

Accepted Solution

by:
dgofman earned 2000 total points
ID: 35224066
Its hard I check via Fiddler and Firefox/FireBug. I didn't see the direct request to FTP server or file.
But you can get this file from Temporary Temp Directory/Cache upload to your server and provide link to your customers. I attached that file.
INPDFViewer-1-.pdf
0
 

Author Comment

by:C_Schlottfeldt
ID: 35224144
Thanks alot! That's indeed a clever workaround !!!! I'll try work that way but I'm gonna wait a little more to see if anyone else can contribute to discussion before closing the question, ok ?
0
 
LVL 29

Expert Comment

by:dgofman
ID: 35224149
fine!
0
 
LVL 29

Expert Comment

by:dgofman
ID: 35224153
but I don't think if anyone can find way downloading corrupted stream/file :)
0
 

Author Closing Comment

by:C_Schlottfeldt
ID: 35236480
Very good solution
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Sometimes you know that one object has a specific child in it, but you can't find the child. This happened to me when I was trying to code some actionScript to make a toolbar work with its embedded buttons.  My partner had created the toolbar usi…
There are times in your Flash CS4 application when you want more than a simple pointer or a hand, and it's hard to find an ideal walk-through to tell you what to do.  I spent a few days recently learning my way around making custom cursors in Flash,…
In this tutorial viewers will learn how to create a basic motion tween animation in Flash Open a new document in Flash: Draw/import an image: Press CTRL + F8 to convert it into a graphic symbol: Select a frame (how long you want the tween to last): …
The goal of the tutorial is to teach the user how to use the auto adjust feature and what the different options do. When your video is not working right you can choose the auto adjust feature to help choose your settings.
Suggested Courses
Course of the Month8 days, 17 hours left to enroll

765 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question