|
|
|
@@ -983,6 +983,7 @@ namespace Novacode |
|
|
|
List<String> imageContentTypes = new List<string>
|
|
|
|
{
|
|
|
|
"image/jpeg",
|
|
|
|
"image/jpg",
|
|
|
|
"image/png",
|
|
|
|
"image/bmp",
|
|
|
|
"image/gif",
|
|
|
|
@@ -1152,11 +1153,15 @@ namespace Novacode |
|
|
|
private void merge_images(PackagePart remote_pp, DocX remote_document, XDocument remote_mainDoc, String contentType)
|
|
|
|
{
|
|
|
|
// Before doing any other work, check to see if this image is actually referenced in the document.
|
|
|
|
// In my testing I have found cases of Images inside documents that are not refer
|
|
|
|
// In my testing I have found cases of Images inside documents that are not referenced
|
|
|
|
var remote_rel = remote_document.mainPart.GetRelationships().Where(r => r.TargetUri.OriginalString.Equals(remote_pp.Uri.OriginalString.Replace("/word/", ""))).FirstOrDefault();
|
|
|
|
if (remote_rel == null)
|
|
|
|
return;
|
|
|
|
|
|
|
|
{
|
|
|
|
remote_rel = remote_document.mainPart.GetRelationships().Where(r => r.TargetUri.OriginalString.Equals(remote_pp.Uri.OriginalString)).FirstOrDefault();
|
|
|
|
if (remote_rel == null)
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
String remote_Id = remote_rel.Id;
|
|
|
|
|
|
|
|
String remote_hash = ComputeMD5HashString(remote_pp.GetStream());
|
|
|
|
@@ -1172,6 +1177,10 @@ namespace Novacode |
|
|
|
found = true;
|
|
|
|
|
|
|
|
var local_rel = mainPart.GetRelationships().Where(r => r.TargetUri.OriginalString.Equals(part.Uri.OriginalString.Replace("/word/", ""))).FirstOrDefault();
|
|
|
|
if (local_rel == null)
|
|
|
|
{
|
|
|
|
local_rel = mainPart.GetRelationships().Where(r => r.TargetUri.OriginalString.Equals(part.Uri.OriginalString)).FirstOrDefault();
|
|
|
|
}
|
|
|
|
if (local_rel != null)
|
|
|
|
{
|
|
|
|
String new_Id = local_rel.Id;
|
|
|
|
@@ -1208,7 +1217,7 @@ namespace Novacode |
|
|
|
{
|
|
|
|
String new_uri = remote_pp.Uri.OriginalString;
|
|
|
|
new_uri = new_uri.Remove(new_uri.LastIndexOf("/"));
|
|
|
|
new_uri = new_uri.Replace("word/", "");
|
|
|
|
//new_uri = new_uri.Replace("word/", "");
|
|
|
|
new_uri += "/" + Guid.NewGuid().ToString() + contentType.Replace("image/", ".");
|
|
|
|
if (!new_uri.StartsWith("/"))
|
|
|
|
new_uri = "/" + new_uri;
|
|
|
|
@@ -1232,6 +1241,9 @@ namespace Novacode |
|
|
|
|
|
|
|
String new_Id = pr.Id;
|
|
|
|
|
|
|
|
//Check if the remote relationship id is a default rId from Word
|
|
|
|
Match defRelId = Regex.Match(remote_Id, @"rId\d+", RegexOptions.IgnoreCase);
|
|
|
|
|
|
|
|
// Replace all instances of remote_Id in the local document with local_Id
|
|
|
|
var elems = remote_mainDoc.Descendants(XName.Get("blip", DocX.a.NamespaceName));
|
|
|
|
foreach (var elem in elems)
|
|
|
|
@@ -1243,6 +1255,33 @@ namespace Novacode |
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!defRelId.Success)
|
|
|
|
{
|
|
|
|
// Replace all instances of remote_Id in the local document with local_Id
|
|
|
|
var elems_local = mainDoc.Descendants(XName.Get("blip", DocX.a.NamespaceName));
|
|
|
|
foreach (var elem in elems_local)
|
|
|
|
{
|
|
|
|
XAttribute embed = elem.Attribute(XName.Get("embed", DocX.r.NamespaceName));
|
|
|
|
if (embed != null && embed.Value == remote_Id)
|
|
|
|
{
|
|
|
|
embed.SetValue(new_Id);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Replace all instances of remote_Id in the local document with local_Id
|
|
|
|
var v_elems_local = mainDoc.Descendants(XName.Get("imagedata", DocX.v.NamespaceName));
|
|
|
|
foreach (var elem in v_elems_local)
|
|
|
|
{
|
|
|
|
XAttribute id = elem.Attribute(XName.Get("id", DocX.r.NamespaceName));
|
|
|
|
if (id != null && id.Value == remote_Id)
|
|
|
|
{
|
|
|
|
id.SetValue(new_Id);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Replace all instances of remote_Id in the local document with local_Id (for shapes as well)
|
|
|
|
var v_elems = remote_mainDoc.Descendants(XName.Get("imagedata", DocX.v.NamespaceName));
|
|
|
|
foreach (var elem in v_elems)
|