Add a footer on Migradoc last page - pdfsharp

I need to add a footer on the MigraDoc.
The following code adds footer to all the pages.
The page has a header which needs to appear on each page.
Document document = new Document();
PdfDocumentRenderer pdfRenderer = new PdfDocumentRenderer(false);
Section HeaderSection = document.AddSection();
HeaderSection.PageSetup.DifferentFirstPageHeaderFooter = false;
MigraDoc.DocumentObjectModel.Shapes.Image image = HeaderSection.Headers.Primary.AddImage("../images/logo.jpg");
image.Height = new Unit(65);
image.Width = new Unit(150);
image.LockAspectRatio = false;
image.RelativeVertical = RelativeVertical.Line;
image.RelativeHorizontal = RelativeHorizontal.Margin;
Paragraph ParaHead1 = HeaderSection.AddParagraph();
Parahead1.AddFormattedText("..dfg");
Table table = HeaderSection.Footers.Primary.AddTable();
table.Borders.Width = 0;
Column column = table.AddColumn();
column.Width =Unit.FromPoint(300);
column.Format.Alignment = ParagraphAlignment.Left;
Column column1 = table.AddColumn();
column1.Width = Unit.FromPoint(200);
column1.Format.Alignment = ParagraphAlignment.Left;
Row row = table.AddRow();
Cell cell = row.Cells[0];
cell.AddParagraph("Regards,");
cell = row.Cells[1];
Paragraph para1 = cell.AddParagraph();
para1.AddFormattedText("Support Team");
I need the footer table to appear only on the last page.
I don't want add to add the last paragraph as the table as the footer as that will cause the footer to appear just appear the text.
The content on the page is dynamic.

You cannot use the MigraDoc footers for a footer on the last page only.
To achieve this effect, you have to add the text to the main body - or draw the footer later using PDFsharp.
You can use a TextFrame to have the footer at a fixed location, but you must take care that the TextFrame will not overlap with other main body content.
To answer the question from the comment:
To have the "footer" directly below the content, just add it to the main body in any form you like (table, paragraph, ...)
To have the footer at an absolute position (e.g. using a TextFrame): I recommend adding an empty dummy paragraph to the main body text (if needed) to make sure the footer does not overlap with the main body; the height of the dummy paragraph will be the height of the footer that overlaps with the main body area of the document

The approach I used was to add a flag to PageSetup within a Section.
The flag tells the engine to replace last page header and footer with the ones specified by the LastPageHeader and LastPageFooter keywords.
This is an example of section supporting last page header and footer ( it uses a special Migradoc/xml syntax, but it's supported with the original mddl as well):
<Section>
<Attributes>
<PageSetup PageHeight="29.7cm" PageWidth="21cm" Orientation="Portrait" DifferentLastPageHeaderFooter="true"/>
</Attributes>
<LastPageHeader>
....
</LastPageHeader>
<LastPageFooter>
....
</LastPageFooter>
</Section>
A fork supporting this functionality is available here: https://github.com/emazv72/MigraDoc
Note that LastPageHeader and LastPageFooter only work with PDF, not with RTF.

Related

Vaadin 17 Grid change style of the second header row

Is there a way to change the style (color, font) of the second header row added to Vaadin 17 grid?
Second header row is added with grid.appendHeaderRow();
You can add whatever component you like to the Header Row.
For example:
Div div = new Div();
// add classes or styles to the Div
HeaderRow headerRow = employeeGrid.appendHeaderRow();
headerRow.getCell(idColumn).setComponent();
Checkout the examples here:
https://vaadin.com/components/vaadin-grid/java-examples/header-and-footer

How can I reduce the amount of vertical space between lines of text using CSS?

The "obvious" answer is to use the line-height CSS rule, but this code (where I do use that):
private void GenerateSection7()
{
var headerFirstPart = new Label
{
CssClass = "finaff-webform-field-label",
Text = "<h2><strong>Section 7: Submit Information </strong></h2>"
};
headerFirstPart.Style.Add("display", "inline-block");
headerFirstPart.Style.Add("white-space", "pre");
headerFirstPart.Style.Add("line-height", "20%");
var headerSecondPart = new Label
{
CssClass = "finaff-webform-field-label",
Text = " (This payment is subject to post audit review by Financial Affairs)"
};
headerSecondPart.Style.Add("display", "inline-block");
headerFirstPart.Style.Add("line-height", "20%");
this.Controls.Add(headerFirstPart);
this.Controls.Add(headerSecondPart);
var submissionInstructions = new Label
{
CssClass = "finaff-webform-field-label",
Text = "<h4>Submit completed and approved form to Mail stop: FAST/AP Office</h4>"
};
this.Controls.Add(submissionInstructions);
}
...produces this result:
As you can see, the Cumberland gap could fit between these two lines. I started with 80% and kept reducing the percentage, but it makes no difference - 20% is no better than 50% (which was no better than 80%).
How can I cinch up the "play" between the lines?
UPDATE
Spurred on by oriol and quinnuendo, I changed my code to this:
private void GenerateSection7()
{
var headerFirstPart = new Label
{
CssClass = "finaff-webform-field-label",
Text = "<h2><strong>Section 7: Submit Information </strong></h2>"
};
headerFirstPart.Style.Add("display", "inline-block");
headerFirstPart.Style.Add("white-space", "pre");
//headerFirstPart.Style.Add("line-height", "20%");
headerFirstPart.Style.Add("margin", "0");
var headerSecondPart = new Label
{
CssClass = "finaff-webform-field-label",
Text = " (This payment is subject to post audit review by Financial Affairs)"
};
headerSecondPart.Style.Add("display", "inline-block");
//headerSecondPart.Style.Add("line-height", "20%");
headerFirstPart.Style.Add("margin", "0");
this.Controls.Add(headerFirstPart);
this.Controls.Add(headerSecondPart);
var submissionInstructions = new Label
{
CssClass = "finaff-webform-field-label",
Text = "<h4>Submit completed and approved form to Mail stop: FAST/AP Office</h4>"
};
submissionInstructions.Style.Add("margin", "0");
this.Controls.Add(submissionInstructions);
}
...but it still generates exactly the same page (with the Grand Canyon between the last two lines preventing Evel Kneivel from safely traversing the expanse).
Note: I tried both "0" (as shown above) and "0px" as the margin values, and the results are identical either way.
Line height is not the problem here. The problem is the space between the elements, which is controlled by the margin properties.
These tend to be preset to some values that allow for "normal" text flow, so you will have space before and after a heading and around paragraphs for instance.
Headings have various amounts of margin-top and margin-bottom depending on the level of the heading (h2 will have more than an h4). For instance it is "1em" sometimes (the width of a capital M in the current font).
So you will want to reduce these, or set them to 0 directly and experiment from there. The margins need to be set for the actual headings (h4, h2, or whatever) not for the containing element, they will not inherit it. For initial experiments you can try to just apply everything directly in the code, something like <h4 style='margin:0px'> ..... For a proper solution you would want to define actual CSS sheets for the particular case with introducing classes into the heading or in some surrounding div or an analogue.
In some cases you may also need to check out the padding property to fully control the spacings.
The problem is not the line-height but the vertical margins between elements. Also the fact that the headerSecondPart is untag.
See example for the solution.

How to make Report Footer print at bottom of page

I want the Report Footer to print at the bottom of the page rather than at the bottom of the end of the last line item of the report.
Also I'm formatting this for a paper that has a pre-printed grid on it and in order to make everything fit in the grid, I also have a Page Footer that's a couple inches high. However, I need the Report Footer to print in the Page Footer area.
There is no report footer in the Stimulsoft Reports.
There is a Report Summary where you could set the Pring at Bottom property.
You should set PrintOnAllPages = True in the footer band
StiFooterBand footerBand = new StiFooterBand();
footerBand.Height = 0.5f;
footerBand.Name = "FooterBand";
footerBand.Border = new StiBorder(StiBorderSides.All, Color.Black, 1, StiPenStyle.Solid);
footerBand.PrintOnAllPages = true;
page.Components.Add(footerBand);

cObject in Typolink assigned with border-content

Basically, I (think I ) need to know how to assign borderContent to a cObject, when it is a typolink parameter.
To tell the whole story: I'm using perfect lightbox, and I want it to open the lightbox when a text is clicked, and display the images that are in a single content element in the border section.
Looking through the manual, i found this code:
page.20 = TEXT
page.20.value = Open an image in a lightbox
page.20.typolink {
title = This is my caption
parameter.cObject = IMG_RESOURCE
parameter.cObject = fileadmin/image2.jpg
parameter.cObject.file.maxW = 600
parameter.cObject.file.maxH = 600
ATagParams = rel="lightbox[mySet]"
}
which is working fine. But I don't want the path to be hard set, but the content to be loaded from the border section, as I said. But if I try the following:
page.20 = TEXT
page.20.value = Open an image in a lightbox
page.20.typolink {
title = This is my caption
parameter.cObject = IMG_RESOURCE
parameter.cObject < styles.content.getBorder
parameter.cObject.file.maxW = 600
parameter.cObject.file.maxH = 600
ATagParams = rel="lightbox[mySet]"
}
the link is gone.
So I GUESS I'm assigning the content wrong. Somebody knows the answer?
Thanks!
(If of any help, I use automaketemplate..)
Assigning styles.content.getBorder will just assign the full content elements from the border column. This will not get you anywhere.
You will need to manually load the content elements from the border column, of course this can be done with TypoScript. It should be something like this:
page.20 = TEXT
page.20 {
value = Open an image in a lightbox
typolink {
ATagParams = rel="lightbox[mySet]"
title = This will be the title attribute
parameter.cObject = CONTENT
parameter.cObject {
table = tt_content
select {
pidInList = this
where = colPos = 3
}
renderObj = IMG_RESOURCE
renderObj.file {
import = uploads/pics
import.field = image
import.listNum = 0
width = 600
height = 600
}
}
}
}
Basically this will load all content elements on the border position from the current page. Render the first image in the list of images and return you the resource.

calculating Spark TextArea width

I am treating a spark TextArea as text input(by setting heightInLines="1"). The TextArea is part of an mxml component and I want to resize the component when the text is changed.
I haven't been able to use textArea.measureaText(textArea.text) to get line metrics and use it. I get this error "Parameter antiAliasType must be non-null."
Is there any way to get the width of a TextArea which it is going to consume at runtime for a particular string or a particular TextFlow?
A little ugly but works for me:
var uiText:UItextField = new UITextField();
// if you have custom text style on the TextArea then set it the same of this uitextfield
uiText.setTextFormat("bla bla bla");
uiText.text = "This is the text that I want the size for";
var textW:Number = uiText.textWidth;
var textH:Number = uiText.textHeight;
// then we need to consider also the border of the text area and the paddings
// try read the padding values and border sizes using getStyle(...)
myTextArea.width = textW+2*borderW+paddingL+paddingR;
myTextArea.height = textH+2*borderH+paddingT+paddingB;
That should be all

Resources