PDFsharp & MigraDoc Foundation http://forum.pdfsharp.de/ |
|
Adding an address to a pdf http://forum.pdfsharp.de/viewtopic.php?f=2&t=2226 |
Page 1 of 1 |
Author: | silentbob [ Mon Nov 19, 2012 12:00 pm ] |
Post subject: | Adding an address to a pdf |
Hello All First time poster and also quite new to VB I have installed pdfsharp and I am amending the pdf generated from the Hello World sample. I am trying to insert an address into the document and so far I have the following Code: gfx.DrawString("First Line" & Environment.NewLine & "secondline", address, XBrushes.Black, _ New XRect(0, 0, page.Width.Point, page.Height.Point), XStringFormats.Center) It doesnt appear that the environment.newline adds a carrige return. Any suggestions? Also any help on placing it in the top right of the pdf wouldnt go amiss. |
Author: | Thomas Hoevel [ Mon Nov 19, 2012 1:44 pm ] |
Post subject: | Re: Adding an address to a pdf |
Hi! Use XStringFormats.TopLeft instead of XStringFormats.Center. Use the XTextFormatter class (or MigraDoc) for multi-line text. See here: http://www.pdfsharp.net/wiki/TextLayout-sample.ashx |
Author: | silentbob [ Mon Nov 19, 2012 1:45 pm ] |
Post subject: | Re: Adding an address to a pdf |
i have amended my code to the below Code: Dim font2 As New XFont("Verdana", 10) Dim brush As XBrush = XBrushes.Black Dim format As New XStringFormat() Dim rect As New XRect(300, 75, 250, 140) gfx.DrawRectangle(XPens.White, rect) format.Alignment = XStringAlignment.Far gfx.DrawString("line 1" & vbCrLf & "line2", font2, brush, rect, format) This doesnt add the extra line as required all it does is add a large space between line 1 and 2 |
Author: | Thomas Hoevel [ Mon Nov 19, 2012 1:47 pm ] |
Post subject: | Re: Adding an address to a pdf |
Use the XTextFormatter class (or MigraDoc) for multi-line text. |
Author: | silentbob [ Mon Nov 19, 2012 1:59 pm ] |
Post subject: | Re: Adding an address to a pdf |
thanks for that, I have the following code (in VB) Code: Dim Sembaddress As String = "Line1" + _ "Line2" + _ "Line 3" + _ "Line4" + _ "line5" + _ "line6" + _ "line7" + _ "line8" Dim gfx2 As XGraphics = XGraphics.FromPdfPage(page) Dim font2 As New XFont("Times New Roman", 10, XFontStyle.Bold) Dim tf As New XTextFormatter(gfx2) Rect = New XRect(310, 100, 250, 220) gfx.DrawRectangle(XBrushes.SeaShell, Rect) tf.Alignment = XParagraphAlignment.Right tf.DrawString (Text, font2, XBrushes.Black, Rect, XStringFormats.TopLeft) but it doesnt like Rect and text it wants me to generate stubs for them. As I say I am new to this so apologies if these are noob questions. |
Author: | silentbob [ Mon Nov 19, 2012 2:58 pm ] |
Post subject: | Re: Adding an address to a pdf |
doh, text should be sembaddress and I have now delcared the rect, it still doesnt work how I would like as it just joins all the text above into one line split over 2 lines |
Author: | Thomas Hoevel [ Mon Nov 19, 2012 3:48 pm ] |
Post subject: | Re: Adding an address to a pdf |
Try adding linebreaks using vbCrLf to your text - "_" will only break the source code line, not the string. |
Author: | silentbob [ Thu Nov 22, 2012 4:29 pm ] |
Post subject: | Re: Adding an address to a pdf |
I worked it out, well lets just say it works. There maybe a better way of doing it Code: gfx.DrawString("Line1", address, XBrushes.Black, New XRect(400, 100, 0, 0), XStringFormats.TopLeft)
gfx.DrawString("Line2", address, XBrushes.Black, New XRect(400, 115, 0, 0), XStringFormats.TopLeft) gfx.DrawString("Line3", address, XBrushes.Black, New XRect(400, 130, 0, 0), XStringFormats.TopLeft) gfx.DrawString("Line4", address, XBrushes.Black, New XRect(400, 145, 0, 0), XStringFormats.TopLeft) gfx.DrawString("Line5", address, XBrushes.Black, New XRect(400, 160, 0, 0), XStringFormats.TopLeft) gfx.DrawString("line6", address, XBrushes.Black, New XRect(400, 175, 0, 0), XStringFormats.TopLeft) gfx.DrawString("line7", address, XBrushes.Black, New XRect(400, 190, 0, 0), XStringFormats.TopLeft) gfx.DrawString("line8", address, XBrushes.Black, New XRect(400, 205, 0, 0), XStringFormats.TopLeft) |
Author: | Thomas Hoevel [ Mon Nov 26, 2012 12:56 pm ] |
Post subject: | Re: Adding an address to a pdf |
silentbob wrote: There maybe a better way of doing it Yes, using MigraDoc or the TextFormatter class.See also: http://www.pdfsharp.net/wiki/TextLayout-sample.ashx |
Page 1 of 1 | All times are UTC |
Powered by phpBB® Forum Software © phpBB Group https://www.phpbb.com/ |