/// <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); }
/// <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; }