PDFsharp & MigraDoc Foundation

PDFsharp - A .NET library for processing PDF & MigraDoc Foundation - Creating documents on the fly
It is currently Mon Dec 09, 2019 5:15 am

All times are UTC


Forum rules


Please read this before posting on this forum: Forum Rules



Post new topic Reply to topic  [ 4 posts ] 
Author Message
PostPosted: Sun Nov 03, 2019 8:31 pm 
Offline

Joined: Sun Nov 03, 2019 7:51 pm
Posts: 37
Hi,

In my program I have a very long string, that contains text. It can fill up 2 or more pages of a PDF file (I don't know how many pages).

I make a new page in my code like this:

Code:
page = document.AddPage();
gfx = XGraphics.FromPdfPage(page);


Then I write the long string to the page like this ("text" is the string that must be written):

Code:
XTextFormatter tf = new XTextFormatter(gfx);
tf.Alignment = XParagraphAlignment.Justify;
tf.DrawString(text, font, XBrushes.Black, new XRect(0 + 10, 0 + 10, page.Width - 20, page.Height - 20), XStringFormats.TopLeft);


The string is too long for 1 page so it doesn't fit. It's written until the current page is filled (part of the string is not written, because it's too long for the page)

Is there a way PDFsharp can add more pages automatically when a string is too long for 1 page?
Or how do I solve this problem?

Jessica


Top
 Profile  
Reply with quote  
PostPosted: Sun Nov 03, 2019 10:52 pm 
Offline
PDFsharp Expert
User avatar

Joined: Sat Mar 14, 2015 10:15 am
Posts: 508
Location: CCAA
Jessica wrote:
Is there a way PDFsharp can add more pages automatically when a string is too long for 1 page?
Or how do I solve this problem?
MigraDoc can break strings across several pages. Consider using MigraDoc.

If you want to stick to PDFsharp:
There is an improved version of XTextFormatter that returns how much text was written. If the text was truncated, just try to write the remaining text on the next page until no truncation occurs.
See also:
viewtopic.php?f=8&t=3192

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


Top
 Profile  
Reply with quote  
PostPosted: Sun Nov 03, 2019 11:23 pm 
Offline

Joined: Sun Nov 03, 2019 7:51 pm
Posts: 37
Hi

I want to use MigraDoc. Can you give a small code example including the method to use for writing a string across several pages automatically? I'm a beginner and don't know what to use.

Thanks


Top
 Profile  
Reply with quote  
PostPosted: Mon Nov 04, 2019 9:44 am 
Offline
PDFsharp Guru
User avatar

Joined: Mon Oct 16, 2006 8:16 am
Posts: 3012
Location: Cologne, Germany
Hi!
Jessica wrote:
Can you give a small code example including the method to use for writing a string across several pages automatically?
A string passed in a call to "AddParagraph(text)" will break across several lines and pages if needed.
"AddFormattedText" is the advanced version used in this sample:
http://www.pdfsharp.net/wiki/MigraDocHe ... ample.ashx

See also:
http://www.pdfsharp.net/wiki/HelloMigraDoc-sample.ashx

_________________
Regards
Thomas Hoevel
PDFsharp Team


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

All times are UTC


Who is online

Users browsing this forum: Google [Bot] and 21 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:  
cron
Privacy Policy, Data Protection Declaration, Impressum
Powered by phpBB® Forum Software © phpBB Group