Esempio n. 1
0
 private static void CopyHeaderImages(HeaderPart oldHeader, HeaderPart newHeader, List<ImageData> images)
 {
     foreach (XElement imageReference in newHeader.GetXDocument().Descendants(ns_a + "blip"))
     {
         string relId = imageReference.Attribute(ns_r + "embed").Value;
         ImagePart oldPart = (ImagePart)oldHeader.GetPartById(relId);
         ImageData temp = ManageImageCopy(oldPart, images);
         if (temp.ResourceID == null)
         {
             ImagePart newPart = newHeader.AddImagePart(oldPart.ContentType);
             temp.ResourceID = newHeader.GetIdOfPart(newPart);
             temp.WriteImage(newPart);
         }
         imageReference.Attribute(ns_r + "embed").Value = temp.ResourceID;
     }
 }
Esempio n. 2
0
 private static void CopyHeaderEmbeddedObjects(HeaderPart oldHeader, HeaderPart newHeader)
 {
     foreach (XElement oleReference in newHeader.GetXDocument().Descendants(ns_o + "OLEObject"))
     {
         string relId = oleReference.Attribute(ns_r + "id").Value;
         EmbeddedObjectPart oldPart = (EmbeddedObjectPart)oldHeader.GetPartById(relId);
         EmbeddedObjectPart newPart = newHeader.AddEmbeddedObjectPart(oldPart.ContentType);
         using (Stream oldObject = oldPart.GetStream(FileMode.Open, FileAccess.Read))
         using (Stream newObject = newPart.GetStream(FileMode.Create, FileAccess.ReadWrite))
         {
             int byteCount;
             byte[] buffer = new byte[65536];
             while ((byteCount = oldObject.Read(buffer, 0, 65536)) != 0)
                 newObject.Write(buffer, 0, byteCount);
         }
         oleReference.Attribute(ns_r + "id").Value = newHeader.GetIdOfPart(newPart);
     }
 }