Page break in an Xfinium flow document - c#

I'm creating a PdfFlowDocument using Xfinium.PDF for UWP. I need to insert a page break but only if a certain section (containing paragraphs and tables) does not fit on the current page. It's a kind of "keep together" feature.
How could I accomplish my task?
UPDATE: I've minimized the amount of content that I need to keep together to just a single table. Although it is a flow table, I understand I will need to convert it to a fixed-sized table to calculate its height. If I could somehow find out the current position on the page after rendering all flow content, I would be able to calculate how much space left on the page. If there is enough space for the table, I would render it on the page. If not, I would issue a page break and render it on the next page.
Is there a feature to find out the current position on the page after rendering the flow content?

You can force a page break by calling PdfFlowDocument.StartNewPage.
Size information for flow content is not available in the public API, you cannot test in your code if a content object fits the current available space.
We'll support this in the next release.

Create a table with a single row and cell. For the cell use a PdfFlowTableCompositeCell. It has a property Content which is a collection of flow content objects. On the row set EnableRowSplit = false.
var table = new PdfFlowTableContent(1);
//column width in %
table.Columns[0].Width = 100;
var row = table.Rows.Add();
row.EnableRowSplit = false;
var cell = new PdfFlowTableCompositeCell();
//text
cell.Content.Add(new PdfFlowTextContent(new PdfFormattedContent(KswModuleTranslator.PdfFaultReportStationAssuranceText)));
//image
var image = new PdfPngImage(new MemoryStream(signatureData.Signature));
var imgDings = new PdfFlowImageContent(image);
cell.Content.Add(imgDings);
//text
cell.Content.Add(new PdfFlowTextContent(new PdfFormattedContent(signatureInfo.SigneeName)));
row.Cells.Add(cell);
document.AddContent(table);

Related

Get table height of DocumentRenderer FormatedDocument in Migradoc

I'm creating a PDFSharp document with an embedded table created using Migradoc.
This works just fine.
As the table has a variable number of rows, I need to know the actual height after rendering it into the main PDFsharp document. I need this to continue drawing other sections just after the table created using Migradoc.
This is the code that actually prepares and renders the table:
DocumentRenderer docRenderer = new DocumentRenderer(doc);
docRenderer.PrepareDocument();
docRenderer.RenderObject(gfx, XUnit.FromPoint(x), XUnit.FromPoint(y), XUnit.FromPoint(width), populatedTable);
In the docRenderer.PrepareDocument().FormatedDocument I can get the number of pages (in my case will always be one) and the size of the actual page (A4, for example) but not the height of the actual object.
How can I achieve this?
Well, I just found out how to do it.
After you call PrepareDocument(), you can access the RenderInfo array and check its content:
RenderInfo[] info = docRenderer.GetRenderInfoFromPage(1);
double yTableHeight = info[info.Length - 1].LayoutInfo.ContentArea.Height.Point;
In my case I'm rendering directly the table to a PDFsharp document, the whole ContentArea height is for the table. On a normal page, you will have also margins to add to this number.

How do i print all columns and rows from a datagrid?

I have a wpf application. Upon a user request I create a datagrid of certain columns for all the data from a database. I need to print this information. Preferably I would like to print all odd pages first and then all even pages with a header and footer. I have the following code so far but when I print I only get what I see on the screen. I am sure it is pdPrintDialog.PrintVisual statement. I am assuming I need to use pdPrintDialog.PrintDocument. But I don't know to convert the datagrid or datagrid.itemssource to Documents.DocumentPaginator. I can not find how to do this anywhere. Please help!
System.Windows.Controls.PrintDialog pdPrintDialog = new System.Windows.Controls.PrintDialog();
if ((bool)pdPrintDialog.ShowDialog().GetValueOrDefault())
{
Size pntPageSize = new Size(pdPrintDialog.PrintableAreaWidth, pdPrintDialog.PrintableAreaHeight);
dgPWLCGrid.Measure(pntPageSize);
dgPWLCGrid.Arrange(new Rect(5, 5, pntPageSize.Width, pntPageSize.Height));
pdPrintDialog.PrintVisual(dgPWLCGrid, "North Berwick Food Pantry Client Info");
}

add multiple items to a header Microsoft.Office.Interop.Word

I am building up a word document programatically and the final thing for me to do is to add a header which contains an image to the left a title in the middle.
I have tried various different things but nothing is working. I have tried adding a table to the header range (this throws an exception). I have tried adding the image and then the text but this just makes the text appear and not the image. I have tried adding new fields to the header range but this doesn't work neither.
Could someone point me in the correct direction?
//Add header into the document
foreach (Section section in document.Sections)
{
//Get the header range and add the header details.
Range headerRange = section.Headers
[WdHeaderFooterIndex.wdHeaderFooterPrimary].Range;
headerRange.InlineShapes.AddPicture(#"C:\Development\Tools\CommentParser\CommentParser\HeaderLogo.png");
headerRange.Font.ColorIndex = WdColorIndex.wdBlue;
headerRange.Font.Size = 10;
headerRange.Text = "Title";
}
I have found the solution to my problem. It is rather silly if you ask me but if you have headerRange.Text before the image then it will display them both and the text will be to the right of the image. If I have headerRange.Text second as it is in my sample text then it will just display the text.
Although I have solved it, if someone could please explain why this happens then it would be much appreciated.

ASP.NET Dynamic Image ToolTip Not Displaying Within Table

I have a ASP.NET / C# page where there are multiple tables with an image being loaded into the header. These tables are added dynamically to the page (via the c# code-behind). The images are supposed to be Tool-Tipped with some text, but the tips are not showing up when floating the mouse over the image.
The table is built using this basic concept:
//TABLE CREATION CODE
Table t = new Table();
TableRow tabrHeaderRow = new TableRow();
TableCell tabcHeaderCell = new TableCell();
//IMAGE CODE
System.Web.UI.WebControls.Image im = new System.Web.UI.WebControls.Image();
im.ImageUrl = #"~/img/HEL-icon.png";
im.ImageAlign = ImageAlign.Right;
//im.**add tooltip**
//Add Image to header of table
tabcHeaderCell.Controls.Add(im);
TableCell tabcHeaderCell2 = new TableCell();
tabrHeaderRow.Cells.Add(tabcHeaderCell);
tabrHeaderRow.Cells.Add(tabcHeaderCell2);
t.Rows.Add(tabrHeaderRow);
Attempts for adding tooltip:
im.ToolTip = "TipThisPlz";
im.Attributes.Add("alt", "TipThisPlz");
im.AlternateText = "TipThisPlz";
I have tried various approaches and none seem to get the tooltip to display. Every time, the image will appear, and when I "ViewSource" on the page, it loads correctly and shows either the "alt" or "title" property as being set, but the ToolTip will never display when floating the mouse over the image.
I did some brief experimentation with the "z-index" property, but it didn't seem to help me at all.
Any suggestions on what could be causing the ToolTip not to display when being dynamically added?
NOTE: Adding an < ASP:Image> to the markup with an AlternateText works perfectly fine on the page.
BROWSER OF INTEREST: IE9
It turns out that there was a some CSS effecting the layering of the controls. Therefore, the image was not able to have the mouse float over it since it was in the back and the table was in the front.
The "Z-Index" was the property that was preventing the tooltip from displaying.

iTextSharp read pdf template from hard drive and write text

I have a basic PDF file that I has 5 different blank content areas that I want to use iTextSharp to write text too. The problem is I'm not sure the best way to accomplish this. I have attempted to use ColumnText to accomplish this, but I cannot seem to add multiple ColumnText objects.
ColumnText tagColumn = new ColumnText(pdfContentByte);
tagColumn.SetSimpleColumn(460, 100, 620, 160);
string[] tagColors = bt.DealerTagColor.Split('|');
Font tagFont = FontFactory.GetFont(bt.DealerTagFont, bt.DealerTagSize, Font.NORMAL, new BaseColor(int.Parse(tagColors[0]), int.Parse(tagColors[1]), int.Parse(tagColors[2])));
Paragraph p = new Paragraph(dto.Tag, tagFont);
p.Leading = bt.DealerTagSize;
tagColumn.AddElement(p);
tagColumn.Go();
What I like about the ColumnText is it allows me to essential define a heigth/width, and position of the text area.
Any thoughts on how I can accomplish this with or without using ColumnText? I just need to have control of the font/fontsize/font color/leading/and width of the area which will allow the text to wrap.
The easiest way would be to create and use form fields on your template PDF. This way you can reference a form field by name and set its value with a simple function call.
This article helped me:
Fill in PDF Form Fields using the Open Source iTextSharp Dynamic Link Library
EDIT: PdfPTables?
If your ColumnTexts are tabularly arranged consider using a PdfPTable. I've used PdfPTables to fill rows of data in forms generated from a blank template form. You need to figure out the x-coordinate of each of your columns and use these values when adding PdfPCells to your table, but it does work. I've never had to set an upper limit to the height of a PdfPCell but I image you can do it.
Check this page for more on PdfPTables.

Categories