PDFsharp & MigraDoc Foundation

PDFsharp - A .NET library for processing PDF & MigraDoc Foundation - Creating documents on the fly
It is currently Thu Jul 18, 2024 7:24 pm

All times are UTC


Forum rules


Please read this before posting on this forum: Forum Rules



Post new topic Reply to topic  [ 5 posts ] 
Author Message
PostPosted: Sun Jan 22, 2012 2:19 pm 
Offline

Joined: Sun Jan 22, 2012 2:11 pm
Posts: 4
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)


Top
 Profile  
Reply with quote  
PostPosted: Sun Jan 22, 2012 4:47 pm 
Offline

Joined: Sun Jan 22, 2012 2:11 pm
Posts: 4
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


Top
 Profile  
Reply with quote  
PostPosted: Sun Jan 22, 2012 5:24 pm 
Offline

Joined: Sun Jan 22, 2012 2:11 pm
Posts: 4
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


Top
 Profile  
Reply with quote  
PostPosted: Mon Jan 23, 2012 10:35 am 
Offline
PDFsharp Guru
User avatar

Joined: Mon Oct 16, 2006 8:16 am
Posts: 3101
Location: Cologne, Germany
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.

_________________
Regards
Thomas Hoevel
PDFsharp Team


Top
 Profile  
Reply with quote  
PostPosted: Mon Jan 23, 2012 1:14 pm 
Offline

Joined: Sun Jan 22, 2012 2:11 pm
Posts: 4
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


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 5 posts ] 

All times are UTC


Who is online

Users browsing this forum: No registered users and 48 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Privacy Policy, Data Protection Declaration, Impressum
Powered by phpBB® Forum Software © phpBB Group