PDFsharp & MigraDoc Foundation

PDFsharp - A .NET library for processing PDF & MigraDoc Foundation - Creating documents on the fly
It is currently Mon Jun 17, 2024 11:03 am

All times are UTC


Forum rules


Please read this before posting on this forum: Forum Rules



Post new topic Reply to topic  [ 9 posts ] 
Author Message
PostPosted: Mon Nov 19, 2012 12:00 pm 
Offline

Joined: Mon Nov 19, 2012 11:54 am
Posts: 16
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.


Top
 Profile  
Reply with quote  
PostPosted: Mon Nov 19, 2012 1:44 pm 
Offline
PDFsharp Guru
User avatar

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

_________________
Regards
Thomas Hoevel
PDFsharp Team


Top
 Profile  
Reply with quote  
PostPosted: Mon Nov 19, 2012 1:45 pm 
Offline

Joined: Mon Nov 19, 2012 11:54 am
Posts: 16
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


Top
 Profile  
Reply with quote  
PostPosted: Mon Nov 19, 2012 1:47 pm 
Offline
PDFsharp Guru
User avatar

Joined: Mon Oct 16, 2006 8:16 am
Posts: 3100
Location: Cologne, Germany
Use the XTextFormatter class (or MigraDoc) for multi-line text.

_________________
Regards
Thomas Hoevel
PDFsharp Team


Top
 Profile  
Reply with quote  
PostPosted: Mon Nov 19, 2012 1:59 pm 
Offline

Joined: Mon Nov 19, 2012 11:54 am
Posts: 16
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.


Top
 Profile  
Reply with quote  
PostPosted: Mon Nov 19, 2012 2:58 pm 
Offline

Joined: Mon Nov 19, 2012 11:54 am
Posts: 16
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


Top
 Profile  
Reply with quote  
PostPosted: Mon Nov 19, 2012 3:48 pm 
Offline
PDFsharp Guru
User avatar

Joined: Mon Oct 16, 2006 8:16 am
Posts: 3100
Location: Cologne, Germany
Try adding linebreaks using vbCrLf to your text - "_" will only break the source code line, not the string.

_________________
Regards
Thomas Hoevel
PDFsharp Team


Top
 Profile  
Reply with quote  
PostPosted: Thu Nov 22, 2012 4:29 pm 
Offline

Joined: Mon Nov 19, 2012 11:54 am
Posts: 16
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)


Top
 Profile  
Reply with quote  
PostPosted: Mon Nov 26, 2012 12:56 pm 
Offline
PDFsharp Guru
User avatar

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

_________________
Regards
Thomas Hoevel
PDFsharp Team


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

All times are UTC


Who is online

Users browsing this forum: No registered users and 140 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