MJ
Mirza Javed
January 12, 2007 04:01 PM UTC
The version is 4.1.0.62
What I am basically trying to do is read the data from a database and draw the text in the pdf document.
Here is the code...
I use a stored procedure to populate the Data Reader and then use the values in the Data Reader to draw the text in the PDF document.
Try
....
....
....
....
sqlConn.Open()
DataReader = sqlCommand.ExecuteReader()
While DataReader.Read()
'******** Create a new PDF Document. The pdfDoc object represents the PDF document.
'******** This document has one page by default and additional pages have to be added.
Dim pdfDoc As PDFDocument = New PDFDocument
pdfDoc.AutoCreatePages = True
Dim props As IPDFGraphicState = pdfDoc.CreateGraphicState()
props.BreakBehavior = AutoBreakBehavior.MultiLineTextBreak
'******** Adding a font that can be used to draw Text inside the PDF document.
'******** Using the Predefined fonts to draw the text.
Dim pdfFont As IPDFFont = pdfDoc.Fonts.Add(FontBaseFamily.TimesRoman)
Dim pdfBold As IPDFFont = pdfDoc.Fonts.Add(FontBaseFamily.TimesBold)
Dim pdfHeader As IPDFFont = pdfDoc.Fonts.Add(FontBaseFamily.TimesBold)
pdfHeader.Size = "20"
'******** Draw text at the specified Location.
pdfDoc.Graphics.DrawImage(New PointF(0, 0), Server.MapPath("images/strategiclogodla.jpg"))
pdfDoc.Graphics.DrawText(200, 10, "SFI Coaching & Training Record", pdfHeader)
pdfDoc.Graphics.DrawText(0, 75, "Agent being Evaluated:", pdfBold)
pdfDoc.Graphics.DrawText(300, 75, DataReader("TSR Name"), pdfFont)
pdfDoc.Graphics.DrawLine(New PointF(300, 90), New PointF(500, 90))
pdfDoc.Graphics.DrawText(0, 110, "Date Evaluated:", pdfBold)
pdfDoc.Graphics.DrawText(300, 110, DataReader("lastchangeddate"), pdfFont)
pdfDoc.Graphics.DrawLine(New PointF(300, 125), New PointF(500, 125))
pdfDoc.Graphics.DrawText(0, 145, "Team Leader / Manager performing Evaluation:", pdfBold)
pdfDoc.Graphics.DrawText(300, 145, DataReader("Evaluator"), pdfFont)
pdfDoc.Graphics.DrawLine(New PointF(300, 160), New PointF(500, 160))
pdfDoc.Graphics.DrawText(0, 180, "Type of Evaluation:", pdfBold)
pdfDoc.Graphics.DrawText(300, 180, DataReader("evaltype"), pdfFont)
pdfDoc.Graphics.DrawLine(New PointF(300, 195), New PointF(500, 195))
pdfDoc.Graphics.DrawText(0, 215, "Reason for Session:", pdfBold)
pdfDoc.Graphics.DrawText(300, 215, DataReader("evalreason"), pdfFont)
pdfDoc.Graphics.DrawLine(New PointF(300, 230), New PointF(500, 230))
pdfDoc.Graphics.DrawText(0, 250, "Project:", pdfBold)
pdfDoc.Graphics.DrawText(300, 250, DataReader("project"), pdfFont)
pdfDoc.Graphics.DrawLine(New PointF(300, 265), New PointF(500, 265))
pdfDoc.Graphics.DrawText(0, 285, "Position Evaluated:", pdfBold)
pdfDoc.Graphics.DrawText(300, 285, DataReader("evalposition"), pdfFont)
pdfDoc.Graphics.DrawLine(New PointF(300, 300), New PointF(500, 300))
pdfDoc.Graphics.DrawText(0, 320, "Call Index:", pdfBold)
pdfDoc.Graphics.DrawText(300, 320, DataReader("callindex"), pdfFont)
pdfDoc.Graphics.DrawLine(New PointF(300, 335), New PointF(500, 335))
pdfDoc.Graphics.DrawText(0, 355, "Comments:", pdfBold)
pdfDoc.Graphics.DrawMultiText(0, 375, 500, 250, DataReader("evalcomments"), pdfFont, props)
pdfDoc.Graphics.DrawText(0, 650, "I have given/received this feedback and" & _
" understand the importance of the points made.", pdfFont)
pdfDoc.Graphics.DrawText(0, 720, "_________________________________", pdfFont)
pdfDoc.Graphics.DrawText(300, 720, "_________________________________", pdfFont)
pdfDoc.Graphics.DrawText(0, 740, DataReader("Evaluator"), pdfFont)
pdfDoc.Graphics.DrawText(300, 740, DataReader("TSR Name"), pdfFont)
'******** Display the PDF file on the screen
pdfDoc.Save(DataReader("TSR Name") & ".pdf", Response, HttpReadType.Save)
End While
End Using
Catch x As Exception
lblError.Text = x.Message
lblError.Visible = True
End Try
As I said earlier, everything seems to work great, and I can't notice any error with the pdf document or the application itself, but when it executes the statement
pdfDoc.Save(DataReader("TSR Name") & ".pdf", Response, HttpReadType.Save)
It jumps into the catch block and I can read the error by placing a break point on the statement
lblError.Text = x.Message
But, because it throws an error and goes to the catch block, it never executes any code that I place after the pdfdoc.save statement
Thanks
Hopefully this is not too overwhelming
MJ
Mirza Javed
January 16, 2007 04:37 PM UTC
Thanks Dhivya,
I tried your code, and just like it does for me, everything works fine.
But, the error is hidden and is not displayed. Here is what I want you to do to see the error. Put a break point on the statement "Try", so that while executing the application the code stops here. Then walk through the code until you reach the statement "pdfDoc.Save....". Now, if you keep going you will notice that it will ignore/skip the "Label1.text = "Success" statement after that and jump right into catch block
If you keep going further, when the statment "label1.text = x.message" is highlighted, individually hightlight the "x" and put your mouse on top of it, this is where you will see the error description
Try --ADD A BREAK POINT HERE
...
...
...
'******** Display the PDF file on the screen
pdfDoc.Save("TSR Name" & ".pdf", Response, HttpReadType.Save) -- THIS THROWS AN ERROR
Label1.Text = "Success" -- THIS LINE IS SKIPPED
Catch x As exception
Label1.text = x.message -- SHOWS AN ERROR DESCRIPTION
End Try
Thanks
Default.zip