spacer
spacer

Visual Basic & VB.NET resources | VBprofs.com

Google
 
Main Menu
Home
IT News
Articles
Source Codes
Books
Calendar of Events
Publish your Content
Links Directory
Reviews and Recs
Premium Content
 VBprofs Premium Content Become a member to get access to our premium content! 

 Membership is entirely free, and allows you to:
  •  access programming projects posted by our partners;
  •  publish your articles, news, links;
  •  publish a project request;
  •  access our VB Careers section.
Polls
How did you reach VBprofs.com?
  
Which is your favorite programming language?
  
Related Items
 
Home arrow Articles arrow Visual Basic / .NET Articles arrow SharpPDF Usage in VB6

SharpPDF Usage in VB6 PDF Print E-mail
Written by Thomas Kaloyani   
Sunday, 09 April 2006
Most people are looking on how to create PDF documents through their VB applications, but 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 cool C# library based on .NET Framework 1.1 and creates 100% compatible PDF document. More information about SharpPDF library can be found on sharppdf.sourceforge.net.


Visual Basic developers can't use this library straight. If you register the SharpPDF and try to create the pdfDocument method you'll get an error. So how can you take advantage of sharpPDF? A choice I can think of is to change the code of sharpPDF based on your needs. If you don't want to mess up with the code of sharpPDF you can simply create a wrapper library with VB.NET, register the assembly and reference the wrapper through you VB6 project.

To register the assembly use the following command:
regasm /tlb: mywrapper.tlb /codebase mywrapper.dll

and from your VB6 project add a refence to mywrapper.tlb

Sample Code of wrapper created with VB.NET:

Imports sharpPDF

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(ByVal Value As String)
m_sTitle = Value
End Set
End Property

Public WriteOnly Property Author() As String
Set(ByVal Value As String)
m_sAuthor = Value
End Set
End Property

Public WriteOnly Property Content() As String
Set(ByVal Value As String)
m_sContent = Value
End Set
End 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
End Function
End Class

Sample Code for calling the wrapper through your VB6 project:

Dim o As New clsSharpPDFWrapper
o.Title = "My First PDF Document"
o.Author = "Thomas Kaloyani"
o.Content = "Hello World!"
o.createPDFDocument

Happy coding!


Thomas is an experienced Visual Basic developer, with expertise of 7+ years developing especially financial applications. His main IT skills are VB, SQL, Crystal Reports - should you need a Visual Basic developer for your projects feel free to contact Thomas through his personal website www.Kaloyani.com or through VBprofs.com - the newest Visual Basic and VB.NET resources portal.

Source: www.VBprofs.com
< Prev   Next >

 
Antivirus Shop
BitDefender Antivirus v10
Newsflash

PowerRefresh 1.0 released!
A simple yet extremely useful tool for webmasters, publishers and SEO working bees: PowerRefresh allows you to automatically refresh your IE windows every x minutes. It can handle unlimited number of windows and, unlike similar applications, is using full browsers.


Get PowerRefresh from Kaloyani.com: download
Login Form
Username

Password

Remember me
Forgotten your password?
No account yet? Create one
Popular

VBprofs.com - online resources for Visual Basic and VB.NET professionals: Visual Basic and VB.NET articles, industry news and events, career tools, VB / VB.NET books, calendar and much more. VBprofs.com is an interactive web site with free membership.
(c) Copyright 2005 - 2006 by VBprofs.com
powered by Mambo Open Source Software
spacer