Link to home
Start Free TrialLog in
Avatar of tracymr
tracymrFlag for United States of America

asked on

Adobe Acrobat Reader PDF/FDF Merge and View

My goal is to prepopulate PDF forms with information that resides in a database via a web (ASP) platform.

In order to do this, I am merging a PDF template with a FDF file.  This part works.

The problem I am having is that I would prefer to launch the document in the Acrobat Reader stand alone program and instead the generated document is being launched in the reader plug-in for IE/Netscape.  If I can't get the document to launch in the stand-alone reader I'd like to not have the stand-alone reader launch at all and simply have the document loaded in the web browser plug-in.

'**************************************************************************
'--This sample launches the an empty instance of adobe acrobat reader and then opens the merged
'--document in a browser window with the form prepopulated

Set FdfAcX = Server.CreateObject("FdfApp.FdfApp")

' Create a blank FDF file
Set objFdf = FdfAcX.FDFCreate
objFdf.FDFSetValue "strLastName", strLastName, False
objFdf.FDFSetValue "strFirstName", strFirstName, False

objFdf.FDFSetFile "http://www.myweb.com/Content/DynamicForms/myfile.pdf"

' Save the file
Response.ContentType = "application/vnd.fdf"
Response.BinaryWrite objFdf.FDFSaveToBuf

' Close the file
objFdf.FDFClose
   
' Cleanup
Set objFdf = Nothing
Set FdfAcX = Nothing
**************************************************************************


'**************************************************************************
'--This sample only works in the server because of the physical file location of the PDF but launches in
'--Adobe Acrobat reader as desired.  I just wanted to show this example as a contrast to above
'--but that it offers the desired result

Set FdfAcX = Server.CreateObject("FdfApp.FdfApp")

' Create a blank FDF file
Set objFdf = FdfAcX.FDFCreate
objFdf.FDFSetValue "strLastName", strLastName, False
objFdf.FDFSetValue "strFirstName", strFirstName, False

objFdf.FDFSetFile "c:/DynamicPDFs/Content/DynamicForms/myfile.pdf"

' Save the file
Response.ContentType = "application/vnd.fdf"
Response.BinaryWrite objFdf.FDFSaveToBuf

' Close the file
objFdf.FDFClose
   
' Cleanup
Set objFdf = Nothing
Set FdfAcX = Nothing
**************************************************************************




ASKER CERTIFIED SOLUTION
Avatar of cavijayan
cavijayan

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Natasja_
Natasja_

try

Response.ContentType ="application/pdf"
Hi

using Response.ContentType ="application/pdf"  will only give you a error because of no proper PDF file structure ...
Ok, here's how I do it .. the file will get displayed in the stand alone program :
the trick is to first write the pdf to a physical file, then call Response.WriteFile on that file

....
string rrnaam = GetFaktNaam(Session["klant"].ToString());

                  string theFile = FdfAcX_Doc.FDFSaveToStr();

                  FileStream fs = new FileStream( ExportFolder + rrnaam + ".pdf" , FileMode.OpenOrCreate, FileAccess.Write);
                  StreamWriter m_streamWriter = new StreamWriter(fs);
 
                  // Write to the file using StreamWriter class
                  m_streamWriter.BaseStream.Seek(0, SeekOrigin.End);
                  m_streamWriter.WriteLine(theFile);
                  m_streamWriter.Flush();
                  fs.Close();
                  //-------------------

                  FdfAcX_Doc.FDFClose();
                  Response.ContentType="Application/vnd.fdf";
                  Response.WriteFile(ExportFolder + rrnaam + ".pdf");
                  Response.End();
Avatar of tracymr

ASKER

Natasja_,
I do not have access to the methods and classes you mention.  I'm not using .Net  just straight up ASP on an IIS 5.0 server.  I should have mentioned that to begin with.

I don't necessarily *need* to have the PDF launch in the stand-alone reader, that is preferred.  However, if the PDF must launch in a browser window I'd rather not have adobe reader launch at all.  It doesn't appear to be providing any purpose.

Any other ideas?
Avatar of tracymr

ASKER

My wish list is this
1.  Open the PDF in the stand-alone reader

else

2.  Open the PDF in the browser and do not open the reader stand-alone

else
what I have now is
3.  Open the PDF in the browser and launch an empty instance of Acrobat reader.
I don't think it will open the empty instance of Acrobat reader? Are you sure? Bcoz i'm using IE 6 but i have never seen such thing before ...
do you mean that adobe acrobat (CREATOR, not the Free reader) is opened when you look at the FDF ? So you got 1 open window with your data, and an open empty Acrobat ?

Because that's normal, it doesn't happen on PC's where only the free reader is installed.
Avatar of tracymr

ASKER

I don't know why you haven't seen this behavior but I've tested this code..
**************************************************************************
'--This sample launches the an empty instance of adobe acrobat reader and then opens the merged
'--document in a browser window with the form prepopulated

Set FdfAcX = Server.CreateObject("FdfApp.FdfApp")

' Create a blank FDF file
Set objFdf = FdfAcX.FDFCreate
objFdf.FDFSetValue "strLastName", strLastName, False
objFdf.FDFSetValue "strFirstName", strFirstName, False

objFdf.FDFSetFile "http://www.myweb.com/Content/DynamicForms/myfile.pdf"

' Save the file
Response.ContentType = "application/vnd.fdf"
Response.BinaryWrite objFdf.FDFSaveToBuf

' Close the file
objFdf.FDFClose
   
' Cleanup
Set objFdf = Nothing
Set FdfAcX = Nothing
**************************************************************************

on several different machines and get the same result.  The back end is Windows 2000, IIS 5.0 and I've tested on a Windows 2000 Professional computer running IE 6, 2 windows XP machines running IE 6, and a Windows 98 machine running IE 6 and all have displayed the same behavior of launching an empty acrobat reader and then loading the PDF in a browser window.
Avatar of tracymr

ASKER

I really appreciate all the comments thus far.  

I have double checked that only the free reader is installed on my test machine just to verify that what I've said thus far is accurate.  It does happen on a machine where only the free reader is installed.  Again, what I end up with is an IE window with the pdf and an instance of Acrobat Reader with no document.