PDFsharp & MigraDoc Foundation

PDFsharp - A .NET library for processing PDF & MigraDoc Foundation - Creating documents on the fly
It is currently Thu Mar 28, 2024 12:23 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: Fri May 17, 2019 8:29 pm 
Offline

Joined: Fri May 03, 2019 10:10 pm
Posts: 21
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 7521 times ]
verse(2).jpg
verse(2).jpg [ 59.67 KiB | Viewed 7521 times ]
Top
 Profile  
Reply with quote  
PostPosted: Wed May 22, 2019 8:52 am 
Offline
PDFsharp Guru
User avatar

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

_________________
Regards
Thomas Hoevel
PDFsharp Team


Top
 Profile  
Reply with quote  
PostPosted: Thu May 23, 2019 6:36 pm 
Offline

Joined: Fri May 03, 2019 10:10 pm
Posts: 21
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?


Top
 Profile  
Reply with quote  
PostPosted: Thu May 23, 2019 7:19 pm 
Offline
PDFsharp Expert
User avatar

Joined: Sat Mar 14, 2015 10:15 am
Posts: 909
Location: CCAA
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.

_________________
Best regards
Thomas
(Freelance Software Developer with several years of MigraDoc/PDFsharp experience)


Top
 Profile  
Reply with quote  
PostPosted: Fri May 24, 2019 12:59 pm 
Offline

Joined: Fri May 03, 2019 10:10 pm
Posts: 21
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


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 115 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