none
Create or Write a pdf file ... RRS feed

  • Question

  • Is there any way to create and write a pdf file in vb.net without third party tools or dlls ???
    Monday, July 22, 2013 9:21 AM

Answers

All replies

  • Hi ,

    .net has no native support for PDF

    You have to use 3rd party libraries

    http://stackoverflow.com/questions/4804295/free-pdf-library

    Regards,

    stygen

    • Marked as answer by Wall.E Wednesday, July 24, 2013 6:18 AM
    Monday, July 22, 2013 2:04 PM
    • Edited by QianQ Monday, August 19, 2013 8:40 AM
    Monday, August 19, 2013 8:39 AM
  • Hi Wall.E,

    If you have MS Office then you can use its PIA assembly to achieve your task. You can find a list of included components here. What you need to include is a Word Interop that will work in .NET.

    Here is a sample code:

    Imports Microsoft.Office.Interop.Word
    
    ' ...
    
    ' Create new document
    Dim application = New Application()
    Dim document = application.Documents.Add()
    
    ' Add some content
    Dim paragraph As Paragraph = document.Content.Paragraphs.Add()
    Dim paragraphRange As Range = paragraph.Range
    paragraphRange.Text = "Hello World!"
    paragraphRange.InsertParagraphAfter()
    
    ' Export document as PDF.
    document.ExportAsFixedFormat(OutputFileName:="C:\Sample.pdf", ExportFormat:=WdExportFormat.wdExportFormatPDF)
    
    ' Cleanup
    document.Close()
    application.Quit()
    System.Runtime.InteropServices.Marshal.ReleaseComObject(application)
    If you do not have MS Office on your machine, or if the machine that is intendent to run your application does not have it then you will have to use some 3rd party. I can recommend you this Word processing component for .NET, it has a really easy interface.

    Here is how you can create and write PDF files in .NET:

    Imports GemBox.Document
    
    ' ...
    
    ' Create new document
    Dim document = New DocumentModel()
    
    ' Add some content
    document.Sections.Add(
        New Section(document,
            New Paragraph(document, "Hello world!")))
    
    ' Export document as PDF.
    document.Save("C:\Document.pdf")

    Wednesday, October 15, 2014 7:46 AM