Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1271
  • Last Modified:

How to download dynamic generated pdf file from server

I am trying to download pdf file from server on client computer. I am using "FDFACX.DLL" for generating dynamic pdf file. When I download this file then it is not opened in acrobat reader. On my system file is opened only in adobe acrobat and other system file is not downloaded.
Response.Clear();
        Response.Buffer=true ;
 
        FdfAppClass fdfAcX = new FdfAppClass();
        FdfDoc fdfAcXDoc = (FdfDoc)fdfAcX.FDFCreate();
        fdfAcXDoc.FDFSetFile(Server.MapPath("App_Data/Dealer_ULA_New10.pdf"));
 
       
        fdfAcXDoc.FDFSetValue("store_name", "S.P.L. Merchant", false);
        fdfAcXDoc.FDFSetValue("store_state", "L.A", false);
        fdfAcXDoc.FDFSetValue("store_entity", "Software Solutions", false);
       
        fdfAcXDoc.FDFSetValue("date", DateTime.Now.Date.ToString("dd/MM/yyyy"), false);
       
 Response.BinaryWrite((byte[])fdfAcXDoc.FDFSaveToBuf());
 Response.ContentType = "application/vnd.fdf";
fdfAcXDoc.FDFClose();
        Response.End();

Open in new window

Dealer-ULA-New10.pdf
0
teamsunarc
Asked:
teamsunarc
  • 5
  • 5
1 Solution
 
amxCommented:
Try changing
Response.ContentType = "application/vnd.fdf";
to


Response.ContentType = "application/pdf";

Open in new window

0
 
teamsunarcAuthor Commented:
I have already tried this thing. because I am putting pdf with text box and dynamically storing textbox by value and want to download that pdf. So, let me know if any another solution you have to download  that pdf.
0
 
amxCommented:
have downloaded the latest version of the adobe pdf reader?
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
thiyagukTech Lead Commented:
Please  use this as mime type        
Response.ContentType ="application/pdf"

for the list of Mime Time ,
Please
 Refer

http://www.w3schools.com/media/media_mimeref.asp


This is the complete Program listing.
 Response.Clear()
                    Response.AddHeader("content-disposition", "attachment;filename=" + strPath)
               
                    Response.ContentType = "application/pdf"
                    Response.TransmitFile(strPath)
                    Response.Flush()
                    Response.End()
0
 
teamsunarcAuthor Commented:
I am using adobe reader 8.0 and adobe acrobat 5.1. when pdf downloads then reader is opened and display nothing. but when I open this file in adobe acrobat then it is shown all text with dynamic data. but when attachment open on browser then reader does not show anything. one thing more when I downloads the pdf then its size shows only 1kb while the size of pdf is 88kb.
0
 
teamsunarcAuthor Commented:
This is the complete Program listing.
                    Response.Clear()
                    Response.AddHeader("content-disposition", "attachment;filename=" + strPath)
               
                    Response.ContentType = "application/pdf"
                    Response.TransmitFile(strPath)
                    Response.Flush()
                    Response.End()

The above code will not run according to my requirement because this code downloads the file which is placed on server but in my requirement pdf is fullfilled by dynamic text and then downloaded. So I am using Response.BinaryWrite(byte[]) function to download pdf file.  According to my code I am using fdfacx.dll to create dynamic pdf file and want to export this pdf to client.
Response.Clear();
        Response.Buffer=true ;
 
        FdfAppClass fdfAcX = new FdfAppClass();
        FdfDoc fdfAcXDoc = (FdfDoc)fdfAcX.FDFCreate();
        fdfAcXDoc.FDFSetFile(Server.MapPath("App_Data/Dealer_ULA_New10.pdf"));
 
       
        fdfAcXDoc.FDFSetValue("store_name", "S.P.L. Merchant", false);
        fdfAcXDoc.FDFSetValue("store_state", "L.A", false);
        fdfAcXDoc.FDFSetValue("store_entity", "Software Solutions", false);
       
        fdfAcXDoc.FDFSetValue("date", DateTime.Now.Date.ToString("dd/MM/yyyy"), false);
       
 Response.BinaryWrite((byte[])fdfAcXDoc.FDFSaveToBuf());
 Response.ContentType = "application/vnd.fdf";
fdfAcXDoc.FDFClose();
        Response.End();

Open in new window

0
 
amxCommented:
use thiyaguk code but replace the line

Response.BinaryWrite((byte[])fdfAcXDoc.FDFSaveToBuf());

with
Response.Write(fdfAcXDoc.FDFSaveToStr());

Open in new window

0
 
amxCommented:
Ignore my last comment, i think this will work:
Response.ContentType = "application/vnd.fdf"; 
 
byte[] myByte = (byte[])fdfAcXDoc.FDFSaveToBuf();
 
fdfAcXDoc.FDFClose();
 
Response.OutputStream.Write(myByte, 0, myByte.Length); 

Open in new window

0
 
teamsunarcAuthor Commented:
Thanks for above code but the pdf is downloaded on only my pc but when I download this pdf from other pc then it gives error like-

the file you are attempting to open contains comments or form data that are supposed to be placed on , C:\inetpub\demopdf\App_Data\Dealer_ULA.pdf . This document can not be found . it may have been moved or deleted . would you lke to browse to attempt to locate this document


0
 
amxCommented:
I think the problem is with this line:

fdfAcXDoc.FDFSetFile(Server.MapPath("App_Data/Dealer_ULA_New10.pdf"));
 
try replacing with something like this, making sure you replace the url to your server

FdfAcX_Doc.FDFSetFile("http://www.yourserver.com/test.pdf")

Open in new window

0
 
teamsunarcAuthor Commented:
Thanks for this solution. I was giving path of file with "App_Data". and fdfacx does not take file from by app_data. So when I changed it as you said. It is running fine.
Thanks once again.
0

Featured Post

Independent Software Vendors: 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!

  • 5
  • 5
Tackle projects and never again get stuck behind a technical roadblock.
Join Now