I know I have to take a screen capture of the page that was generated in Flash. But how then can I get that to a PDF format? I want a button on the Flash page that the user can click for all this to happen in the background.

Thanks for any help!

This would have to be done via some server side script that created a pdf file on the fly.

What operating system would the server be? (Windows NT/2000, Linux, etc?) If you were using linux, for example, you'd need the flash program to automatically execute a script which would run a program on the server in the background which generated the image.

I'm not exactly sure how to go about doing this or how it would be done. I just know it seems pretty complicated ...

I'm an owner of Adobe Acrobat 5.0, and I swear my life by it. The way we create PDF files with Acrobat 5 is by printing to an Actobat Printer. In theory, you would need to create a little program that captures the screen and prints it to the PDF printer.

What you're trying to do I think is impossible, within Flash anyways. If you're trying to automate this process, all from within Flash, and by that I mean, when you press a Flash button, it takes a screen shot and saves it as a PDF in the background. If this is the case, then Flash would need some system access, which it doesn't have for security reasons, and thank God for that. It would suck if I went to a Flash web site, while I had another window open with passwords, and this Flash web site took a screenshot of everything and processed it on the server.

What you're trying to do though, if I follow correctly, can be done with ActiveX. You'd have to code this control yourself. The browser would ask the user if it's safe to download the control. Once this is downloaded by the user, it can take the snapshot, send it back to the server, and you can use another process to convert to PDF. There are SDKs out there to convert images to PDFs on the fly.

PDF generation is possible with PHP, I believe. What you need to do is redirect the user to a PHP form (with all of the information passed in a GET request) and have PHP generate a PDF file which it outputs for the user to download.

It cannot be done with ActionScript alone -- you will require some form of server-side programming language.

Torres Aarron

PDF FILE INTO FLASH CODE
--------------------------------------------------------------------------------

on (press) {

        import flash.net.FileReference;

        var listener:Object = new Object();

        

        listener.onSelect = function(file:FileReference):Void {

                trace("onSelect: " + file.name);

        }

        

        listener.onCancel = function(file:FileReference):Void {

                trace("onCancel");

        }

        

        listener.onOpen = function(file:FileReference):Void {

                trace("onOpen: " + file.name);

        }

        

        listener.onProgress = function(file:FileReference, bytesLoaded:Number,

 bytesTotal:Number):Void {

                trace("onProgress with bytesLoaded: " + bytesLoaded 

+ " bytesTotal: " + bytesTotal);

        }

        

        listener.onComplete = function(file:FileReference):Void {

                trace("onComplete: " + file.name);

        }

        

        listener.onIOError = function(file:FileReference):Void {

                trace("onIOError: " + file.name);

        }

        

        var fileRef:FileReference = new FileReference();

        fileRef.addListener(listener);

        var url:String = "resume.pdf";

        if(!fileRef.download(url, "resume.pdf")) {

                trace("dialog box failed to open.");

        }

}

it does not work for me .. what did I did wrong?

There are many companies who will do this pretty cheap.

I know I have to take a screen capture of the page that was generated in Flash. But how then can I get that to a PDF format? I want a button on the Flash page that the user can click for all this to happen in the background.
Thanks for any help!

You could try something like this...

Make the button on your Flash movie call a server-side script with the getURL function. The script will need to know what page is to be rendered. Don't rely on the HTTP Referer header as this is not always reliable. Instead, pass the document location encoded in the query string...

on(release) {
  getURL("http://www.yoursite.com/my-script.aspx?referrer=my-flash-page.htm","_self");
}

Your server-side script, written in ASP.NET or PHP, can then access the query string. Decode the referring URL and and pass it on to a PDF component / library for further processing.

The following code is written in C# and uses the ABCpdf component from WebSupergoo (mentioned earlier by rajarajan07):

string theUrl = "http://www.yoursite.com/" + yourDecodedUrlQueryString
Doc theDoc = new Doc();
theDoc.AddImageUrl(theUrl);
theDoc.Save("output.pdf");
theDoc.Clear();

Optionally, you can stream the PDF back to your client's browser or send it as an inline attachment. To do this, simply replace the call to Doc.Save() with something like this:

byte[] theData = theDoc.GetData();
Response.ContentType = "application/pdf";
Response.AddHeader("content-length", theData.Length.ToString());
if (Request.QueryString["attachment"] != null)
  Response.AddHeader("content-disposition", "attachment; filename=ExampleSite.pdf");
else
 Response.AddHeader("content-disposition", "inline; filename=ExampleSite.pdf");
Response.BinaryWrite(theData);
Response.End();

Sometimes it's necessary to control which frame of a Flash movie is captured, such as when Flash movies fade in. See the HTMLOptions.AddMovie property for details on how to do this.

If you need to import Flash movies that aren't embedded in an HTML document, there's some example code to be found in the documentation for the SwfImportOperation.Import function...

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.