Click here to Skip to main content
13,295,051 members (69,049 online)

How to create PDF file with DataBase Values

Karwa_Vivek asked:

Open original thread
Hi am Using PDFSharp dll
to creates a Pdf file and to save the file in a Folder.
Ny Problem is that when i am passing a particular
string from textbox to the DrawString
the result is fine but when I am using
Database Values to show in the created
Pdf all the written values are overlapping in the same Place.
I mean I am just getting a black image in the Pdf File.
Below is the Code i am trying'
public sub create()
Dim document As PdfDocument = New PdfDocument
document.Info.Title = "testPdf"
' Create an empty page
        Dim page As PdfPage = document.AddPage
        ' Get an XGraphics object for drawing
        Dim gfx As XGraphics = XGraphics.FromPdfPage(page)
Dim font As XFont = New XFont("Verdana", 20, XFontStyle.Bold)
        'Fetch Values from DataBase
        Dim id As Integer = 0
        Dim sd As New SqlDataAdapter("Select * from testTable", myCon.con)
        Dim dt As New DataTable
For i2 As Integer = 0 To dt.Rows.Count - 1
                id = dt.Rows(i2).Item("ID")
               gfx.DrawString("" & id & "", font, XBrushes.Black, New XRect(0, 0, page.Width.Point, page.Height.Point), XStringFormats.TopLeft)
Dim filename As String = "test.pdf"
End sub

I think am Missing something may be the loop.Please assist.Any Ideas
Tags: VB, VB.NET


When answering a question please:
  1. Read the question carefully.
  2. Understand that English isn't everyone's first language so be lenient of bad spelling and grammar.
  3. If a question is poorly phrased then either ask for clarification, ignore it, or edit the question and fix the problem. Insults are not welcome.
Let's work to help developers, not make them feel stupid.
Please note that all posts will be submitted under the The Code Project Open License (CPOL).

Advertise | Privacy |
Web04 | 2.8.171207.1 | Last Updated 26 Mar 2009
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100