Embedding Adobe Reader PDF in ASP.NET, HTML, ASP or PHP

> Edraw Tip > Embedding Adobe Reader PDF in ASP.NET, HTML, ASP or PHP
author
Posted by James Freeman |
PDF Viewer Component helps developers to embed pdf documents in ASP, HTML, ASP.NET or PHP page.

Edraw PDF Viewer Component can embed pdf documents in web page by implementing a full featured ActiveX document container. Now you can have adobe reader run embedded inside your custom solution in ediable mode or read mode.

Click Here to Download PDF Viewer Component

free download2 MB

PDF Viewer Component Online Demo

Embed pdf in ASP.NET

Figure 1: Embedding and Displaying PDF in ASP.NET Page.

Use the pdfviewer.cab file

The office control can be used in web application. It is a standard ActiveX Control and run at the client. So the developers need to embed the component at the html Object tag.

<object classid="clsid:44A8091F-8F01-43B7-8CF7-4BBA71E61E04" id="PDFViewer1" width="100%" height="100%" codebase="http://localhost:13971/download/pdfviewer.cab#version=5,0,0,412">
<param name="TitlebarText" value="PDF Viewer OCX">
<param name="TitlebarBackColor" value="-2147483635">
<param name="TitlebarTextColor" value="-2147483634">
<param name="Titlebar" value="1">
<param name="BorderStyle" value="1">
<param name="BorderColor" value="-2147483632">
<param name="BackColor" value="16777215">
<param name="ForeColor" value="12632256">
<param name="NamedDest" value>
<param name="Page" value>
<param name="Comment" value>
<param name="Zoom" value>
<param name="View" value>
<param name="ViewRect" value>
<param name="PageMode" value>
<param name="Search" value>
<param name="Scrollbar" value="-1">
<param name="Toolbars" value="-1">
<param name="Statusbar" value="0">
<param name="Messages" value="0">
<param name="NavPanes" value="0">
<param name="Highlight" value>
<param name="Path" value>
<param name="LicenseName" value>
<param name="LicenseKey" value>
</object>

Note: You should put the pdfviewer.cab file in your own site and change the codebase url when you distribute the component.

You can view the html samples in the install folder\samples\asp.net folder.

The pdfviewer.cab file is available in the install folder. You can create your own cab file.

Why do I fail to download the ActiveX control on the client machine?

The failure of loading ActiveX control has the following possible causes:

1. The security settings of IE on the client machine are incorrect.

Please verify the following security settings of IE to "Prompt" or "Enabled":
a) Download signed ActiveX controls
b) Run ActiveX Controls and plug-ins
c) Script ActiveX controls marked safe for scripting
d) Add the site in the IE trust site list
The dialog box of the security setting can be launched from menu Tools>Internet Options. Then select the security tab.

How to add PDF Viewer Component to your ASP.NET project

1. Open Visual Studio.
2. Create a new ASP.NET project.
3. Do not attempt to add the PDF Viewer Component to the Toolbox. It is a client component. You can add it as the HTML Object.
4. Copy all files at the asp.net\loadpdf\loadpdf\ to the new project folder. (UploadAction.aspx UploadAction.aspx.cs Default.aspx.cs Default.aspx Tester.doc)
5. Then add existing items...
6. Modify the Server Port in the Default.aspx.
6. Run.

Use the Javascript to Open, Save, Print Office Document

You can write the javascript or vbscript code in the asp.net, php, html, asp page to call the methods of PDF Viewer Component.

<script ID=clientEventHandlersJS language=javascript>
function LoadPDFFile()
{
//var sPath= window.prompt("Type the local file path:", "d:\\test.pdf");
document.all.PDFViewer1.LoadFile("");//sPath
}

function LoadfromServer()
{
//var sPath= window.prompt("Type the file url:", "http://www.ocxt.com/demo/samples/sample.pdf");
//document.all.PDFViewer1.LoadFile(sPath);

//To test, you need put a 1.pdf file in the d:\1.pdf. See UploadAction.aspx.cs file
var strUploadPath = "http://localhost:13971/UploadAction.aspx"; // You need change the port and the folder: [server:port/folder/file]

document.all.PDFViewer1.HttpInit();
document.all.PDFViewer1.HttpAddpostString("DocumentID", "W-9.pdf");
document.all.PDFViewer1.HttpOpenFileFromStream (strUploadPath);
}

function ShowToolbars()
{
var x = document.all.PDFViewer1.Toolbars;
document.all.PDFViewer1.Toolbars= ! x;
}

function ShowTitlebar()
{
var x = document.all.PDFViewer1.Titlebar;
document.all.PDFViewer1.Titlebar= ! x;
}

function ShowScrollbar()
{
var x = document.all.PDFViewer1.Scrollbar;
document.all.PDFViewer1.Scrollbar= ! x;
}

function FirstPage()
{
document.all.PDFViewer1.GotoFirstPage();
}

function PreviousPage()
{
document.all.PDFViewer1.GotoPreviousPage();
}

function NextPage()
{
document.all.PDFViewer1.GotoNextPage();
}

function LastPage()
{
document.all.PDFViewer1.GotoLastPage();
}

function PrintOut()
{
document.all.PDFViewer1.PrintWithDialog();
//document.all.PDFViewer1.PrintAll(); //more print options
//document.all.PDFViewer1.PrintAllFit(True); //more print options
//document.all.PDFViewer1.PrintPagesFit(1,3,True); //more print options
//document.all.PDFViewer1.PrintPages(1,3); //more print options
}

function SinglePage()
{
document.all.PDFViewer1.ApplyLayoutMode("SinglePage");
}

function DoublePage()
{
document.all.PDFViewer1.ApplyLayoutMode("TwoColumnLeft");
}

function ThumbView()
{
document.all.PDFViewer1.ApplyPageMode("thumbs");
}

function NoneThumb()
{
document.all.PDFViewer1.ApplyPageMode("none");
}

function ClosePDF()
{
document.all.PDFViewer1.Clear();
}

function SetReadOnly() {
document.all.PDFViewer1.SetReadOnly();
}

function SavetoServer()
{
var sPath= window.prompt("Type the file url:", "http://www.ocxt.com/demo/samples/sample.pdf");
document.all.PDFViewer1.HttpInit();
document.all.PDFViewer1.HttpAddPostFile (sPath)
document.all.PDFViewer1.HttpPost("http://www.ocxt.com/demo/upload_weboffice.php");
}

</script>

Clear the ActiveX CAB File from IE Cache

For IE7/8/9/10/11

1. Open a new Internet Explore.

2. Go to Internet Explorer, and click the "Tools" button in the left of browser, and then click Manage Add-ons.

3. Click Toolbars and Extensions.

4. Double Click the add-on you want to delete. In the pop up message box, you can click the Delete button in the bottom.

For IE6

IE Toolbar > Options > General > Setting > View Object...

Then delete the Edraw Viewer Component for Word.

About the IE Protection Mode

The component can not run at the IE protection mode. So the client needs to add the site in IE trusted site list. The component will pop up the reminder dialog if it run at the IE protection mode.

With the PDF Viewer Component, it's easy to host the Adobe Reader in a custom solution.

Embedding MS Word, Excel, PowerPoint into a ASP.NET Application

download EdrawMind
main page

Get Started! You Will Love This Easy-To-Use Diagram Software

EdrawMax is an advanced all-in-one diagramming tool for creating professional flowcharts, org charts, mind maps, network diagrams, UML diagrams, floor plans, electrical diagrams, science illustrations, and more. Just try it, you will love it!