I need to put an image in the center of a table's cell.
When I add the image in a cell the image is aligned topleft.
How can I align the image in the center of a cell?
You might need to add a paragraph to the cell, set the alignment on the paragraph, and then add the image to the paragraph.
row.Cells[0].Format.Alignment = ParagraphAlignment.Center;
row.Cells[0].VerticalAlignment = VerticalAlignment.Center;
row.Cells[0].AddParagraph().AddImage(imageLocation);
row.Cells[0].Format.Alignment = ParagraphAlignment.Center;
row.Cells[0].VerticalAlignment = VerticalAlignment.Center;
In my version of MigraDoc, Jeff and Reuben's solution does not work as shown: Setting the cell's Format.Alignment property has no effect, even when the image is inside a paragraph.
However, what does work for me is to put the image in a paragraph, just as Jeff and Reuben say, then give the paragraph a named style which includes centering.
In my method which predefines all my styles, I do something like:
// Here we assume the "TableText" style has already been created
var sty = doc.Styles.AddStyle( "TableTextCenter", "TableText" );
sty.ParagraphFormat.Alignment = ParagraphAlignment.Center;
And at the point where I add the image, I do this:
var para = table.Cells[ 0 ].AddParagraph();
para.Style = "TableTextCenter"; // <----- This is the magic!
var img = para.AddImage( imageFileSpec );
img.LockAspectRatio = true;
img.Width = "4cm";
img.WrapFormat = new WrapFormat {
Style = WrapStyle.Through
};
As #Reuben says, what is interesting is:
row.Cells[0].AddParagraph().AddImage(imageLocation);
I was trying with
row.Cells[0].AddImage(imageLocation);
And the image was inserted in the document but I couln't get it centered.
Related
Can't figure out how I change the text colour of tooltips. For my column chart I tried:
series.tooltip.label.fill = am4core.color("#FFFFFF");
But it doesnt work. Curious also how I do it for the pie charts? Is there one place that I can update to affect all chart types, or do each need to be handled independently?
The tooltip label gets a calculated color that contrasts with the tooltip background. You need to set autoTextColor to false in order to the fill color to take effect.
series.tooltip.autoTextColor = false;
series.tooltip.label.fill = am4core.color("#FFFFFF");
The same is valid for pie charts.
You can create your own theme but that could be more than what you need.
You can use more than one theme, which allows you to use one default theme and then override just what you need:
am4core.useTheme(am4themes_animated);
am4core.useTheme(function customTheme (object) {
// Identify the instances
if (object instanceof am4core.Tooltip && object.label) {
object.autoTextColor = false;
object.label.fill = am4core.color("#FFFFFF");
}
});
After a lengthy search, I got the Below Line of code as successful line
pieSeries.labels.template.fill = am4core.color("white");
I have added above line of code if you are using axis range you can use that however as I can see your problem please take a look below line of code will solve your problem
series.tooltip.getFillFromObject = false;
series.tooltip.label.propertyFields.fill = "color";
series.tooltip.background.propertyFields.stroke = "color";
https://www.amcharts.com/docs/v4/concepts/tooltips/
HSSFPatriarch drawing = sheet.createDrawingPatriarch();
HSSFClientAnchor my_anchor = (HSSFClientAnchor) helper.createClientAnchor();
my_anchor.setAnchorType(HSSFClientAnchor.DONT_MOVE_AND_RESIZE);
my_anchor.setCol1(0);
// my_anchor.
my_anchor.setRow1(excelData.getRowNum());
strb.append(" ");
HSSFPicture my_picture = drawing.createPicture(my_anchor, my_picture_id);
/* Call resize method, which resizes the image */
my_picture.resize();
I am passing sheet, helper as parameter to my method.
With this code, still Image Icon can be moved in the excel sheet.
Also I want to set the vertical alignment for the icon in the cell as bottom aligned. Please suggest.
You can align the image using anchor, adjust the values of Dx1, Dy1, Dx2 and Dy2 accordingly. Below is the example:-
ClientAnchor anchor = sheet.getWorkbook().getCreationHelper().createClientAnchor();
anchor.setDx1(0);
anchor.setDy1(0);
anchor.setDx2(0);
anchor.setDy2(0);
Refer to the below URL for complete example:-
https://svn.apache.org/repos/asf/poi/trunk/src/examples/src/org/apache/poi/ss/examples/AddDimensionedImage.java
You can align the image using anchor, adjust the values of Dx1, Dy1, Dx2 and Dy2, pict.resize() accordingly. Below is the example:
ClientAnchor anchor = sheet.getWorkbook().getCreationHelper().createClientAnchor();
Modify below values s per your original image size
anchor.setDx1(0);
anchor.setDy1(0);
anchor.setDx2(90);
anchor.setDy2(90);
// Creates a picture
Picture pict = drawing.createPicture(anchor, pictureIdx);
// Reset the image to the original size
Modify below value s per your original image size
pict.resize(1.75);
Please refer updated below URL for complete example: https://svn.apache.org/repos/asf/poi/trunk/poi-examples/src/main/java/org/apache/poi/examples/ss/AddDimensionedImage.java
Before, there is image:
I am totally new in Titanim(Appcelerator). There is task: I must draw or import and select the definite regions of circle. When clicked, it must change colour. Your help will be appreciated.
With regards
Plz Keep two images one with new background and one with original background.Just change the image path and you would be good to go.Something like this
Ti.UI.backgroundColor = 'white';
var win = Ti.UI.createWindow();
var image = Ti.UI.createImageView({
image:'/images/myimage.png'
});
image.addEventListener('click',function(e){
image.image="images/newimage";
});
win.add(image);
win.open();
I am using iTextSharp to export reports in PDF format. Reports' headers should have following format:
The problem is to align report header by center of the page, while there is an image on the left of the page. When I use a table, report header is aligned by center of its cell, not by center of the page. Is there a better approach?
EDIT:
Code for adding header is following:
var doc = new Document(pageSize, margins.Width, margins.Width, margins.Height, margins.Height);
using (PdfWriter.GetInstance(doc, destination))
{
doc.Open();
var headerTable = new PdfPTable(1){ WidthPercentage = 100 };
RenderHeader(headerTable); // adds several lines to headerTable
doc.Add(headerTable);
}
Do you really need a PdfPTable?
Why not add a Paragraph with the data that is right-aligned, followed by a couple of Paragraphs that are centered.
Then add the image at an absolute position, for instance:
Image img = Image.GetInstance(path_to_image);
img.SetAbsolutePosition(36, PdfWriter.getVerticalPosition(true));
document.Add(Image);
Another option is to add the Image in a table or a cell event instead of adding it straight to the table. Suppose that your PdfPTable consists of a single row and a single column, then you could define a cell event like this:
public class ImageCell : IPdfPCellEvent {
public void CellLayout(
PdfPCell cell, Rectangle position, PdfContentByte[] canvases
) {
float x1 = position.Left + 2;
float y1 = position.Top - 2;
float y2 = position.Bottom + 2;
PdfContentByte canvas = canvases[PdfPTable.LINECANVAS];
Image img = Image.GetInstance(path_to_image);
img.scaleToFit(10000, y1 - y2);
img.SetAbsolutePosition(x1, y2);
canvas.AddImage(img);
}
}
Suppose that cell is the PdfPCell with the date and the title, then you can do this:
cell.CellEvent = new ImageCell();
Note that in this case, the image will be scaled to the height of the cell.
Forgive me if the code doesn't compile right away, I'm writing this by heart (based on experience), I didn't test the actual code.
I am using canvas to add image programatically.
for example:
Image image1=new image1();
Image image2=new image1();
var left = new BitmapImage();
left.UriSource = new Uri("images/box.png", UriKind.Relative);
image1.Source = left;
image2.Source = left;
ContentPanelCanvas.Children.Add(image1);
ContentPanelCanvas.Children.Add(image2);
First time enter the loop Add Image to canvas. second time i want to clear canvas.
and again add different images same canvas.
Is this possible wp7.
tell some idea to do this.
thanks
Yes, it is possible:
ContentPanelCanvas.Children.Clear();
This will empty the canvas.
Why not simply change the Source property of the images you already added?