I want to set the minimum height of row. however it seems there is limit
i am using below code [http://forum.pdfsharp.de/viewtopic.php?f=2&t=2812 ]
var spacerRow = t1.AddRow();
spacerRow.Height = "0.1mm";
var para2 = new Paragraph();
para2.Format.LineSpacingRule = LineSpacingRule.Exactly;
para2.Format.LineSpacing = "0.1mm";
para2.Format.SpaceBefore = 0;
para2.Format.SpaceAfter = 0;
spacerRow.Cells[0].Add(para2);
but the height is not reducing any further.
the spacer row is between the borderd rows as show in attached picture.
If you want to do it for all rows:
Table table = new Table();
table.Format.Alignment = ParagraphAlignment.Center;
table.Rows.HeightRule = RowHeightRule.Exactly;
table.Rows.Height = 5;
For a single row:
row = table.AddRow();
row.HeightRule = RowHeightRule.Exactly;
row.Height = 5;
Related
How to remove this large blank space between my chart area and the legends? See that I even tried different docking styles but the gap is still there.
Any ideas?
I import the data from a CSV file, generated by another application. Every column is a new data series but they are all added into the same chart and chartArea element.
// Load data from CSV into a DataTable
DataTable dataTable = ReadCsvFile(System.IO.Path.GetFileName("mqlWeekRace.txt"), false);
Chart chart1 = new Chart();
chart1.Height = 1000;
chart1.Width = 1500;
chart1.ChartAreas.Add("ChartArea1");
chart1.ChartAreas["ChartArea1"].AxisX.MajorGrid.LineWidth = 1;
chart1.ChartAreas["ChartArea1"].AxisX.MajorGrid.LineDashStyle = ChartDashStyle.Dot;
chart1.ChartAreas["ChartArea1"].AxisY.MajorGrid.LineWidth = 1;
chart1.ChartAreas["ChartArea1"].AxisY.MajorGrid.LineDashStyle = ChartDashStyle.Dot;
chart1.ChartAreas["ChartArea1"].AxisX.IsMarginVisible = false;
// chart1.ChartAreas["ChartArea1"].AxisY.IsStartedFromZero = false;
// Line colors
string[] myColors = new string[] { "Blue", "DarkOrange", "Firebrick", "DarkSeaGreen", "DarkViolet", "Sienna",
"DarkOrchid", "IndianRed", "ForestGreen", "Teal", "MidnightBlue", "DimGray" };
int colorIndex = 0;
foreach (DataColumn col in dataTable.Columns)
{
if (!col.ColumnName.StartsWith("Data") && col.ColumnName.Length > 1)
{
chart1.Series.Add(col.ColumnName.ToString());
chart1.Series[col.ColumnName].ChartArea = "ChartArea1";
chart1.Legends.Add(new Legend(col.ColumnName));
chart1.Legends[col.ColumnName].LegendStyle = LegendStyle.Column;
chart1.Legends[col.ColumnName].Docking = Docking.Top;
chart1.Legends[col.ColumnName].Font = new Font(FontFamily.GenericSansSerif, 15);
chart1.Series[col.ColumnName].ChartType = SeriesChartType.Line;
chart1.Series[col.ColumnName].XValueMember = "Data";
chart1.Series[col.ColumnName].YValueMembers = col.ColumnName.ToString();
chart1.Series[col.ColumnName].XValueType = ChartValueType.Date;
chart1.Series[col.ColumnName].BorderWidth = 3;
chart1.Series[col.ColumnName].Color = System.Drawing.Color.FromName(myColors[colorIndex]);
colorIndex++;
}
}
chart1.DataManipulator.IsStartFromFirst = true;
chart1.DataSource = dataTable;
chart1.DataBind();
I have the code for generating an Excel sheet and I want to set the Row height there.
The code is as follows:
Columns lstColumns = sheet1.Worksheet.GetFirstChild<Columns>();
bool needToInsertColumns = false;
if (lstColumns == null)
{
lstColumns = new Columns();
needToInsertColumns = true;
}
lstColumns.Append(
new Column() { Min = 1, Max = 1, Width = 120, CustomWidth = true }
);
if (needToInsertColumns)
{
sheet1.Worksheet.InsertAt(lstColumns, 0);
}
// For rows.
Row row;
row = new Row() { RowIndex = 1 };
row.Height = 100;
sheetData.Append(row);
Through the following code I am able to set the width but not the height.
Do the following:
Row row;
row = new Row() { RowIndex = 1 };
row.Height = 10.0;
row.CustomHeight = true;
or, better:
var row = new Row { Height = 10.0, CustomHeight = true, RowIndex = 1 };
The CustomHeight property is important here.
I try crossout row in table. Line must be over all cells in center vertical.
So I add new shape to cell, like this:
var cell = node as Cell;
var width = cell.CellFormat.Width;
var line = new Shape(args.Document, ShapeType.Line);
line.Width = width;
line.HorizontalAlignment = HorizontalAlignment.Center;
line.RelativeVerticalPosition = RelativeVerticalPosition.Paragraph;
line.Top = 5;
line.BehindText = true;
line.WrapType = WrapType.None;
line.StrokeColor = Color.Black;
line.Stroke.LineStyle = ShapeLineStyle.Single;
line.StrokeWeight = 1;
_builder.MoveTo(cell.LastParagraph);
_builder.InsertNode(line);
But this work only when I have single text line in cell, if is two or more line text, my crossout line is not center:
How fix it?
Maybe is other solution for crossout whole row?
You can build logic on the following code that inserts a full-width Line Shape at the middle of each Cell in Table.
Document doc = new Document("E:\\temp\\in.docx");
DocumentBuilder builder = new DocumentBuilder(doc);
LayoutCollector collector = new LayoutCollector(doc);
LayoutEnumerator enumerator = new LayoutEnumerator(doc);
foreach (Table table in doc.FirstSection.Body.Tables)
{
foreach (Row row in table.Rows)
{
foreach (Cell cell in row.Cells)
{
enumerator.Current = collector.GetEntity(cell.FirstParagraph);
while (enumerator.Type != LayoutEntityType.Cell)
{
enumerator.MoveParent();
}
double top = enumerator.Rectangle.Top + (enumerator.Rectangle.Height / 2);
double left = enumerator.Rectangle.Left;
double width = enumerator.Rectangle.Width;
builder.MoveTo(table.NextSibling);
Shape line = builder.InsertShape(ShapeType.Line, width, 0);
line.Top = top;
line.Left = left;
line.RelativeHorizontalPosition = RelativeHorizontalPosition.Page;
line.RelativeVerticalPosition = RelativeVerticalPosition.Page;
line.BehindText = true;
line.WrapType = WrapType.None;
line.StrokeColor = Color.Blue;
line.Stroke.LineStyle = ShapeLineStyle.Single;
line.StrokeWeight = 1;
}
}
}
doc.Save("E:\\temp\\19.1.docx");
Hope, this help. I work with Aspose as Developer Evangelist.
I have a large form I'm transforming into a PDF. The first 1/6th of it looks like this:
http://i.imgur.com/y4pO8Th.png
The number of entered fields however, varies from 1 to 20 per section, and I need to be able to make this document break pages intelligently. My plan was to originally draw the tables piece by piece and just manage the Y-coordinate by grabbing the number of rows in all previous tables. This worked, but falls apart when I get to a page break, and I start needing some semi-complicated logic to make it work, and it's the kind of logic that gets messier and messier with each additional table added.
My second plan was to reproduce the table structure of the HTML document in the PDF, which I manage to do successfully...
private void DrawPDF()
{
Document tDoc = new Document();
MigraDoc.DocumentObjectModel.Style style = tDoc.Styles["Normal"];
style.Font.Name = tPdfFont;
style.Font.Size = 10;
Section tSec = tDoc.AddSection();
MigraDoc.DocumentObjectModel.Tables.Table masterTable = new MigraDoc.DocumentObjectModel.Tables.Table();
masterTable = tSec.AddTable();
masterTable.Borders.Visible = false;
Column leftColumn = masterTable.AddColumn("365pt");
Column spacer = masterTable.AddColumn("10pt");
Column rightColumn = masterTable.AddColumn("365pt");
Row tFS = masterTable.AddRow();
Cell tCell = tFS.Cells[0];
//
// Farm Assets Column
//
{
MigraDoc.DocumentObjectModel.Tables.Table tAssetsTable = new MigraDoc.DocumentObjectModel.Tables.Table();
tAssetsTable.Borders.Visible = false;
Column tColumn = tAssetsTable.AddColumn("365pt");
tCell.Elements.Add(tAssetsTable);
//
// Current Farm Assets
//
for (int i = 0; i < 10; i++) // Drawn 10 times to force it to draw over the 1st page.
{
Section thisSection = tDoc.AddSection();
Row tAssetsRow = tAssetsTable.AddRow();
Cell tAssetsCell = tAssetsRow.Cells[0];
MigraDoc.DocumentObjectModel.Tables.Table table = new MigraDoc.DocumentObjectModel.Tables.Table();
table = thisSection.AddTable();
table.Borders.Width = 0.2;
table.Rows.LeftIndent = 0;
Column columnData = table.AddColumn("295pt");
columnData.Borders.Left.Visible = false;
Column columnValue = table.AddColumn("70pt");
Row rowA = table.AddRow();
rowA.Shading.Color = Color.FromRgbColor((byte)255, Color.Parse("0xa2a2d2"));
rowA.Cells[0].AddParagraph("CURRENT FARM ASSETS");
rowA.Cells[1].AddParagraph("$ Value");
rowA.Cells[1].Format.Alignment = ParagraphAlignment.Right;
Row row1 = table.AddRow();
row1.Borders.Bottom.Visible = false;
row1.Cells[0].AddParagraph("Cash: Savings: ($" + MP.FormFinancialStatement.CurrentStaticAssets.Savings + ") Checking: ($" + MP.FormFinancialStatement.CurrentStaticAssets.Checking + ")");
row1.Cells[1].AddParagraph(MP.FormFinancialStatement.CurrentStaticAssets.CashTotal);
row1.Cells[1].Format.Alignment = ParagraphAlignment.Right;
Row row2 = table.AddRow();
row2.Borders.Bottom.Visible = false;
row2.Cells[0].AddParagraph("Invest: Time Cret $" + MP.FormFinancialStatement.CurrentStaticAssets.TimeCret + " Other: $" + MP.FormFinancialStatement.CurrentStaticAssets.OtherInvestments + "");
row2.Cells[1].AddParagraph(MP.FormFinancialStatement.CurrentStaticAssets.InvestTotal);
row2.Cells[1].Format.Alignment = ParagraphAlignment.Right;
Row row3 = table.AddRow();
row3.Borders.Bottom.Visible = false;
row3.Cells[0].AddParagraph("Replacement Account");
row3.Cells[1].AddParagraph(MP.FormFinancialStatement.CurrentStaticAssets.ReplacementAccount);
row3.Cells[1].Format.Alignment = ParagraphAlignment.Right;
Row row4 = table.AddRow();
row4.Cells[0].AddParagraph("Accouts and Notes Recievable");
row4.Cells[1].AddParagraph(MP.FormFinancialStatement.CurrentStaticAssets.AccountsNotesReceivable);
row4.Cells[1].Format.Alignment = ParagraphAlignment.Right;
MigraDoc.DocumentObjectModel.Tables.Table clone = (MigraDoc.DocumentObjectModel.Tables.Table)table.Clone();
tAssetsCell.Elements.Add(clone);
}
}
MigraDoc.Rendering.DocumentRenderer docRenderer = new DocumentRenderer(tDoc);
docRenderer.PrepareDocument();
docRenderer.RenderObject(gfx, 30, 85, "740pt", masterTable);
}
But alas, this does not actually break pages correctly. I tried sectioning off each individual table, hoping that'd do page break magic, but it does not.
How can I structure this to allow for good page breaks?
You can use the KeepWith property of the table rows to keep blocks together on one page. Only use this for chunks that will surely fit on one page.
See also:
https://stackoverflow.com/a/6831048/1015447
https://stackoverflow.com/a/1327228/1015447
I can make a header in Migradoc like this:
//Create Header
Paragraph paragraph = section.Headers.Primary.AddParagraph();
paragraph.AddText("Roto");
paragraph.Format.Font.Size = 9;
paragraph.Format.Alignment = ParagraphAlignment.Center;
And I can make make a simple table like this:
// Create the HEADER table for the top of every page
this.table = section.AddTable();
this.table.Style = "Table";
this.table.Borders.Color = TableBorder;
this.table.Borders.Width = 0.25;
this.table.Borders.Left.Width = 0.5;
this.table.Borders.Right.Width = 0.5;
this.table.Rows.LeftIndent = 0;
Column column = this.table.AddColumn("8cm");
column.Format.Alignment = ParagraphAlignment.Center;
column = this.table.AddColumn("8cm");
column.Format.Alignment = ParagraphAlignment.Center;
// Create the header of the table
Row row = table.AddRow();
//row = table.AddRow();
row.HeadingFormat = true;
row.Format.Alignment = ParagraphAlignment.Center;
row.Format.Font.Bold = true;
row.Shading.Color = TableBlue;
row.Cells[0].AddParagraph("Rotary");
row.Cells[0].MergeRight = 1;
row = table.AddRow();
row.HeadingFormat = true;
row.Format.Alignment = ParagraphAlignment.Center;
row.Format.Font.Bold = true;
row.Shading.Color = TableBlue;
row.Cells[0].AddParagraph("Part No.:");
row.Cells[0].Format.Alignment = ParagraphAlignment.Left;
row.Cells[1].AddParagraph("Tested by:");
row.Cells[1].Format.Alignment = ParagraphAlignment.Left;
row = table.AddRow();
row.Cells[0].MergeRight = 1;
How do I get the table into the header so it appears at the top of every page?
EDIT:
So to make it work I changed:
this.table = section.AddTable();
to:
this.table = section.Headers.Primary.AddTable();
If you want to have the same header on every page:
Use section.Headers.Primary.AddTable() instead of section.Headers.Primary.AddParagraph().
By setting row.HeadingFormat = true; for the first n rows of your table, you mark this rows as header rows. When the table grows and breaks over several pages, the header rows will be repeated on every page (but in the "normal" page body, not the header area). This is the typical usage of heading rows. If you don't add other rows to your header table, HeadingFormat = true will not have any effect.