Click here to Skip to main content
15,880,608 members

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
        sd.Fill(dt)
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)
 Next
Dim filename As String = "test.pdf"
document.Save(filename)
End sub


I think am Missing something may be the loop.Please assist.Any Ideas
Tags: Visual Basic

Plain Text
ASM
ASP
ASP.NET
BASIC
BAT
C#
C++
COBOL
CoffeeScript
CSS
Dart
dbase
F#
FORTRAN
HTML
Java
Javascript
Kotlin
Lua
MIDL
MSIL
ObjectiveC
Pascal
PERL
PHP
PowerShell
Python
Razor
Ruby
Scala
Shell
SLN
SQL
Swift
T4
Terminal
TypeScript
VB
VBScript
XML
YAML

Preview



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.
  4. Don't tell someone to read the manual. Chances are they have and don't get it. Provide an answer or move on to the next question.
Let's work to help developers, not make them feel stupid.
Please note that all posts will be submitted under the http://www.codeproject.com/info/cpol10.aspx.



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