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

Suitability for my project
https://forum.pdfsharp.net/viewtopic.php?f=2&t=3965
Page 1 of 1

Author:  Rocky48 [ Fri May 17, 2019 8:29 pm ]
Post subject:  Suitability for my project

I am designing a program that users can print a card verse for various sizes of greetings cards.
This involves choosing the verse from a list on a database selecting the correct parameters (Card size, Font, font size etc).
I have had this running on a website for some years, but now I want to design a stand-alone version.
Below is attached an example of what I want to acheive (verse (2).jpg).
Also I have attached a diagram of the information I store in a database to position the text (C-Size-Diag.jpg)

I have experimented with the 'Hello World' VB code and changed it to what I thought would position the text, but it does not work as I anticipated.
In the following line I thought that the text would fit within the rectangle, but it doesn't?
Code:
gfx.DrawString(text, font, XBrushes.Black, New XRect(170 * 2.5, 60 * 2.5, cellw, cellh), XStringFormats.Center)

It spreads across the page (if the text is long enough)?
Am I understanding the code wrongly?
If so, how do I get the text to print within the box?
Also, can you force the text to CR/LF where you wish it to?

If the PDFsharp can't do what I wish then I will abandon trying to use this code.

Attachments:
C-Size-diag.jpg
C-Size-diag.jpg [ 170.24 KiB | Viewed 2331 times ]
verse(2).jpg
verse(2).jpg [ 59.67 KiB | Viewed 2331 times ]

Author:  Thomas Hoevel [ Wed May 22, 2019 8:52 am ]
Post subject:  Re: Suitability for my project

Hi!
Rocky48 wrote:
If so, how do I get the text to print within the box?
Also, can you force the text to CR/LF where you wish it to?
Use classes like XTextFormatter or XTextFormatterEx2.
XGraphics.DrawString neither truncates nor wraps long text.

See also:
http://www.pdfsharp.net/wiki/TextLayout-sample.ashx
viewtopic.php?f=8&t=3192

Author:  Rocky48 [ Thu May 23, 2019 6:36 pm ]
Post subject:  Re: Suitability for my project

Thanks for that!
That will work, but how can I force a line change witout relying on text wrap?
Also, where can I get XTextFormatterEx2?

Author:  TH-Soft [ Thu May 23, 2019 7:19 pm ]
Post subject:  Re: Suitability for my project

Rocky48 wrote:
That will work, but how can I force a line change witout relying on text wrap?
In C# you just insert "\n" into the text. In VB that'll be something like VB_LF or so.

Rocky48 wrote:
Also, where can I get XTextFormatterEx2?
The linked forum page has a link to the ZIP with the source code.
You can create a C# project with the XTextFormatterEx2 class and reference this from you VB.NET project.

Author:  Rocky48 [ Fri May 24, 2019 12:59 pm ]
Post subject:  Re: Suitability for my project

Thanks again!
As I am inexperienced VB coder, could you advise how I write the code.
All the verses are in a database, so would I enclose each line in quotes and then enter the VBcrlf constant at the end of the line and save this in the database?
E.g. "Happy Birthday" VBcrlf
"To you" VBcrlf etc
Tony Hudson

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