/// <summary> /// Gets Paragraph that includes the embedded object /// </summary> private static Paragraph GetEmbeededObjectParagraph(string fileType, string imageID, string imageStyle, string embeddedPackageID) { EmbeddedObject embeddedObject = new EmbeddedObject(); string shapeID = GetUniqueXmlItemID(); V.Shape shape = new V.Shape() { Id = shapeID, Style = imageStyle }; V.ImageData imageData = new V.ImageData() { Title = "", RelationshipId = imageID }; shape.Append(imageData); OVML.OleObject oleObject = new OVML.OleObject() { Type = OVML.OleValues.Embed, ProgId = fileType, ShapeId = shapeID, DrawAspect = OVML.OleDrawAspectValues.Icon, ObjectId = GetUniqueXmlItemID(), Id = embeddedPackageID }; embeddedObject.Append(shape); embeddedObject.Append(oleObject); Paragraph paragraphImage = new Paragraph(); Run runImage = new Run(embeddedObject); paragraphImage.Append(runImage); return(paragraphImage); }
private EmbeddedObject ProcessObject(string filePath, string contentType, string progId) { if (TryCreateAbsoluteUri(filePath, out Uri uri)) { int width, height; string relationshipId = string.Concat("rId", (++context.RelationshipId).ToString()); EmbeddedPackagePart embeddedPackagePart = context.MainDocumentPart.AddNewPart <EmbeddedPackagePart>(contentType, relationshipId); using (Stream stream = GetStream(uri)) { embeddedPackagePart.FeedData(stream); } ImagePart imagePart = context.MainDocumentPart.AddImagePart(ImagePartType.Jpeg); using (MemoryStream mem = GetImageStream(Path.GetFileName(filePath), out width, out height)) { imagePart.FeedData(mem); } V.Shape shape = new V.Shape() { Id = string.Concat("_x0000_i", context.RelationshipId.ToString()), Ole = false, Type = "#_x0000_t75", Style = "width:" + width.ToString() + "pt;height:" + height.ToString() + "pt" }; V.ImageData imageData = new V.ImageData() { Title = "", RelationshipId = context.MainDocumentPart.GetIdOfPart(imagePart) }; shape.Append(imageData); EmbeddedObject embeddedObject = new EmbeddedObject() { DxaOriginal = "9360", DyaOriginal = "450" }; embeddedObject.Append(shape); OVML.OleObject oleObject = new OVML.OleObject() { Type = OVML.OleValues.Embed, ProgId = progId, ShapeId = string.Concat("_x0000_i", context.RelationshipId.ToString()), DrawAspect = OVML.OleDrawAspectValues.Content, ObjectId = string.Concat("_", context.RelationshipId.ToString()), Id = relationshipId }; embeddedObject.Append(oleObject); return(embeddedObject); } return(null); }
private static void GenerateHeaderPart1Content(HeaderPart headerPart1) { var header1 = new Header(); var paragraph2 = new Paragraph(); var run1 = new Run(); var picture1 = new Picture(); var shape1 = new V.Shape { Id = "WordPictureWatermark75517470", Style = "position:absolute;left:0;text-align:left;margin-left:0;margin-top:0;width:456.15pt;height:456.15pt;z-index:-251656192;mso-position-horizontal:center;mso-position-horizontal-relative:margin;mso-position-vertical:center;mso-position-vertical-relative:margin", OptionalString = "_x0000_s2051", AllowInCell = false, Type = "#_x0000_t75" }; var imageData1 = new V.ImageData { Gain = "19661f", BlackLevel = "22938f", Title = "水印", RelationshipId = "rId999" }; shape1.Append(imageData1); picture1.Append(shape1); run1.Append(picture1); paragraph2.Append(run1); header1.Append(paragraph2); headerPart1.Header = header1; header1.Save(); }
/// <summary> /// Generates the run to embed in the document so that objects can be viewed inline. /// </summary> /// <param name="imagePartId">ID of the image icon from GetIdOfPart.</param> /// <param name="objectPartId">ID of the object association from GetIdOfPart.</param> /// <param name="extension">File extension</param> /// <returns>A run linking all items.</returns> private Run GetObjectRun(string imagePartId, string objectPartId, string extension) { String shapePrefix = "_x0000_i"; int shapeId = this.shapeId++; int objectId = this.objectId++; EmbeddedObject embeddedObject = new EmbeddedObject() { DxaOriginal = "1531", DyaOriginal = "990" }; //EmbeddedObjectInit only needs to run if there are no objects already within the document. if (!objectsPresent) { embeddedObject.Append(EmbeddedObjectInit()); objectsPresent = true; } V.Shape shape = new V.Shape() { Id = shapePrefix + shapeId, Style = "width:76.35pt;height:49.45pt", Ole = null, Type = "#_x0000_t75" }; V.ImageData imageData = new V.ImageData() { Title = "", RelationshipId = imagePartId }; shape.Append(imageData); embeddedObject.Append(shape); String progId = GetProgId(extension); Ovml.OleObject oleObject = new Ovml.OleObject() { Type = Ovml.OleValues.Embed, ProgId = progId, ShapeId = shapePrefix + shapeId, DrawAspect = Ovml.OleDrawAspectValues.Icon, ObjectId = "_" + objectId, Id = objectPartId }; embeddedObject.Append(oleObject); Run r = new Run(); r.Append(embeddedObject); return r; }
public void Write(Marker marker, Image image) { if (image == null) { return; } var markerParagraph = marker.Container; var parent = markerParagraph.Parent; W.Picture imageElement = new W.Picture(); V.Shapetype shapetype1 = new V.Shapetype() { Id = "_x0000_t75", CoordinateSize = "21600,21600", Filled = false, Stroked = false, OptionalNumber = 75, PreferRelative = true, EdgePath = "m@4@5l@4@11@9@11@9@5xe" }; V.Stroke stroke1 = new V.Stroke() { JoinStyle = V.StrokeJoinStyleValues.Miter }; V.Formulas formulas1 = new V.Formulas(); V.Formula formula1 = new V.Formula() { Equation = "if lineDrawn pixelLineWidth 0" }; V.Formula formula2 = new V.Formula() { Equation = "sum @0 1 0" }; V.Formula formula3 = new V.Formula() { Equation = "sum 0 0 @1" }; V.Formula formula4 = new V.Formula() { Equation = "prod @2 1 2" }; V.Formula formula5 = new V.Formula() { Equation = "prod @3 21600 pixelWidth" }; V.Formula formula6 = new V.Formula() { Equation = "prod @3 21600 pixelHeight" }; V.Formula formula7 = new V.Formula() { Equation = "sum @0 0 1" }; V.Formula formula8 = new V.Formula() { Equation = "prod @6 1 2" }; V.Formula formula9 = new V.Formula() { Equation = "prod @7 21600 pixelWidth" }; V.Formula formula10 = new V.Formula() { Equation = "sum @8 21600 0" }; V.Formula formula11 = new V.Formula() { Equation = "prod @7 21600 pixelHeight" }; V.Formula formula12 = new V.Formula() { Equation = "sum @10 21600 0" }; formulas1.Append(formula1); formulas1.Append(formula2); formulas1.Append(formula3); formulas1.Append(formula4); formulas1.Append(formula5); formulas1.Append(formula6); formulas1.Append(formula7); formulas1.Append(formula8); formulas1.Append(formula9); formulas1.Append(formula10); formulas1.Append(formula11); formulas1.Append(formula12); V.Path path1 = new V.Path() { AllowGradientShape = true, ConnectionPointType = Ovml.ConnectValues.Rectangle, AllowExtrusion = false }; Ovml.Lock lock1 = new Ovml.Lock() { Extension = V.ExtensionHandlingBehaviorValues.Edit, AspectRatio = true }; shapetype1.Append(stroke1); shapetype1.Append(formulas1); shapetype1.Append(path1); shapetype1.Append(lock1); V.Shape shape1 = new V.Shape() { Id = "_x0000_i1025", Style = string.Format("width:{0}pt;height:{1}pt", image.Width, image.Height), Type = "#_x0000_t75" }; V.ImageData imageData1 = new V.ImageData() { Title = "eed80b48-ca3b-4af3-85c1-c5d1a0af4c63", RelationshipId = image.Id }; shape1.Append(imageData1); imageElement.Append(shapetype1); imageElement.Append(shape1); parent.InsertAfter(imageElement, markerParagraph); }