Results 1 to 6 of 6

Thread: VB2005 PDF Document Creator Component

Threaded View

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Mar 2006
    Posts
    235

    VB2005 PDF Document Creator Component

    Title: vbPDF
    Description: PDF document creator, written in VB 2005
    Author name: Ken Bradford
    License info: Open Source, GNU General Public License

    To use, just add the following three files to the your project: vbPdf.vb, vbPdfFonts.vb and vbPdfRoutines.vb.

    Code:
        'This example will show you how to display text in a document.
    
        Me.Cursor = Cursors.WaitCursor
    
        'Creates a new instance of cPdf.
        Dim cPDF As New vbPDF
    
        With cPDF
          .ReportFileName = "c:\Text.pdf"
          .ScaleMode = pdf.ScaleMode.Inch
          .PaperSize = pdf.PaperSize._8_5x11
          .Author = "Ken Bradford"
          .Title = "Example 2a - Text"
    
          If Not .CreatePDFFile() Then
            Me.Cursor = Cursors.Default
            Exit Sub
          End If
    
          'This example will be using the following fonts: Arial, ArialBold, ArialItalic, CourierNew and CourierNewBold.
          .LoadFont("Arial", pdf.FontName.Arial, pdf.FontStyle.Regular)
          .LoadFont("ArialItalic", pdf.FontName.Arial, pdf.FontStyle.Italic)
          .LoadFont("ArialBold", pdf.FontName.Arial, pdf.FontStyle.Bold)
          .LoadFont("CourierNew", pdf.FontName.CourierNew, pdf.FontStyle.Regular)
          .LoadFont("CourierNewBold", pdf.FontName.CourierNew, pdf.FontStyle.Bold)
    
          .StartPage()
    
          'PDF DRAWS A PAGE FROM THE BOTTOM TO THE TOP.
    
          'PageWidthInInch returns the width of the page. In this case it will return 11, since .PaperSize = pdf.PaperSize._8_5x11.
          'x will be set to 5.5 (11 / 2).
          Dim x As Single = .PageWidthInInch / 2
    
          'PageHeightInInch returns the height of the page. In this case it will return 8.5, since .PaperSize = pdf.PaperSize._8_5x11.
          'y will be set to 4.25 (8.5 / 2).
          Dim y As Single = .PageHeightInInch / 2
    
          'Text Alignment.
          .DrawText(x, 10.25, "This text is align left from the center of the page", "Arial", 12, pdf.TextAlignment.Left, Color.Red)
          .DrawText(x, 10, "This text is align center from the center of the page", "Arial", 12, pdf.TextAlignment.Center, Color.Green)
          .DrawText(x, 9.75, "This text is align right from the center of the page", "Arial", 12, pdf.TextAlignment.Right, Color.BlueViolet)
    
          'Different font styles on the same line.
          .DrawText(2.5, 8, "Name", "Arial", 12, pdf.TextAlignment.Right, Color.Black)
          .DrawText(2.6, 8, "Jack Benny", "ArialBold", 12, pdf.TextAlignment.Left, Color.Black)
          .DrawText(5, 8, "Age", "Arial", 12, pdf.TextAlignment.Right, Color.Black)
          .DrawText(5.1, 8, "39", "ArialBold", 12, pdf.TextAlignment.Left, Color.Black)
          .DrawText(2.5, 7.8, "Profession", "Arial", 12, pdf.TextAlignment.Right, Color.Black)
          .DrawText(2.6, 7.8, "Star of Stage, Screen, Radio and Television", "ArialBold", 12, pdf.TextAlignment.Left, Color.Black)
          .DrawText(2.5, 7.6, "Place of Birth", "Arial", 12, pdf.TextAlignment.Right, Color.Black)
          .DrawText(2.6, 7.6, "Waukegan, Illinois", "ArialBold", 12, pdf.TextAlignment.Left, Color.Black)
    
    
          'Underlining text.
          .DrawText(0.25, 6.2, "This is Arial text, underlined.", "Arial", 15, pdf.TextAlignment.Left, Color.SeaGreen, Color.SeaGreen, 0.001)
          .DrawText(0.25, 6.0, "This is Arial Italic text, underlined.", "ArialItalic", 15, pdf.TextAlignment.Left, Color.SeaGreen, Color.SeaGreen, 0.001)
          .DrawText(0.25, 5.8, "This is Arial Bold text, underlined.", "ArialBold", 15, pdf.TextAlignment.Left, Color.SeaGreen, Color.SeaGreen, 0.001)
          .DrawText(0.25, 5.6, "This is CourierNew text, underlined.", "CourierNew", 15, pdf.TextAlignment.Left, Color.SeaGreen, Color.SeaGreen, 0.001)
          .DrawText(0.25, 5.4, "This is CourierNew Bold text, underlined.", "CourierNewBold", 15, pdf.TextAlignment.Left, Color.SeaGreen, Color.SeaGreen, 0.001)
    
          .DrawText(0.25, 4.5, "This text is underlined with a line thickness of .01 inch", "CourierNew", 15, pdf.TextAlignment.Left, Color.Firebrick, Color.Firebrick, 0.01)
          .DrawText(0.25, 4.25, "This text is underlined with a line thickness of .02 inch", "CourierNew", 15, pdf.TextAlignment.Left, Color.Firebrick, Color.Firebrick, 0.02)
          .DrawText(0.25, 4, "This text is underlined with a line thickness of .03 inch", "CourierNew", 15, pdf.TextAlignment.Left, Color.Firebrick, Color.Firebrick, 0.03)
          .DrawText(0.25, 3.75, "This text is underlined with a line thickness of .04 inch", "CourierNew", 15, pdf.TextAlignment.Left, Color.Firebrick, Color.Firebrick, 0.04)
          .DrawText(0.25, 3.5, "This text is underlined with a line thickness of .05 inch", "CourierNew", 15, pdf.TextAlignment.Left, Color.Firebrick, Color.Firebrick, 0.05)
          .DrawText(0.25, 3.25, "This text is underlined with a line thickness of .06 inch", "CourierNew", 15, pdf.TextAlignment.Left, Color.Firebrick, Color.Firebrick, 0.06)
          .DrawText(0.25, 3, "This text is underlined with a line thickness of .07 inch", "CourierNew", 15, pdf.TextAlignment.Left, Color.Firebrick, Color.Firebrick, 0.07)
    
          .DrawText(3, 2.5, "Black text underlined in Blue.", "Arial", 15, pdf.TextAlignment.Left, Color.Black, Color.Blue, 0.001)
          .DrawText(3, 2.25, "Yellow text underlined in Green.", "Arial", 15, pdf.TextAlignment.Left, Color.Yellow, Color.Green, 0.001)
          .DrawText(3, 2, "Purple text underlined in Violet.", "Arial", 15, pdf.TextAlignment.Left, Color.Purple, Color.Violet, 0.001)
    
          .EndPage()
    
          .ClosePDFFile()
    
        End With
    
        Try
          System.Diagnostics.Process.Start("c:\Text.pdf")
        Catch ex As Exception
          Me.Cursor = Cursors.Default
          MessageBox.Show("Unable to display PDF Document 'c:\Text.pdf" & "'.'" & Environment.NewLine & Environment.NewLine & ex.Message, Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Error)
        End Try
    
        Me.Cursor = Cursors.Default
    Attached Images Attached Images
    Attached Files Attached Files
    Last edited by Ken B; Jun 17th, 2007 at 08:26 AM. Reason: Added report produced by the sample code

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width