How To view PDF Files in a browser using the filename(path) reference in Database ?

Posted on 2007-10-03
Last Modified: 2010-04-23
Hi All,

I am working on project where I need to view PDF files in a browser and the file reference (path) of the pdf file is in MS SQL SERVER DB Table.

The table layout is as follows:

autokey      uncname      path      
1      \\servername\sharename      c:\files\0001.pdf      
2      \\servername\sharename      c:\files\0002.pdf      
3      \\servername\sharename      c:\files\0003.pdf      
4      \\servername\sharename      c:\files\0004.pdf      
5      \\servername\sharename      c:\files\0005.pdf      
autokeyid      field1      field2      field2

I need to load the 0001.pdf file in the browser and design 3 text boxes so that user can input data into those boxes and that will populate the respective files in table 2.Once that is done user can move onto the next file in the table which is 0002.pdf...and so on

Hope this makes sense.

Can somebody please guide me on this one?


Question by:matrix_aash
    LVL 14

    Expert Comment

    either you have to use FRAMES or open the PDF file separately...

    keep your TEXT boxes in one frame and in teh second frame have the PDF displayed...
    it is not possible to display the PDF and you controls in one single page without using frames...

    have your textboxes and the link to hte pdf file in you web page...and when the user clicks the link the pdf can be opened up...
    LVL 8

    Author Comment

    I want the pdf file and the text boxes on the same page and not separately as it defeats the object. How can i load the image from database, that is the bit which i am confused about. It is possible for you give me some code ?
    LVL 21

    Expert Comment

    If you want the PDF to be viewed along with other parts of the page, you MUST use one of the following tags:

    The object tag would look something like this:
    <object data="data/test.pdf" type="application/pdf" width="300" height="200">
      alt : <a href="data/test.pdf">test.pdf</a>

    But, there is a problem.   Since the object tag was used in classic ASP to load COM objects, you cannot do this:
      <object id='PDFObject' runat='server'...>
    This is because the ASP processor would try to load the COM object on the server and not generate any client html.

    Instead, use the <asp:Literal> control like this:
      <asp:Literal id='PDFView' runat='server OnPreRender="BuildObjectTag"' />

    Then in the code behind:
      protected void BuildObjectTag(object sender, EventArgs e)

    LVL 21

    Accepted Solution

    sorry, submitted by mistake:
    Then in the code behind:
      protected void BuildObjectTag(object sender, EventArgs e)
            string PDFFileLocation="~/PDFS/PDFFile.pdf";
             string ClientPath = page.ResolveClientUrl(PDFFileLoctaion);
             PDFView.Text=string.format(@"<object data='{0}' type='application/pdf' width='300' height='200'>
      alt : <a href='{0}'>Link to {0}</a>
    </object>", ClientPath);

    NOTE:  The PDF MUST be located within the WEB directory subtree.  If the PDF cannnot be located within the WEB subtree then you need to create a ViewPDF.aspx and the PDFFileLocation would be something like this:
       string PDFFileLocation="~/ViewPDF.aspx?FileName=PDFFile.pdf";
    ViewPDF.aspx would then read the PDF file and write it to the Response and set the content type to 'application/pdf'
    LVL 1

    Expert Comment

    Forced accept.

    EE Admin

    Featured Post

    How your wiki can always stay up-to-date

    Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
    - Increase transparency
    - Onboard new hires faster
    - Access from mobile/offline

    Join & Write a Comment

    Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
    If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
    To add imagery to an HTML email signature, you have two options available to you. You can either add a logo/image by embedding it directly into the signature or hosting it externally and linking to it. The vast majority of email clients display l…
    Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

    746 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

    Need Help in Real-Time?

    Connect with top rated Experts

    18 Experts available now in Live!

    Get 1:1 Help Now