Launching PDF without saving it first
I need to launch a pdf document from vb.net without forcing user to save the document first. I want the user to just be able to view it.
Is this possible?
Thanks,
Ninel
[190 byte] By [
ninel] at [2007-11-11 8:27:19]

# 1 Re: Launching PDF without saving it first
Is this a Web app or a Windows app? If you're running on the user's desktop, I don't know of any PDF viewers that can display anything other than a file. If it's a Web app, you should have posted to the ASP.NET forum. ;-) You can send the PDF in the response stream and the browser should open it in the user's default PDF viewer. See http://support.microsoft.com/default.aspx?id=306654 for more information.
# 2 Re: Launching PDF without saving it first
I have a table of pdf files that need to be displayed to an employee. When an employee punches in I check if they viewed the pdf files. If not, I show a link on the login page for them to click on. In order to track the clicking of that link I use the .navigateurl to go to another page where I can update a table. I then want to display the pdf.
I am doing the following:
To test initially, I saved one pdf in the same directory as the login.aspx page of my .net project.
Here's the code:
Login.aspx :
hlnkTest.Visible = True
hlnkTest.Target = "_blank"
hlnkTest.Text = "TEST"
hlnkTest.NavigateUrl = "CaptureClickandDisplayPDF.aspx"
CaptureClickandDisplayPDF.aspx :
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
If Not Page.IsPostBack Then
Dim FilePath As String
Response.ContentType = "Application/pdf"
FilePath = MapPath("TestPDF.pdf")
Response.WriteFile(FilePath)
End If
End Sub
I don't get an error message, but get mumbo jumbo displayed and not the actual contents of the pdf file.
What am I doing wrong? Is there another way to do this?
Thanks,
Ninel
Go to Top of Page
ninel at 2007-11-11 23:14:12 >

# 3 Re: Launching PDF without saving it first
Based on this followup thread: http://forums.dev-archive.com/showthread.php?threadid=152310 , am I correct in concluding that you solved this problem? If so, what was the solution?
# 4 Re: Launching PDF without saving it first
Yes and no. I changed the way I coded it.
When the user clicks on the link instead of navigating to a different aspx page I navigate directly to the pdf file which opens up in a separate window. There is a checkbox on the first page that is disabled. When the link is clicked on I need the checkbox enabled I also need to execute a stored procedure that updates a table.
This is what I have so far:
Page1
HTML:
<asp:hyperlink id="hlnkTest" runat="server" Font-Names="Tahoma" Font-Size="x-Small" ForeColor="BLUE" Visible="true"></asp:hyperlink>
<asp:checkbox id="chkRead" runat="server" OnCheckedChanged="chkRead_checked" AutoPostBack="true" Font-Size="x-Small" Font-Names="Tahoma" Text="I have read the new/updated policies"></asp:checkbox>
ASPX:
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
If Not Page.IsPostBack Then
hlnkTest.Visible = True
hlnkTest.Target = "_blank"
hlnkTest.Text = "TEST"
hlnkTest.Attributes.Add("onclick", "enableCheckBox()")
hlnkTest.NavigateUrl = "EmployeePolicies.pdf"
chkRead.Enabled = False
Dim str As String
str = "<script language='javascript'>"
str = str & "function enableCheckBox() {document.getElementById('chkRead').disabled = false;}"
str = str & "</script>"
Response.Write(str)
End If
End Sub
I'm not getting any errors, but it's also not enabling the checkbox.
What am I doing wrong?
Thanks,
Ninel
ninel at 2007-11-11 23:16:13 >

# 5 Re: Launching PDF without saving it first
First, try using an HTML CheckBox control instead of an ASP.NET control. This way you can access it directly in your javascript.
Example: FormName.ControlName.disabled
If it still doesn't work, try the code below.
Try using a hidden control to store a value. When the javascript function is called, have it change the value of the hidden control. In your code behind you will need to put an if statement to check the value of the hidden control on every post back. Once the value is changed, your if statement should run CheckBox.Enabled = true. Just keep in mind that you need to have the page post back once the button or link is pressed and if your control does post back to the server, you cannot use the 'OnClick' event. This is why I used an HTML button control which supports the Onclick and OnMouseDown events. You can run your javascript on the OnMouseDown event. You may want to consider adding the code to open the pdf to your javascript function for changing the checkbox.
--> Use HTML INPUT controls instead of ASP controls
<INPUT id="Button8" runat="server" type="button" value="Button" onmousedown='javascript:enableCheckBox()'>
<INPUT runat=server ID="Hidden1" type="hidden" value="1">
----> Javascript make sure you use your FormName.ControlName.value
function enableCheckBox()
{
Form1.Hidden1.value = "2";
}
//inside your page load, outside your if not postback statement
if (Hidden1.Value = "2")
{
CheckBox.Enabled = true;
}
Any questions, my email is Jtangowski@jbtsoftware.com
