I'm using MigraDoc to create PDF file. I'm adding two paragraph in a textframe. One paragraph is a label while the other is a textbox. After adding the paragraphs to textframe I added the textframe to table row cell. Currently the textbox location goes below the label. I want it to be just beside the label or they are just in one line. Anyone knows the solution for this? Please help. Here's my code and image
Code:
static void AddTextBlockAndTextBoxToRow(Row row, int cellIndex, Paragraph label, Paragraph textbox)
{
var textFrame = new TextFrame();
label.Format.Alignment = ParagraphAlignment.Left;
textbox.Format.Alignment = ParagraphAlignment.Left;
textFrame.Add(label);
textFrame.Add(textbox);
row.Cells[cellIndex].Add(textFrame);
}
Image
MigraDoc cannot show two paragraphs side by side. Not in one table cell, not in one TextFrame.
You could create a table with two columns inside your TextFrame to work around this limitation.
Or do it without TextFrame and create two cells in the main table (you can use MergeRight for other rows to merge those two cells in other rows).
Sample table program in pdfsharp....
Table table = document.LastSection.AddTable();
table.Borders.Visible = true;
table.Format.Shading.Color = Colors.LavenderBlush;
table.Shading.Color = Colors.Salmon;
table.TopPadding = 5;
table.BottomPadding = 5;
Column column = table.AddColumn();
column.Format.Alignment = ParagraphAlignment.Left;
column = table.AddColumn();
column.Format.Alignment = ParagraphAlignment.Center;
column = table.AddColumn();
column.Format.Alignment = ParagraphAlignment.Right;
table.Rows.Height = 35;
Row row = table.AddRow();
row.VerticalAlignment = VerticalAlignment.Top;
row.Cells[0].AddParagraph("Text");
row.Cells[1].AddParagraph("Text");
row.Cells[2].AddParagraph("Text");
row = table.AddRow();
row.VerticalAlignment = VerticalAlignment.Center;
row.Cells[0].AddParagraph("Text");
row.Cells[1].AddParagraph("Text");
row.Cells[2].AddParagraph("Text");
row = table.AddRow();
row.VerticalAlignment = VerticalAlignment.Bottom;
row.Cells[0].AddParagraph("Text");
row.Cells[1].AddParagraph("Text");
row.Cells[2].AddParagraph("Text");
Related
I want to put an image inside a tables cell in MigraDoc, but I end up with image stretching the whole row. The part of the simpilfied code looks like so:
table = sec.AddTable();
table.Borders.Width = 0.1; //only for visualization
column = table.AddColumn("6cm");
column = table.AddColumn("7.5cm");
column = table.AddColumn("2.5cm");
row = table.AddRow();
row[0].AddParagraph("title");
row[1].AddImage("C:\\sample.jpg").Width = "3cm";
row = table.AddRow();
row[0].AddParagraph(" - some text");
row = table.AddRow();
row[0].AddParagraph(" - some text");
row = table.AddRow();
row[0].AddParagraph(" - some text");
row = table.AddRow();
row[2].AddParagraph("0.00$");
First image below shows the result and the second one - the desired effect.
When you set .WrapFormat.Style = WrapStyle.Through for the image then the image will be ignored by the layouter and the height of the row will not be adapted to the image.
If the table has borders then you may have to add the image after the table to have it drawn on top of the table.
A simple alternative could be using .MergeDown for the table cell with the image. This is like RowSpan in HTML. In this case the table will grow to fit the image, so you cannot get the effect of the second image (image extends below the table).
This avoids the complications that come with WrapStyle.Through if you have to deal with many different image sizes and should give you clean pagebreaks if the table should not fit a single page.
The Invoice sample does not use images in tables, but it used MergeDown:
http://pdfsharp.net/wiki/Invoice-sample.ashx
Using C# and Visual Studio, I have a DataGridView with 2 columns. For every row, the first column will display text. For every row EXCEPT one specific row, the second column will display text. In one specific cell in the second column, I need to show an image.
For example:
Row[0].Cell[0] = "test" Row [0].Cell[1] = "test"
Row[1].Cell[0] = "test" Row [1].Cell[1] = "test"
Row[2].Cell[0] = "test" Row [2].Cell[1] = need to display an image here
Row[3].Cell[0] = "test" Row [3].Cell[1] = "test"
There is more than one way to do it but here is a simple example that will set one single cell to show an image:
Bitmap bmp = (Bitmap) Bitmap.FromFile(someimagefile);
DataGridViewImageCell iCell = new DataGridViewImageCell();
iCell.Value = bmp;
dataGridView1[1, 2] = iCell;
Of course any other image source will work as well..
Try not to leak the bitmaps if you change them..
I am working with DocX, a library for creating Microsoft .docx files from C#. https://docx.codeplex.com/
I need to merge some tables inside same row. I already figured out how to merge them inside a column.
var doc = DocX.Load(fileName);
Table t3 = doc.AddTable(39, 11);
t3.Alignment = Alignment.center;
t3.Design = TableDesign.TableGrid;
t3.MergeCellsInColumn(0, 0, 9);
doc.InsertTable(t3);
Row row = table.InsertRow();
if use: row.MergeCells(0, 3);
It merge both column and row
So, can use to remove rows empty
row.Cells[0].RemoveParagraphAt(3);
row.Cells[0].RemoveParagraphAt(2);
row.Cells[0].RemoveParagraphAt(1);
and use : table.MergeCellsInColumn(2, 1, 1);
Only merge rows in a column
To merge cells inside a row you need to define the row first. A bitt different than in Colums where you define the colum inside the function.
t2.Rows[0].MergeCells(1, 2);
Set font use Docx.dll:
FontFamily font = new FontFamily("Times New Roman");
Row row = table.InsertRow();
row.Paragraphs[0].Font(font).FontSize(13);
I have to display an image in a GridView cell.
For example, let 'Stock' be a column in a GridView.
In that column, based on the condition, I have to display either an image or text. Is this possible?
Step 1 : Add your image in Resources.resx under properties folder. (ex. Picture1.jpeg)
Step 2 : Add a DataGridViewImageColumn in your DataGridView
Step 3 : Add image this way
for (int row = 0; row <= [YourDataGridViewName].Rows.Count - 1; row++)
{
((DataGridViewImageCell)gvFiles.Rows[row].Cells[1]).Value = Properties.Resources.Picture1
}
that's it
Manoj
I assume you mean DataGridView as GridView is a control in ASP.NET not Winforms.
And to answer your question: yes it is possible.
If you have DataGridViewImageColumn and want to show inside text you have to create textbox cell and replace it with default cell in that column:
var row = new DataGridViewRow();
row.Cells[Stock.Index] = new DataGridViewTextBoxCell();
row.Cells[Stock.Index].Value = "Test";
I started using PDFSharp the day before yesterday and I used the following code to add an Image to a cell:
Section section = this.document.AddSection();
Table table1 = section.Headers.Primary.AddTable();
Column column = table1.AddColumn("8.5cm");
column.Format.Alignment = ParagraphAlignment.Right;
column = table1.AddColumn("8.5cm");
column.Format.Alignment = ParagraphAlignment.Right;
Row row = table1.AddRow();
Image image = row.Cells[0].Elements.AddImage(#"C:\testdump\logo.jpg");
image.LockAspectRatio = true;
image.RelativeVertical = RelativeVertical.Line;
image.RelativeHorizontal = RelativeHorizontal.Margin;
image.Top = ShapePosition.Top;
image.Left = ShapePosition.Left;
image.WrapFormat.Style = WrapStyle.None;
I added another table after this one:
Table table2 = section.AddTable();
The image in the cell overlaps onto table2. Anyone know why this happens?
Seems like adding a "blank" row to the second table solved the issue. Not sure how that solves the overlapping.
AFAIK the line
image.WrapFormat.Style = WrapStyle.None;
creates a free-floating image. The image gets its position from the cell, but has no effect on the layout of the table.
Use WrapStyle.None if you want to overlap the image with text or other elements.