PDFsharp & MigraDoc Foundation

PDFsharp - A .NET library for processing PDF & MigraDoc Foundation - Creating documents on the fly
It is currently Mon Jul 15, 2024 10:06 am

All times are UTC


Forum rules


Please read this before posting on this forum: Forum Rules



Post new topic Reply to topic  [ 3 posts ] 
Author Message
 Post subject: MigraDoc Page Border
PostPosted: Wed Apr 25, 2012 11:48 pm 
Offline

Joined: Wed Apr 25, 2012 11:39 pm
Posts: 2
I'm having trouble creating a border around the whole page in a Migra Doc.

I found a posting at

http://stackoverflow.com/questions/8044 ... ge-borders

That says to use a TextFrame...

Quote:
Drawing a simple rectangle around the whole page should work using e.g. a TextFrame that is added to the page header. TextFrame can have an absolute position, can have any size, and can have a border (width and color can be set).


I found though, that TextFrame does not have a Border property.

Another posting here

viewtopic.php?f=2&t=562&p=1311&hilit=+page+border#p1311

says to use a TextFrame, but again, I can't figure out how to proceed from there.

I add a paragraph to the TextFrame, and set a border on that, but the border, only goes around the paragraph...The width of the paragraph is the width of my TextFrame (8 inches), which is good, I can adjust the width and margins of my TextFrame to get the border on the left/right correct, but the paragraph does not extend the whole height of the TextFrame, so I don't know how to get the top/bottom margins to be correct.

Does anyone have a complete code sample? Or any more clues as what to do?

Thanks,
Rich

UPDATE:

Well, after poking around with TextFrame some more, I figure out a solution. I think it's the right one. The problem was that I did not know what a LineFormat was. In this case, setting the LineFormat on the TextFrame, draws a Border. Not sure why this property isn't called Border, like the rest of the objects.

Also, in one of the above postings, it is said to set RelativeHorizontal and RelativeVertical to the Page.

I found that RelativeVertical.Page worked for me.

RelativeHorizontal.Page did not work for me. I would set it, and set frame.Left to a positive number, and the TextFrame border always showed up right up on the left page edge, no matter what I set Left to be.

My workaround was to set RelativeHorizontal.Margin and then set frame.Left to a negative number to move it a bit left of the page margin, so that the border was not right up next to my section elements.

I am not sure if my issue with RelativeHorizontal.Page is a bug or not....

This is for Letter size pages (8.5 in x 11 in), with some narrow margins...

Code:
var frame = section.Headers.Primary.AddTextFrame();
frame.RelativeHorizontal = RelativeHorizontal.Margin;
frame.RelativeVertical = RelativeVertical.Page;
frame.Left = "-.04in";
frame.Top = ".25in";
frame.Width = "7.95in";
frame.Height = "10.1in";
frame.LineFormat.Width = Unit.FromPoint(1);


Top
 Profile  
Reply with quote  
 Post subject: Re: MigraDoc Page Border
PostPosted: Thu Apr 26, 2012 10:04 am 
Offline
PDFsharp Guru
User avatar

Joined: Mon Oct 16, 2006 8:16 am
Posts: 3101
Location: Cologne, Germany
awhig wrote:
I am not sure if my issue with RelativeHorizontal.Page is a bug or not....
Could be a bug.
It works if you use DistanceLeft and DistanceTop instead of Left and Top.

I tried this for a DIN A4 page (a red frame 5 mm from the page boundaries):

TextFrame tf = section.AddTextFrame();
tf.WrapFormat.Style = WrapStyle.Through;
tf.WrapFormat.DistanceLeft = "5mm";
tf.WrapFormat.DistanceTop = "5mm";
tf.RelativeHorizontal = RelativeHorizontal.Page;
tf.RelativeVertical = RelativeVertical.Page;
tf.Width = "200mm"; // A 4 is 210
tf.Height = "287mm"; // A 4 is 297
tf.LineFormat.Width = "1pt";
tf.LineFormat.Color = Colors.Red;

_________________
Regards
Thomas Hoevel
PDFsharp Team


Top
 Profile  
Reply with quote  
 Post subject: Re: MigraDoc Page Border
PostPosted: Fri Apr 27, 2012 12:10 am 
Offline

Joined: Wed Apr 25, 2012 11:39 pm
Posts: 2
I switched to your method, as it is no longer relative to the Margin, and is instead completely relative to the Page, which is more correct.

Thanks for your help,
Rich


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

All times are UTC


Who is online

Users browsing this forum: Bing [Bot] and 39 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