PDFsharp & MigraDoc Foundation
https://forum.pdfsharp.net/

Drawstring wrapping (new user)
https://forum.pdfsharp.net/viewtopic.php?f=2&t=1889
Page 1 of 1

Author:  gwatchma [ Sun Jan 22, 2012 2:19 pm ]
Post subject:  Drawstring wrapping (new user)

This past week I wrote an application that uses pdfsharp after looking at many other pdf creators out there. I like it a lot.

The only thing that I haven't been able to figure out is wrapping long text lines inside a drawstring rectangle. I use the textformatter and still it runs off my page. I've included some of the code below. When I break on the line before the drawstring and examine page width, it has a value of 292 which should wrap because the text is several lines long) however, my text goes off the right margin of the page.

Any help most appreciated.

Greg

'create pdf header;
'Dim stream As New MemoryStream()
Dim document As New PdfDocument()
document.Info.Title = "Created with PDFSharp"
Dim page As PdfPage = document.AddPage()

'now loop through elements;
Dim gfx As XGraphics = XGraphics.FromPdfPage(page)
Dim tf As XTextFormatter = New XTextFormatter(gfx)
.
.
.
Dim xrectfortf As New XRect(xstart + (medcol - 1) * xinc + CDbl(reportrow.fontsize) * 2, ystart + (medrow - 1) * yinc, xinc, page.Height.Point)
tf.DrawString(med(medindex), font, XBrushes.Black, xrectfortf, XStringFormats.TopLeft)

Author:  gwatchma [ Sun Jan 22, 2012 4:47 pm ]
Post subject:  Re: Drawstring wrapping (new user)

In working on this problem for a few hours, I now have been able to text wrap (don't really know what change did it), however, now when I try to show my pdf in my browser using the code below.... I get an error that there was an error processing a page and could not be displayed with an error 132 from acrobat. It freezes my browser. Used to show just fine. If instead of writing the bytes to the browser, I instead save the stream to a file... I can then open the pdf file without problem. I looked at the pdf with the pdf-analyzer free utility and it says it's o.k. Any ideas?

Imports System.Data
Imports System.IO
Imports System.Text

Public Class pdfReportPrint
Inherits System.Web.UI.Page
Private mstream As MemoryStream

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Dim pdfclass As New pdf
Dim m_stream As MemoryStream = Nothing
pdfclass.pdfstream(CInt(Session("PatientID")), m_stream)

Dim bytes As Byte() = m_stream.ToArray()
Response.Clear()
Response.ContentType = "application/pdf"
Response.AddHeader("content-length", m_stream.Length.ToString())
Response.BinaryWrite(m_stream.ToArray())
Response.BinaryWrite(bytes)
Response.Flush()
m_stream.Close()
Response.[End]()
End Sub

Author:  gwatchma [ Sun Jan 22, 2012 5:24 pm ]
Post subject:  Re: Drawstring wrapping (new user)

So how do I mark my own topic closed? I feel really silly that I didn't notice the two binarywrite events in a row. Got rid of the extra one and all is well.

I also figured out why I couldn't get the text-wrap to work before... my browser was caching the page and I just kept getting the old one. Once I looked at the pdf file on the hard drive, I realized pdfsharp was working just fine. Although no one answered my questions today, I hope this is an active forum I can come to in the future.

Greg

Author:  Thomas Hoevel [ Mon Jan 23, 2012 10:35 am ]
Post subject:  Re: Drawstring wrapping (new user)

Hi!
gwatchma wrote:
Although no one answered my questions today, I hope this is an active forum I can come to in the future.
This is an active forum, but I don't check it everyday. Give people a day or two to answer (and note that users live on different continents).
You can always edit your posts. If you edit the first post in a thread, you can also change the title of the thread.
You can delete the last post in a thread.

Author:  gwatchma [ Mon Jan 23, 2012 1:14 pm ]
Post subject:  Re: Drawstring wrapping (new user)

Thanks Tom. I feel like a patient who talked to their therapist and figured out their own problem.

Good to know there is a community in case I get stumped in the future.

Greg

Page 1 of 1 All times are UTC
Powered by phpBB® Forum Software © phpBB Group
https://www.phpbb.com/