PDFsharp & MigraDoc Foundation
http://forum.pdfsharp.com/

Horizontal AND Vertical aligning with word wrapping
http://forum.pdfsharp.com/viewtopic.php?f=2&t=2849
Page 1 of 1

Author:  n0652640 [ Mon Jun 30, 2014 3:17 pm ]
Post subject:  Horizontal AND Vertical aligning with word wrapping

Hi,

I am working on a project that generates a PDF dynamically from a template. The template format we have allows text alignment to be in one of 9 positions within a bounding rectangle (Top Left, Center Center, Bottom Right etc). It also expects text to wrap if it exceeds the width of the bounding rectangle.

Using XGraphics.DrawString and passing in an XStringFormat, I can set the text alignment to be one of the 9 values by setting different combinations of XStringAlignment and XLineAlignment. However, when calling XGraphics.DrawString, word wrapping does not seem to be supported.

I have read (http://pdfsharp.net/wiki/TextLayout-sample.ashx) that to allow word wrapping I should use XTextFormatter.DrawString. However, this thows an exception when using an XStringFormat with XStringAlignment and XLineAlignment anything other than Near. I can set the horizontal positioning of the text using XTestFormatter.Alignment, but I can't seem to find a way to set a vertical position.

I'm aware that the documentation recommends using Migradoc for this sort of thing, but I need to absolutely position the bounding rectangle (the software that generates the templates I am rendering allows things to be placed anywhere on the page), and from my experience of using Migradoc items are only placed by inserting them after the last inserted item. Please correct me if I am wrong.

Please let me know if I am missing something, or alternately suggest a workaround if possible. We're using Pdfsharp/Migradoc for various other things and would like to keep using the library for this new requirement if possible.

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