This example shows you how to create a PDF out of a VB6 application.

When the code is executed, the PDF engine of the PDF Maker is used for PDF generation. PDF creation takes into account the PDF settings that were previously set using the corresponding PDF Setting functions of the COM component.

After the PDF conversion has been triggered using the function convertToPDF, the code waits for the return code of the PDF engine. This ensures that the developer knows exactly when and if the PDF generation was successfully completed.

The code sample below is available for download at the bottom of the page.

Source text extract of the source code example (VB6)

  1. Private Sub btnCallConvert_Click()
  2.  
  3. 'Early binding of Var SevenPDFComObj: Please select TypeLibrary "SevenPDFComObj Library" over Project -> References, first!
  4. Dim SevenPDFComObj As New SevenPDFComObj.SevenPDFObjConverter
  5.  
  6. e = 0
  7. On Error GoTo err_handler
  8.    
  9.     '******* INITIALIZATION *********
  10.    
  11.     SevenPDFComObj.Init
  12.     'SevenPDFComObj.UnlockKey ("INSERT LICENSEKEY")
  13.    
  14.     '********************************
  15.    
  16.     '****** Customize some PDF Settings *******
  17.     'Notice: PDF encryption works only in registered version
  18.     '******************************************
  19.    
  20.     SevenPDFComObj.setExportNotes (0)
  21.     SevenPDFComObj.setExportNotesPages (0)
  22.     SevenPDFComObj.setExportBookmarks (0)
  23.    
  24.     'Set PDF Security Options
  25.     'SevenPDFComObj.setEncryptFile (1)
  26.     'SevenPDFComObj.setPermissionPassword ("test1232")
  27.     'SevenPDFComObj.setRestrictPermissions (1)
  28.     'SevenPDFComObj.setChanges (0)
  29.     'SevenPDFComObj.setPrinting (1)
  30.     'SevenPDFComObj.setEnableCopyingOfContent (0)
  31.     'SevenPDFComObj.setEnableTextAccessForAccessibilityTools (0)
  32.        
  33.     'Make the Conversion
  34.    
  35.     txtReturncode.Text = CStr(SevenPDFComObj.convertToPdf(txtFile.Text, txtPDF.Text, 0))
  36.    
  37.     Exit Sub
  38.    
  39. err_handler:
  40.  
  41.    MsgBox "Unvorhergesehener Fehler in Modul" & Chr(10) & Chr(13) _
  42.         & "Beschreibung: " & Err.Description & "", vbExclamation, "Runtime - Error: " & Err.Number & ""
  43.    
  44.    Exit Sub
  45.    
  46. End Sub
  47.  
  48. Private Sub btnSelect_Click()
  49. With CommonDialog1
  50.     .FileName = ""
  51.     .Filter = "All supported Files (*.*)|*.*|Microsoft Office 2007 Files (*.docx;*.xlsx;*.pptx)|*.docx;*.xlsx;*.pptx|Microsoft Office Files (*.doc;*.xls;*.ppt)|*.doc;*.xls;*.ppt|OpenOffice.org 1.0 Files (*.sxw;*.sxc;*.swi)|*.sxw;*.sxc;*.swi|OpenDocument Files (*.odt;*.ods;*.odp;*.odg;*.odf)|*.odt;*.ods;*.odp;*.odg;*.odf|StarOffice Files (*.sdw;*.sdc;*.swi;*.smf;*.vor)|*.sdw;*.sdc;*.swi;*.smf;*.vor|Text based Files (*.rtf;*.txt;*.csv)|*.rtf;*.txt;*.csv|Web based Files (*.htm;*.html;*.xml)|*.htm;*.html;*.xml|Maths Files (*.mml;*.odf;*.sxm;*.smf)|*.mml;*.odf;*.sxm;*.smf|Image Files (*.eps;*.tif;*.jpg;*.jpeg;*.png;*.gif;*.bmp)|*.eps;*.tif;*.jpg;*.jpeg;*.png;*.gif;*.bmp|AutoCAD / Data Interchange Formats (*.dxf;*.dif)|*.dxf;*.dif" 'Sets the filter
  52.     .ShowOpen
  53. End With
  54.  
  55. txtFile.Text = CommonDialog1.FileName
  56.  
  57. End Sub
  58.  
  59. Private Sub btnSelectPDF_Click()
  60.  
  61. With Me.CommonDialog1
  62.   .Filter = "PDF File (*.pdf)|*.pdf"
  63.   .FileName = "output.pdf"
  64.   .DefaultExt = "pdf"
  65.   .ShowSave
  66. End With
  67.  
  68. txtPDF.Text = CommonDialog1.FileName
  69.  
  70. End Sub

Downloads

Attachment Size
Download the code sample 3.82 KB
Top