I wanted to find a way to set the document level properties in MigraDoc. For example I want to set all margins (top, left, right, bottom) to 5 or want to set the font for whole PDF document once. I don't want to set them in each section or paragraph. I know I can set them in sections but my document will have three different sections (header, contents and footer) therefore it is very annoying to repeat the same code for setting same properties in each section.
Moreover, I have set top margin to 5 for header section however top margin seems to be more than 5 (looks like at least 10). Thanks for help.
Margins set for the first section are inherited by the following sections. If you need the same margins for all sections, only set them for the first section.
Use a Style to set the font. Many styles are set by default (like in word), but you can add more styles as needed.
All styles are derived from the Normal style. Set the font for Normal only to change the font for the complete document.
To use a different style, specify its stylename at the paragraph.
See also:
http://pdfsharp.net/wiki/HelloMigraDoc-sample.ashx
(and the other samples)
Re Top Margin: some fonts reserve space for an ascender (accents, diacritical marks, ...) that may make the top margin look bigger than it is.
Related
Is there a way to set fixed height of an element? Could be a table, row or section. This element is dynamically generated from database and it can have a variable number of rows. I need to do that, because the section below needs to be in a fixed position for print out. I am using WPF v1.31. I know it is not the latest, but it's an addition to a quite old application.
You can set the height of a Paragraph or a table Row.
I think you cannot set the height of a Table - but that will be the sum of the heights of all rows. Automatic page breaks will make things complicated if a table does not fit a single page.
A Section always starts on a new page.
TextFrame can be used to place text at a fixed position. Depending on the requirements, this could be simple or complicated.
You can prepare a document to let MigraDoc determine sizes and positions. Then you code can decide whether the items with the fixed position will be on the same page or on a new page.
Here is sample code that shows how to show the progress while creating a PDF:
http://forum.pdfsharp.net/viewtopic.php?f=8&t=3172
The same technique can be used to stitch several MigraDoc documents together to create a single PDF. If I understand your requirements correctly, this could be the way to go - without setting the height of any elements.
I use a Header in my Migradoc documents. Right now I just add a Paragraph to the Header but it doesnt really fit my needs as I want to have lets say two texts that have a different Alignment. For example:
Middle-ALigned.Text Right-Aligned-Text
second line second line
Before I used two textframes and added them to the section (not as Header). That worked somehow but cant be the right choice as I want to print the text on every page and thats what headers are for.
So the question is how do I align the two texts differently in one paragraph or how do I get two paragraphs to appear on the same height in the header.
I hope someone can help with that.
Cheers
Keep it Simple: Use a Tab Stop
The best way to do this is the same as you would do in most word processing tools: with a right-aligned tab-stop, placed on the right margin of the page, with the "left" text, being center-aligned. This is pretty straight forward, but I couldn't find the "full" solution anywhere, so here's what you need:
// Grab the current section, and other settings
var section = documentWrapper.CurrentSection;
var footer = section.Footers.Primary;
var reportMeta = documentWrapper.AdminReport.ReportMeta;
// Format, then add the report date to the footer
var footerDate = string.Format("{0:MM/dd/yyyy}", reportMeta.ReportDate);
var footerP = footer.AddParagraph(footerDate);
// Add "Page X of Y" on the next tab stop.
footerP.AddTab();
footerP.AddText("Page ");
footerP.AddPageField();
footerP.AddText(" of ");
footerP.AddNumPagesField();
// The tab stop will need to be on the right edge of the page, just inside the margin
// We need to figure out where that is
var tabStopPosition =
documentWrapper.CurrentPageWidth
- section.PageSetup.LeftMargin
- section.PageSetup.RightMargin;
// Clear all existing tab stops, and add our calculated tab stop, on the right
footerP.Format.TabStops.ClearAll();
footerP.Format.TabStops.AddTabStop(tabStopPosition, TabAlignment.Right);
The hardest part of this, is figuring out what your tab stop position should be. Because I'm boring and really like encapsulation, I dynamically calculate the tab stop position, based on the page width, less the horizontal page margins. However, getting the current page width wasn't as easy as I'd thought it'd be, because I'm using PageFormat to set the page dimensions.
Next Challenge: Getting Your Page Width, Dynamically
I really hate having tightly coupled code (think: fan-in and fan-out), so even though I know at this point in time what my page width is, even to the point of hard-coding it, I still want to hard code it in only a single place, then refer to that one place everywhere else.
I keep a custom "has-a"/wrapper class to keep this stuff encapsulated into; That's documentWrapper in my code here. Additionally, I don't expose any of the PDFSharp/MigraDoc types to the rest of my application, so I'm using ReportMeta as a way to communicate settings.
Now for some code. When I setup the section, I'm using the MigraDoc PageFormat to define the size of my page for the current section:
// The tab stop will need to be on the right edge of the page, just inside the margin
// We need to figure out where that is
var tabStopPosition =
documentWrapper.CurrentPageWidth
- section.PageSetup.LeftMargin
- section.PageSetup.RightMargin;
// Clear all existing tab stops, and add our calculated tab stop, on the right
footerP.Format.TabStops.ClearAll();
footerP.Format.TabStops.AddTabStop(tabStopPosition / 2, TabAlignment.Center);
footerP.Format.TabStops.AddTabStop(tabStopPosition, TabAlignment.Right);
footerP.Format.Alignment = ParagraphAlignment.Center;
What's really important here, is that I'm storing the CurrentPageWidth, this becomes really important when setting up our tab stops. The CurrentPageWidth property, is simply a MigraDoc Unit type. I am able to determine what this is by using MigraDoc's PageSetup.GetPageSize with my chosen PageFormat.
Results
You can add TextFrames to the header - then they will appear on every page.
Or use one paragraph as header. Use TabStops to position the text (as in Word there are left-aligned, center-aligned, and right-aligned TabStops. With TabStops you have to deal with the linebreaks like this:
(TabStop)Middle Text(TabStop)RightText(LineBreak)(TabStop)MT Second Line(TabStop)RT Second Line.
See also:
https://stackoverflow.com/a/29250830/1015447
I am creating a table in MS Word the table looks like as shown below .
I then ZIP the file and open the document.xml and check for the border elements in the table grid . this is how it looks . I am checking the for border element that is the top border element.
All the border are displayed as none . Then i check the TableGrid in the styles.xml file for table borders below is how the TableGrid styles look like in the styles.xml
The problem here is i am not able to find where exactly is the border element getting assigned. The top black line in the table ?
Borders can be defined at table level via TableStyle (here w:tblBorders in TableGrid style) or via tablesProperties (here w:tblBorders in w:tblPr).
If both of them are definied, there is a conflict and borders definied via tablesProperties will win.
Since the w:tblBorders in w:tblPr are set to None, there is no borders.
But I noticed that TopBorder is missing here (you have Left, Right, Bottom InsideH and InsideV),
It's why, for the TopBorder, MS Word is using the TopBorder definied in TableGrid style and it is set to Single.
So, to remove the top border, you have to :
add the TopBorder which is missing in w:tblBorders in w:tblPr (and set it to none like others)
Or set the borders to None in the TableGrid style.
I am having the problem with setting character elipsis triming, both with word wrapping option in GridView component.
I have changed the height of the header to about 40 px, then set: HeaderPanel.TextOptions.
Trimming to: EllipsisCharacter.
I saw then that single line is trimmed with ellipsis added - successfully.
Next step was to add word wrapping to Wrap. Then ellipsis is never added and
I can see only words of the header caption which fits in the width of the column.
How Can I correctly wrap the header with ellipsis being added when the caption doesn't fit?
Thanks
Wrap and elipsis are rivals. You can use either one or the other.
as the title says, I would like to have a black font with a white border
in my TextBox.
How could it be achieved?
Cheers.
It's possible to convert text into geometry objects with advanced formatting like outlines and fills for individual letters - you can find out more about how to do that here.
Having said that, I'm not sure that this is possible inside a TextBox. It may be for read-only text (TextBlock) only.
Edit
This blog post shows some advanced font rendering techniques inside a TextBox. It may be handy for you.
What I always do for that is set the font color to white and set a DropShadow effect on the text.
Next, play around with depth, angle (set to 0 or something) and blur and you should be able to get what you want.
Check out Blacklight controls # http://blacklight.codeplex.com/. In particular look at the sample on http://mightymeaty.members.winisp.net/blacklight.silverlight/ | Visual Controls | TEXT | Stroke Text Block (Alpha).
A full class and example using Geometries:
http://blogs.msdn.com/b/wpfsdk/archive/2006/12/24/using-text-as-a-decorative-graphic.aspx