PDF with VB.NET
PDF generation with Visual Basic .NET
The example will show how you can use the COM interface of our PDF Maker with the .NET Framework for PDF generation. In the code example, we use VB.NET as the programming language. However, the example can be easily abstracted to C# or even ASP.NET web applications.
The use of the component in the example also shows the exemplary setting of PDF setting options using the PDF Setting functions of the component and the actual PDF conversion of the input file via the PDF conversion function convertToPDF
.
The return code of the PDF engine is then output in a text box. Using the return code, the developer knows exactly when and if the PDF generation has been completed successfully, and can respond flexibly to this program-programmatically.
Execution errors due to different uses of .NET versions
The VB.NET example that can be downloaded here was created with the .NET Framework 3.5. If when executing the sample project a message appears that the original runtime environment is more current than the currently loaded one, you must select the newer .NET Framework version (e.g. 4.7.2) in the project configuration of our example for VB.NET. Then clean up the project before you recreate or compile it, and run it without errors. Also make sure that the target CPU x86 is selected under the project properties!
Source text extract of the source code example (VB.NET)
The code sample below is available for download at the bottom of the page.
- Public Class frmSevenPDFCOMClient
- Private Sub btnSelectFile_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSelectFile.Click
- Dim strDatei As String
- 'Select a File that should be convert to PDF here
- With OpenFileDialog1
- .FilterIndex = 1
- If .ShowDialog() = Windows.Forms.DialogResult.OK Then
- strDatei = .FileName
- txtFile.Text = strDatei
- End If
- End With
- End Sub
- Private Sub btnConvertToPDF_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnConvertToPDF.Click
- Dim SevenPDFComObj As New SevenPDFComObj.SevenPDFObjConverter
- 'COM DLL INVOKE CALL TO SevenPDFComObj.dll
- 'Note that you must register the ActiveX DLL first
- 'Use [regsvr32 "FULLPATH TO DLL FOLDER\SevenPDFComObj.dll"]
- 'Pleas Notice: You need administrative privileges for that!
- Try
- txtReturnCode.Text = ""
- '******* INITIALIZATION *********
- SevenPDFComObj.Init()
- 'SevenPDFComObj.UnlockKey ("INSERT LICENSEKEY")
- '********************************
- '****** Customize some PDF Settings *******
- 'Notice: PDF encryption works only in registered version
- '******************************************
- SevenPDFComObj.setExportNotes(0)
- SevenPDFComObj.setExportNotesPages(0)
- SevenPDFComObj.setExportBookmarks(0)
- 'Set PDF Security Options
- 'SevenPDFComObj.setEncryptFile (1)
- 'SevenPDFComObj.setPermissionPassword ("test1232")
- 'SevenPDFComObj.setRestrictPermissions (1)
- 'SevenPDFComObj.setChanges (0)
- 'SevenPDFComObj.setPrinting (1)
- 'SevenPDFComObj.setEnableCopyingOfContent (0)
- 'SevenPDFComObj.setEnableTextAccessForAccessibilityTools (0)
- 'Make the Conversion
- txtReturnCode.Text = SevenPDFComObj.convertToPdf(txtFile.Text, txtPDF.Text, 0).ToString()
- Catch ex As Exception
- MsgBox("Error occurs: " & ex.Message)
- End Try
- End Sub
- Private Sub btnSelectPDF_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSelectPDF.Click
- Dim strDatei As String
- 'Select a File that should be convert to PDF here
- With SaveFileDialog1
- .FilterIndex = 1
- If .ShowDialog() = Windows.Forms.DialogResult.OK Then
- strDatei = .FileName
- txtPDF.Text = strDatei
- End If
- End With
- End Sub
- End Class
Downloads
Attachement | Size |
---|---|
Download the code sample | 129.23 KB |