Using Sharp PDF in VB6
Most of the people are looking for how to create PDF documents through their VB applications, but they don’t want to spend money to buy Adobe Acrobat SDK or other third-party components. If you don’t want to invest money, there is an open source solution for you, SharpPDF. SharpPDF is a very interesting C# library based on the .NET Framework 1.1 and created a 100% compatible PDF document. More information about the SharpPDF library can be found at sharppdf.sourceforge.net.
Visual Basic developers cannot use this library directly. If you register SharpPDF and try to create the pdfDocument method, you will get an error. So how can you take advantage of sharpPDF? One option I can think of is to change the sharpPDF code to suit your needs. If you don’t want to mess with the sharpPDF code, you can simply create a container library with VB.NET, register the assembly, and reference the container through your VB6 project.
To register the assembly use the following command:
regasm /tlb:mywrapper.tlb /codebase mywrapper.dll
and from your VB6 project add a reference to mywrapper.tlb
Sample wrapper code created with VB.NET:
sharpPDF imports
Public class clsSharpPDFWrapper
Private m_sTitle as string
Private m_sAuthor as string
private m_sContent as string
Public WriteOnly Property Title() as String
Set (ByValueValueAsString)
m_sTitle=Value
final set
final property
Public WriteOnly Property Author() as String
Set (ByValueValueAsString)
m_sAuthor=Value
final set
final property
WriteOnly() public property content as string
Set (ByValueValueAsString)
m_sContent = Value
final set
final property
Public function CreatePDFDocument()
Dim oPDF as new sharpPDF.pdfDocument(m_sTitle, m_sAuthor)
Dim oPDFPage as sharpPDF.pdfPage =
oPDF.addPage(sharpPDF.Enumerators.predefinedPageSize.csA4Page)
oPDFPage.addText(m_sContent, 200, 450,
oPDF.getFontReference(Enumerators.predefinedFont.csHelvetica), 20,
pdfColor.Black)
oPDF.createPDF(“c:MyPDFDoc.pdf”)
oPDFPage = Nothing
oPDF = Nothing
final function
final class
Sample code to call the container through your VB6 project:
Dim or As New clsSharpPDFWrapper
o.Title = “My first PDF document”
o.Author = “Thomas Kaloyani”
o.Content = “Hello world!”
o.createPDFDocument
Happy coding!