I have created two tables on pdf file. Now I wants to arrange them in horizontal position. That is table 1 should be at left of page, and table 2 should be at the exact right position of table 1. But when Iam doing, table 1 comes correctly, but table2 is not exact horizontal with table1.table 2 is just placed as left aligned. How can I place this table 2 as horizontally parallel with table1?
var doc1 = new Document(PageSize.A4);
PdfWriter.GetInstance(doc1, new FileStream(path + "/" + pdf_name + "", FileMode.Create));
doc1.Open();
var table1 = new PdfPTable(1); //table1
table1.HorizontalAlignment = Element.ALIGN_LEFT;
table1.SpacingBefore = 50;
table1.DefaultCell.Border = 1;
table1.WidthPercentage = 40;
PdfPCell cell = new PdfPCell(new Phrase(student_name, boldTableFont));
cell.HorizontalAlignment = Element.ALIGN_CENTER;
table1.AddCell(cell);
doc1.Add(table1);
var table2= new PdfPTable(1); //table2
table2.DefaultCell.Border = 1;
table2.HorizontalAlignment = 2;
table2.SpacingBefore = 50;
table2.WidthPercentage = 40;
PdfPCell cell21 = new PdfPCell(new Phrase("success", body));
cell21.HorizontalAlignment = 1; //0=Left, 1=Centre, 2=Right
table2.AddCell(cell21);
doc1.Add(table2);
doc1.Close();
Create a new table with a single row and two columns.
Place first table in the first row first column and second table in the first row second column
Give the alignment of the first column as left , and for the other right
hope this helps..
Related
I need to align on the headers an image to the right. This is my code:
Section section = document.AddSection();
table = section.Headers.Primary.AddTable();
var column = table.AddColumn("5cm");
column.Format.Alignment = ParagraphAlignment.Left;
column = table.AddColumn("8cm");
column.Format.Alignment = ParagraphAlignment.Left;
column = table.AddColumn("4cm");
column.Format.Alignment = ParagraphAlignment.Right;
eRow.Cells[0].AddParagraph("Some text");
eRow.Cells[1].AddParagraph("Some text");
eRow.Cells[2].Format.Alignment = ParagraphAlignment.Right;
image = eRow.Cells[2].Elements.AddImage(imagePath);
image.LockAspectRatio = false;
image.Width = Unit.FromInch(0.16);
image.Height = Unit.FromInch(0.09);
image.RelativeVertical = RelativeVertical.Line;
image.RelativeHorizontal = RelativeHorizontal.Margin;
image.Top = ShapePosition.Top;
image.Left = ShapePosition.Right;
image.WrapFormat.Style = WrapStyle.Through;
But it's always to the left, any help please?
I know it is a bit late
But you have to wrap your image in a paragraph.
http://forum.pdfsharp.net/viewtopic.php?f=2&t=158
Something like (I use parts of your code)
Section section = document.AddSection();
table = section.Headers.Primary.AddTable();
var column = table.AddColumn("5cm");
//I assume eRow is just a row added to your table
var eRow = table.AddRow();
var paragraph = eRow.Cells[0].AddParagraph();
//set the alignment on the paragraph object
paragraph.Format.Alignment = ParagraphAlignment.Right;
paragraph.AddImage(imagePath);
I had the same problem at it worked with the code/link from above.
The lines
image.RelativeVertical = RelativeVertical.Line;
image.RelativeHorizontal = RelativeHorizontal.Margin;
image.Top = ShapePosition.Top;
image.Left = ShapePosition.Right;
image.WrapFormat.Style = WrapStyle.Through;
logically take the image out of the cell. This creates an image that can appear anywhere on the page, not just inside the cell.
Maybe it works if you simply remove those five lines. Maybe it works if you add a Paragraph to the Cell and add the Image to the cell.
If you would have supplied an MCVE I would have tried if my suggestions work. But you only show a code snippet.
The line image.LockAspectRatio = false; is superfluous, but does no harm.
It will work if you do like that:
row.Cells[1].AddParagraph().AddImage(fileName);
row.Cells[1].Format.Alignment = ParagraphAlignment.Right;
In devexpress report, I have two tables. Based on content T2 table height increases, based on T1 height should be set.
I tried to set height in BeforePrint, AfterPrint, SizeChanged, TextChanged events of T2 and also DataSourceChanged event of report, as follows, added image for reference.
T1.HeightF = T2.HeightF;
or
T1.SizeF = new SizeF(T1.WidthF, T2.HeightF);
But above ways didn't work out.
Any idea how to set height of table dynamically?
You can set XRControl.AnchorVertical property of your table to VerticalAnchorStyles.Both value, so your table will be always attached to sides of its container.
xrTable1.AnchorVertical = VerticalAnchorStyles.Both;
Here is example:
var source = new List<Tuple<string>>()
{
new Tuple<string>("Text"),
new Tuple<string>("Some\ntext"),
new Tuple<string>("Some long long\nlong long long\nlong long long text.")
};
var cell = new XRTableCell();
cell.Text = "Just table";
var someCell = new XRTableCell();
someCell.Text = "Some text";
var anotherCell = new XRTableCell();
anotherCell.Text = "Another cell text";
var contentCell = new XRTableCell();
contentCell.DataBindings.Add(new XRBinding("Text", null, "Item1"));
contentCell.Multiline = true;
var anotherContentCell = new XRTableCell();
anotherContentCell.Text = "Content table";
var row = new XRTableRow();
row.Cells.AddRange(new[] { cell, someCell, anotherCell });
var contentRow = new XRTableRow();
contentRow.Cells.AddRange(new[] { contentCell, anotherContentCell });
var table = new XRTable();
table.Rows.Add(row);
table.Borders = DevExpress.XtraPrinting.BorderSide.All;
table.AnchorVertical = VerticalAnchorStyles.Both;
var contentTable = new XRTable();
contentTable.Rows.Add(contentRow);
contentTable.Borders = DevExpress.XtraPrinting.BorderSide.All;
contentTable.LeftF = 350F;
var panel = new XRPanel();
panel.HeightF = contentTable.HeightF = table.HeightF = 15F;
panel.WidthF = 650F;
panel.Controls.AddRange(new[] { table, contentTable });
var detail = new DetailBand();
detail.HeightF = 30F;
detail.Controls.Add(panel);
var report = new XtraReport();
report.Bands.Add(detail);
report.DataSource = source;
report.ShowRibbonPreview();
Here is result of example:
private List<List<String>> tableOverallList;
i have a series of list in this list. it contains 8 values in each list. i need to place it in the table created. i would like to have 2 Rows with 8 columns. for the 1st Row i have this list.
String[] tableTitleList = {" Title", " (Re)set", " Obs", " Mean", " Std.Dev", " Min", " Max", " Unit"};
List<String> tabTitleList = Arrays.asList(tableTitleList);
help me to place the 1st list of values inside the List tableOverallList in the 2nd Row. i will try managing with the rest of the list.
PdfPTable table = new PdfPTable(3); // 3 columns.
PdfPCell cell1 = new PdfPCell(new Paragraph("Cell 1"));
PdfPCell cell2 = new PdfPCell(new Paragraph("Cell 2"));
PdfPCell cell3 = new PdfPCell(new Paragraph("Cell 3"));
PdfPCell cell3 = new PdfPCell(new Paragraph("Cell 4"));
PdfPCell cell3 = new PdfPCell(new Paragraph("Cell 5"));
PdfPCell cell3 = new PdfPCell(new Paragraph("Cell 6"));
PdfPCell cell3 = new PdfPCell(new Paragraph("Cell 7"));
PdfPCell cell3 = new PdfPCell(new Paragraph("Cell 8"));
table.addCell(cell1);
table.addCell(cell2);
table.addCell(cell3);
table.addCell(cell4);
table.addCell(cell5);
table.addCell(cell6);
table.addCell(cell7);
table.addCell(cell8);
document.add(table);
That's really easy. So you have data in a nested list. For instance:
public List<List<String>> getData() {
List<List<String>> data = new ArrayList<List<String>>();
String[] tableTitleList = {" Title", " (Re)set", " Obs", " Mean", " Std.Dev", " Min", " Max", "Unit"};
data.add(Arrays.asList(tableTitleList));
for (int i = 0; i < 10; ) {
List<String> dataLine = new ArrayList<String>();
i++;
for (int j = 0; j < tableTitleList.length; j++) {
dataLine.add(tableTitleList[j] + " " + i);
}
data.add(dataLine);
}
return data;
}
This will return a set of data where the first record is a title row and the following 10 rows contain mock-up data. It is assumed that this is data you have.
Now when you want to render this data in a table, you do this:
PdfPTable table = new PdfPTable(8);
table.setWidthPercentage(100);
List<List<String>> dataset = getData();
for (List<String> record : dataset) {
for (String field : record) {
table.addCell(field);
}
}
document.add(table);
The result will look like this:
You can find the full source code here: ArrayToTable and this is the resulting PDF: array_to_table.pdf
If you only want 2 rows, a title row and a data row, change the following line:
for (int i = 0; i < 10; ) {
Into this:
for (int i = 0; i < 2; ) {
I've provided a more generic solution because it's more elegant to have generic code.
I had tried binding dynamically created drop down list inside grid view and also added the selected index change event for it but it is giving me output when i had change value of first row drop down. i want individual rows selected index change event what can i do?
I had taken grid view in update panel and added dynamically drop down list in grid view and also bind it for each row.now i want to add selected index change event for each rows drop down list . my code is as follows:-
for (int i = 0; i < gv_details.Rows.Count; i++)
{
DropDownList ddl_Hotel = new DropDownList();
ddl_Hotel.ID = "ddl_Hotel_" + i;
//add TextBox to the first column
string loc = gv_details.Rows[i].Cells[3].Text.ToString();
string selecctloc = "select locid from loc_master where location='" + loc + "'";
SqlDataReader dr = cdf.Execute_SelectForDR(selecctloc);
dr.Read();
string loc_id = dr["locid"].ToString();
dr.Close();
string bind_hotelList = "SELECT Hotel_Id,Hotel_Name FROM Mast_Hotel WHERE LocId ='" + loc_id + "'";
cdf.Bind_DropDownList(ddl_Hotel, bind_hotelList, "Hotel_Name", "Hotel_Id");
//ddl_Hotel.Items.Add(new ListItem("Select", "0"));
ddl_Hotel.Items.Insert(0, new ListItem("---Select---", "0"));
ddl_Hotel.SelectedValue = "0";
gv_details.Columns[5].Visible = true;
ddl_Hotel.SelectedIndexChanged += new EventHandler(ddl_Hotel_SelectedIndexChanged);
this.Form.Controls.Add(ddl_Hotel);
UpdatePanel1.ContentTemplateContainer.Controls.Add(ddl_Hotel);
AsyncPostBackTrigger trigger = new AsyncPostBackTrigger();
trigger.ControlID = ddl_Hotel.ID;
trigger.EventName = "SelectedIndexChanged";
UpdatePanel1.Triggers.Add(trigger);
ddl_Hotel.AutoPostBack = true;
gv_details.Rows[i].Cells[5].Controls.Add(ddl_Hotel);
// ddl_Hotel.Attributes.Add("onchange", "retun destination_name()");
}
please suggest me the answer.
I want to add dynamic series in the chart.
I have a data like date,totalamount. i would like to plot those points on chart.
I get the data from sql database and bind.
i want to plot the data from datatable which will update dynamically.
Series newSeries=new Series();
newseries.ChartType=SeriesChartType.Line;
newSeries.BorderWidth = 3;
Chart1.Series.Add(newSeries);
newSeries.XValueMember = "date1";
newSeries.YValueMembers = "total";
Chart1.DataBind();
this is plotting at last series of the tree view.
please help me on this?
foreach(DataRow row in myDataSet.Tables["Query"].Rows)
{
// For each Row add a new series
string seriesName = row["SalesRep"].ToString();
Chart1.Series.Add(seriesName);
Chart1.Series[seriesName].ChartType = SeriesChartType.Line;
Chart1.Series[seriesName].BorderWidth = 2;
for(int colIndex = 1; colIndex < myDataSet.Tables["Query"].Columns.Count; colIndex++)
{
// For each column (column 1 and onward) add the value as a point
string columnName = myDataSet.Tables["Query"].Columns[colIndex].ColumnName;
int YVal = (int) row[columnName];
Chart1.Series[seriesName].Points.AddXY(columnName, YVal);
}
}