Click here to Skip to main content
15,917,610 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi All,

I'm trying to open PDF file in fancyBox using a Button click. PDF file path is generated dynamically on Button Click. Is there any way to do this ?
Please help me ...

This is my existing code.
HTML
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
    <script src="Scripts/jquery.fancybox.js" type="text/javascript"></script>
    <link href="Scripts/jquery.fancybox.css" rel="stylesheet" type="text/css" />
    <script src="Scripts/jquery-1.4.1.js" type="text/javascript"></script>
    <script type="text/javascript">
        $(document).ready(function () {
            $("a.fancyFrame").fancybox({
                'frameWidth': 200,
                'frameHeight': 200,
                'overlayShow': true,
                'hideOnContentClick': false,
                'type': 'iframe'
            });
        });
    </script>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <div>
            <asp:Button ID="Button1" runat="server" Text="Button" onclick="Button1_Click" />
            <iframe src="Articles/HelloWorld.pdf" width="600" height="500"></iframe>
            <a id="myFrame" class="fancyFrame" title="Item Title" href="???">
                Link to Document</a>
        </div>
    </div>
    </form>
</body>
</html>

And what should be written in Button Click code behind ?
C#
protected void Button1_Click(object sender, EventArgs e)
        {
            string pdfPath=""; //the pdf file path is supplied here on runtime
        }


Thanks in advance ...
Posted
Updated 6-Aug-13 17:16pm
v3
Comments
Sergey Alexandrovich Kryukov 6-Aug-13 23:31pm    
Yes, of course, because you can always set any media type (content type, MIME) in your HTTP response, so you can dynamically generate and respond with PDF context, having no actual file on the server side.

The only problem is this: you should never assume that client side can support PDF. This is not a part of Web standard and does not work on all systems and browsers. If no PDF support is installed, the browser will suggest to just save the file. How about that?

Anyway, this is one reason to work with HTML instead of PDF. And I really don't think PDF has any serious value. I would not personally bother. Just something to think about.

—SA
Member 9330747 7-Aug-13 0:06am    
Hi Alex, thanks for your reply. There is no problem if PDF reader is not installed in client machine, in that case the file would be downloaded. Could you please give an example with code ? I've googled but unable to find any concrete solution.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900