Click here to Skip to main content
15,878,543 members
Please Sign up or sign in to vote.
1.00/5 (3 votes)
See more:
how to create pdf file in vb.net ;)
Posted
Updated 27-Jan-19 18:23pm
Comments
[no name] 5-Feb-16 5:58am    

 
Share this answer
 
Comments
Member 12314871 8-Feb-16 17:13pm    
If I'm looking for a VB.NET solution, why would I want to look at a C# example?
Kevin Dondrea 27-Apr-17 5:19am    
I get mad when C# people do that too but Abhinav was really nice about it. Some of the developers on StackOverflow and their related pages are real donkeys and talk down to people and are very abusive. Abhinav was very polite.
You can also just use the CrystalDecisions.CrystalReports.Engine.ReportClass to export to a pdf file.
 
Share this answer
 
Microsoft .NET doesn't yet include a PDF component, so you'll need to use a third-party component, unless you enjoy doing stuff the hard way, and have plenty of time to spare.

Here are a few popular components for the task - ABCpdf.NET, iTextsharp, PDFSharp.

Some of these are free for personal use, but for commercial purposes you may need to purchase a license. It's certainly worth checking the small print before you begin ;-)

Here's a quick example in VB.NET to show how easy PDF generation can be...

Dim theDoc As Doc = New Doc()
theDoc.FontSize = 96
theDoc.AddText("Hello World")
theDoc.Save("simple.pdf")
theDoc.Clear()


The example above uses the ABCpdf component from WebSupergoo.

All these components feature their own native drawing commands, which enable you to draw and construct pages and documents. One of the differences between these components is what other methods of layout and formatting they offer, e.g. HTML & CSS, Drawing2D, WPF, Flash, PostScript. If you already know one of these, and your chosen components support it, this can help you get up to speed and generate more complex layouts sooner.
 
Share this answer
 
v2
There is a CodeProject article that explains how to create PDFs and includes a C# library that you can use to create PDFs. You can call the C# library from VB .NET.

See PDF File Writer C# Class Library[^]
 
Share this answer
 
Comments
Member 12314871 8-Feb-16 17:16pm    
If I am looking for a VB.NET solution why would I view a C# example? Isn't there a C# section on this site these responses could be moved to?
Mike Meinz 8-Feb-16 17:46pm    
You could use one of the online C# to VB.NET converter tools to make a VB.NET version for your use.
Please look into following link

http://itextsharp.com/[^]
 
Share this answer
 
Comments
Member 12314871 8-Feb-16 17:17pm    
If I am looking for a VB.NET solution why would I view a C# example? Isn't there a C# section on this site these responses could be moved to?
What do you exactly want, creating a PDF or convert a document to PDF?
You can use itextsharp[^] to create PDF.

Here are some articles(in C# unfortunately) from where you can get idea.
ITextSharp Helper Class[^]
Tutorials on creating PDF files using C# 2.0[^]
 
Share this answer
 
Comments
Member 12314871 8-Feb-16 17:17pm    
If I am looking for a VB.NET solution why would I view a C# example? Isn't there a C# section on this site these responses could be moved to?
I found this post when I searching for something about PDF.

Actually, others have given the solutions. But I want to show my solutions.

Code

C#
//Create a pdf document.
PdfDocument doc = new PdfDocument();

// Create one page
PdfPageBase page =doc.Pages.Add();

//Draw the text
page.Canvas.DrawString("Hello, World!",
                       new PdfFont(PdfFontFamily.Helvetica, 30f),
                       new PdfSolidBrush(Color.Black),
                       10, 10);

//Save pdf file.
doc.SaveToFile("HelloWorld.pdf");


How about this? I create it with a third party component
 
Share this answer
 
Comments
Member 10424878 6-Aug-14 6:53am    
There must be a .DLL file that you use, it doesn't work for me...
I am not try this code
You can try and give me reply what happen


VB
Private Sub prn_PrintPage(ByVal sender As System.Object, _
                             ByVal e As System.Drawing.Printing.PrintPageEventArgs)

       e.Graphics.DrawString("Hello from VB.NET", New Font("Arial", 60, FontStyle.Regular), _
                             Brushes.Blue, 100, 100)

   End Sub

   Private Sub PrintTest()
       Dim DC As Object = CreateObject("Neevia.docCreator")

       DC.setParameter("DocumentOutputFormat", "PDF")
       DC.setParameter("DocumentOutputName", "testVBNET")
       DC.setParameter("DocumentOutputFolder", "d:\")

       Dim prn As New System.Drawing.Printing.PrintDocument
       AddHandler prn.PrintPage, AddressOf prn_PrintPage
       prn.PrinterSettings.PrinterName = "Neevia docCreator"

       Dim tempFile As String = DC.getParameter("TempDir") + DC.GUID + ".ps"

       prn.PrinterSettings.PrintFileName = tempFile
       prn.PrinterSettings.PrintToFile = True

       prn.Print()

       DC.setInputDocument(tempFile)

       Dim RVal As Integer = DC.create()
       DC.fileDelete(tempFile)

       prn = Nothing
       DC = Nothing

       If (RVal <> 0) Then
           MsgBox("Error while creating document!!!")
       Else
           MsgBox("Done !!!")
       End If
   End Sub
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900