I am trying to put some image in header of Word document through Microsoft. Office.Interop.Word.
I want to place the picture stretched to both boundaries of document but I am unable to do so; whenever I set right and left indent it only changes the left indent like image is only stretched on the left side but not on the right side, Any type of help will be very precious to me. This is the snippet I am trying with:
foreach (Microsoft.Office.Interop.Word.Section wordSection in docWord.Sections)
{
wordSection.PageSetup.HeaderDistance = 0;
Microsoft.Office.Interop.Word.Range footerRange = wordSection.Footers[Microsoft.Office.Interop.Word.WdHeaderFooterIndex.wdHeaderFooterPrimary].Range;
//footerRange.Font.ColorIndex = Microsoft.Office.Interop.Word.WdColorIndex.wdDarkRed;
//footerRange.ParagraphFormat.LeftIndent = -(docWord.Application.CentimetersToPoints(3));
footerRange.InlineShapes.AddPicture(#"C:\\test\\footer.png");
Microsoft.Office.Interop.Word.Range headerRange = wordSection.Headers[Microsoft.Office.Interop.Word.WdHeaderFooterIndex.wdHeaderFooterPrimary].Range;
//headerRange.Font.ColorIndex = Microsoft.Office.Interop.Word.WdColorIndex.wdDarkRed;
MessageBox.Show((headerRange.ParagraphFormat.RightIndent - (docWord.Application.CentimetersToPoints(72))).ToString());
//headerRange.ParagraphFormat.RightIndent = (docWord.Application.InchesToPoints(-1));
//headerRange.ParagraphFormat.LeftIndent = -(docWord.Application.CentimetersToPoints(3));
headerRange.ParagraphFormat.FirstLineIndent = -(docWord.Application.CentimetersToPoints(3));
//MessageBox.Show(headerRange.ParagraphFormat.RightIndent.ToString());
//headerRange.ParagraphFormat.SpaceBefore =0 ;
headerRange.InlineShapes.AddPicture(#"C:\\test\\header.png");
}
I have worked with Microsoft.interope Library. You are doing it correctly. Unfortunately, Microsoft.interope does not provide support for stretch header.
Related
I'm trying to take a screenshot of a web element that is larger than the screen. I'm using Noksa to do this but part of the content is being overlapped upon when the bottom portion of the screen is being merged with the top. Everything else looks fine except for the 3 or 4 lines that are being cutoff from the bottom part of the page before scrolling. Has anyone else experienced this before?
ScreenshotMaker scrnShot = new ScreenshotMaker();
var by = By.XPath("//*[#id='gw-center-bottom-section']");
var onlyEleDecorator = new OnlyElementDecorator(scrnShot);
onlyEleDecorator.SetElement(by);
ImageBytes = driver.TakeScreenshot(new VerticalCombineDecorator (onlyEleDecorator));
File.WriteAllBytes(filePath + "myFile.bmp", ImageBytes);
I'm trying to create a docx document that has header and footer for all pages.
For the header i want the image to ocuppy all of the header. Like the image below:
For the footer i want it to be on the left and at the right i want to have the number of the page. Like the image below:
what i have right now is:
using (var docx = DocX.Create(filename))
{
docx.AddHeaders();
docx.AddFooters();
var headerDefault = docx.Headers.odd;
var footerDefault = docx.Footers.odd;
Novacode.Paragraph hp = headerDefault.InsertParagraph();
Novacode.Paragraph fp = footerDefault.InsertParagraph();
Novacode.Image logoHeader = docx.AddImage(System.Web.HttpContext.Current.Server.MapPath("/Images/jpg/header_pdf.jpg"));
Novacode.Image logoFooter = docx.AddImage(System.Web.HttpContext.Current.Server.MapPath("/Images/jpg/footer_pdf.jpg"));
hp.AppendPicture(logoHeader.CreatePicture());
fp.AppendPicture(logoFooter.CreatePicture());
The problem is that both the header and the footer get the margins of the rest of the document and even if i do
docx.MarginTop = 0F;
docx.MarginRight = 0F;
docx.MarginBottom = 0F;
docx.MarginLeft = 0F;
there will still be a top margin on the header and a bottom margin on the footer.
Does anyone have a solution? thanks
Late answer, but maybe it would be useful for someone - I faced the same problem. The problem is here:
Novacode.Paragraph hp = headerDefault.InsertParagraph();
Novacode.Paragraph fp = footerDefault.InsertParagraph();
Header and footer already have paragraph, you should just get it:
Novacode.Paragraph hp = headerDefault.Paragraphs.First();
So the margins appeared because there were two paragraphs, one of them was empty but had new line symbol.
This is an issue I have been trying to tackle for a while and decided to reach out for help. I am creating an ESRI ArcGIS Desktop Add-In that allows the user to draw a polygon and then have it added to the map. I am able to capture the polygon and add it to the map, the issue is the transparency. Currently and by default it is 100% opacity and solid. I want to make it around 50% opacity so the user can see the data behind it.
Here is the code I have so far:
public static void AddPolygonToMap(IActiveView ActiveViewInstance, IGeometry NewGeo)
{
//Local Variable Declaration
var fillShapeElement = default(IFillShapeElement);
var element = default(IElement);
var graphicsContainer = default(IGraphicsContainer);
var simpleFilleSymbol = default(ISimpleFillSymbol);
var newRgbColor = default(IRgbColor);
var lineSymbol = default(ILineSymbol);
//Use the IElement interface to set the Envelope Element's geo
element = new PolygonElement();
element.Geometry = NewGeo;
//QI for the IFillShapeElement interface so that the symbol property can be set
fillShapeElement = element as IFillShapeElement;
//Create a new fill symbol
simpleFilleSymbol = new SimpleFillSymbol();
//Create a new color marker symbol of the color black;
newRgbColor = new RgbColor();
newRgbColor.Red = 0;
newRgbColor.Green = 0;
newRgbColor.Blue = 0;
//Create a new line symbol so that we can set the width outline
lineSymbol = new SimpleLineSymbol();
lineSymbol.Color = newRgbColor;
lineSymbol.Width = 2;
//Setup the Simple Fill Symbol
simpleFilleSymbol.Color = newRgbColor;
simpleFilleSymbol.Style = esriSimpleFillStyle.esriSFSHollow;
simpleFilleSymbol.Outline = lineSymbol;
fillShapeElement.Symbol = simpleFilleSymbol;
//QI for the graphics container from the active view allows access to basic graphics layer
graphicsContainer = ActiveViewInstance as IGraphicsContainer;
//Add the new element at Z order 0
graphicsContainer.AddElement((IElement)fillShapeElement, 0);
//Show the new graphic
ActiveViewInstance.Refresh();
}
I know that this is possible somehow and I am sure it's just a line or two missing but any help would be much appreciated.
V/r,
Josh
This looks to be a graphic element that you are creating. Graphic elements do not support transparency other than 100% transparent or 0% transparent. This is outlined in the following documentation:
IColor.Transparency Property
http://help.arcgis.com/en/sdk/10.0/arcobjects_net/componenthelp/index.html#//001w000000nt000000
For graphic elements, 0 for transparent and 255 for opaque are the only supported values.
I hope this helps!
I'm updating software that cuts up and stitches PowerPoint slides together for end users. The slides contain charts. I need to find a way of hiding the raw chart data from the users that receive the files.
Is there anyway of doing this natively within the PowerPoint interop?
I've tried Read-Only but the user can still get at the data.
Ok. Here is my final answer to my question.
This shows the completed code that can perfectly replicate the slide while keeping the charts from being edited i.e. buy turning it into a .png.
This also solves the previous problem of the placeholders being left.
Hopefully some of this code is helpful to someone trawling the internet like I did.
//Open the slides presentation
var pres = _application.Presentations.Open2007(item.PresentationPath,
Microsoft.Office.Core.MsoTriState.msoFalse,
Microsoft.Office.Core.MsoTriState.msoFalse,
Microsoft.Office.Core.MsoTriState.msoFalse,
Microsoft.Office.Core.MsoTriState.msoFalse);
//For slide ranges
foreach (var i in range)
{
//Get the old slide
var oldSlide = pres.Slides[i];
oldSlide.Copy();
//Paste the slide into the new presentation
var newSlide = newPresentation.Slides.Paste(totalSlides + 1);
newSlide.Design = oldSlide.Design;
newSlide.ColorScheme = oldSlide.ColorScheme;
/* The shapes haven't retained their content because we are not in slide...
view because there is no window. */
//Delete all the shapes that were just pasted in because of the slide paste.
for (int k = newSlide.Shapes.Count; k > 0; k--)
{
newSlide.Shapes[k].Delete();
}
//Put in our shapes
//Loop forwards, because we arn't editing the list and forward is required to
//maintain the zorder we want on some slides.
for (int j = 1; j <= oldSlide.Shapes.Count; j++)
{
var oldShape = oldSlide.Shapes[j];
oldShape.Copy();
//Paste Put it where it should be on the page
/* This is a special case where the client have put textboxes in the
Powerpoint and rotated throwing off the position, so we need treat as rotated
shapes to make it right. */
if (oldShape.HasTextFrame == MsoTriState.msoTrue && Math.Abs(oldShape.Rotation) > 0)
{
//Paste as a shape because it's a more complex object
//set ALL THE PROPERTIES just in case.
var newShape = newSlide.Shapes.PasteSpecial(PpPasteDataType.ppPasteShape);
newShape.Rotation = oldShape.Rotation;
newShape.Top = oldShape.Top;
newShape.Left = oldShape.Left;
newShape.TextFrame.Orientation = oldShape.TextFrame.Orientation;
newShape.TextFrame.WordWrap = oldShape.TextFrame.WordWrap;
newShape.TextFrame.VerticalAnchor = oldShape.TextFrame.VerticalAnchor;
}
else // Act normally
{
//Paste the old shape into the new slide as an image to ENSURE FORMATTING
var newShape = newSlide.Shapes.PasteSpecial(PpPasteDataType.ppPastePNG);
newShape.Top = oldShape.Top;
newShape.Left = oldShape.Left;
}
}
totalSlides += ((item.EndIndex - item.StartIndex) + 1);
pres.Close();
}
After the new presentation has been compiled, you must delete all placeholders.
//Loop through all slides
foreach (Slide exportSlide in newPresentation.Slides)
{
//Delete the placeholders
for (int i = exportSlide.Shapes.Placeholders.Count; i > 0; i--)
{
exportSlide.Shapes.Placeholders[i].Delete();
}
}
VBA to ungroup a chart (in order to remove any connection to the original data)
Sub UngroupAChart()
Dim oSh As Shape
Dim oNewSh As Shape
Dim oNewShapes As ShapeRange
Dim oSl As Slide
' for demo purposes, use the currently selected
' shape; up to tester to select a chart
Set oSh = ActiveWindow.Selection.ShapeRange(1)
' Get a reference to the shape's parent slide
' We'll need it later
Set oSl = oSh.Parent
' put the shape on the clipboard
oSh.Copy
Set oNewSh = oSl.Shapes.PasteSpecial(ppPasteEnhancedMetafile)(1)
oNewSh.Ungroup
' once you're done testing, delete the original chart
'oSh.Delete
End Sub
Using the principals of Steve's code I've created a bespoke one for my use. As I am interacting with PowerPoint as a Component Service, I don't have an ActiveWindow or anything.
//Loop through all slides
foreach (Slide exportSlide in newPresentation.Slides)
{
//Loop through all shapes
foreach (Shape shape in exportSlide.Shapes)
{
//If the shape is a chart
if (shape.HasChart == MsoTriState.msoTrue)
{
//Copy to clipboard
shape.Copy();
//Paste as an image
var newShape = exportSlide.Shapes.PasteSpecial(PpPasteDataType.ppPastePNG);
//Move back to chart position
newShape.Left = shape.Left;
newShape.Top = shape.Top;
//Delete the original shape
shape.Delete();
}
}
}
This works fine for replacing the charts with images (no data at all). The only issue now is that because the slides where created with a layout containing chart, when you open the slide in Powerpoint the GUI displays an "Insert Chart" box. I've tried:
exportSlide.Layout = PpSlideLayout.ppLayoutBlank;
However because of my clients custom templates this is not blank, so it's not usable.
I'm trying to offset the position of an image within a table-cell in ITextSharp. Below is some pseudo-code outlining some of my attempts, none of which seem to affect the positioning of the image. I'd specifically like to align the middle of the image with the left border of the cell, but I can't even seem to figure out how to move the image at all.
doc.Open();
var table = new PdfPTable(1);
var cell = new PdfPCell();
var image = Image.GetInstance(); //etc
image.SetAbsolutePosition(-10, 0); //no effect
image.Left -= 10; //no effect
image.IndentationRight = 10; // no effect
cell.AddElement(image);
table.Rows.Add(new PdfPRow(new PdfPCell[] { cell }));
doc.Add(table);
When adding an image to a cell, using an absolute position or changing the properties of the image won't have an effect. If I interpret your question correctly, you want to define a padding for the cell so that there's 10pt of space to the left. Just use the appropriate padding method on the cell object (in iText, that would be cell.setPaddingLeft(10);).