Embed PDF in VB 6 and Automating PDF

> Edraw Tip > Embed PDF in VB 6 and Automating PDF
author
Posted by James Freeman |
PDF viewer component is an easy and reliable solution for the developers to embed pdf documents in a vb application.

With PDF viewer component, it's easy for the vb developers to embed an existing pdf files in a form then disable the print, save and copy functions.

At form load event the developers can use the LoadFile method to load pdf files from the hard drive or server and open in an area on the form. The PDF file can be read-only, full edited, or prohibited to save by different requirements. The developers can also change the pdf display options easily with the vb 6 component.

Click Here to Download PDF Viewer Component - Support vb6, vb.net project

free download

Display PDF Files in VB 6 Form

In this part, we will show the detailed sample code on how to create and customize PDF document windows in VB 6 class. But before this, please make sure that you have embedded PDF Viewer Component into your created VB 6 desktop application.

If you haven't the pdfviewer.ocx file, you need to install the package firstly.

Start Visual Basic and create a new standard project. Form1 is created by default.

Right click on any of the tabs in your toolbox and click choose items.

vb 6 add components...

In the pop up dialog, check the PDF Viewer Component.

vb6 choose pdf

Click the Ok button.

The PDF Viewer Component was added in the Toolbar window.

Toolbox

Switch to a VB 6 form, then add the component in it.

vb6 embed pdf component

The component includes lots of methods, events and properties to customize the Adobe Reader window.

The developer can use the following code to open a pdf file in the Form_Load Event.

Private Sub OpenPDF_Click()
With CommonDialog1
.DefaultExt = "pdf"
.Filter = "PDF File Formats (*.pdf)|*.pdf|All Files (*.*) | *.* ||"
.FilterIndex = 1
End With
CommonDialog1.ShowOpen
PDFViewer1.LoadFile CommonDialog1.FileName
End Sub

To protect the Excel worksheet from modification by the end user, the developer needs to add the following code in the DocumentOpened event.

Private Sub EDOffice_DocumentOpened()
EDOffice1.ProtectDoc 1 ' XlProtectTypeNormal
End Sub

There are some wrapped excel automation methods available to create or modify Excel data.

bool ExcelAddWorkSheet(long Index);
bool ExcelDeleteWorkSheet(long Index);
bool ExcelActivateWorkSheet(long Index);
long ExcelGetWorkSheetCount();
bool ExcelSetCellValue(long Column, long Row, BSTR Value);
BSTR ExcelGetCellValue(long Column, long Row);
bool ExcelSetRowHeight(long Row, double Height);
bool ExcelSetColumnWidth(long Column, double Width);
afx_msg bool ExcelDeleteRow(long Row);
bool ExcelDeleteColumn(long Column);
bool ExcelInsertRow(long Row);
bool ExcelInsertColumn(long Column);
bool ExcelInsertPageBreakInRow(long Row);
bool ExcelInsertPageBreakInColumn(long Column);
bool ExcelCopyToClipboard();
bool ExcelPasteStringToWorksheet(BSTR bstText);

Disable Adobe Reader Edit Function from Visual Basic

In the code window for Form1, insert the following code:

Private Sub DisableAdobeReader_Click()
PDFViewer1.SetReadOnly
PDFViewer1.DisableHotKeyCopy
PDFViewer1.DisableHotKeyPrint
PDFViewer1.DisableHotKeySave
PDFViewer1.DisableHotKeySearch
PDFViewer1.DisableHotKeyShowBookMarks
PDFViewer1.DisableHotKeyShowThumnails
PDFViewer1.DisableHotKeyShowToolbars
End Sub

Press F5 to run the project. The pdf file will be open in the vb 6 window. The user can not changed or copy the pdf files.

disable pdf vb6

With the PDF viewer component, you are not only able to view PDF documents, but also able to disable print, disable copy, disable edit and change the pdf window options.

Embedding MS Word in VB 6 and Do Word Automation

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!