Hello,
I am having an issue displaying an image when converting a word document to pdf. I have attached an example word document and the converted pdf. The image at the top is displaying a red X instead of the image from the word document. The method that converts this is as follows:
public static void FormatConvertDocs(string sCopiedFileName, bool p_bRemoveSeal, string sTempLocation, out string sPDFName)
{
string sDocType = System.IO.Path.GetExtension(sCopiedFileName);
sPDFName = System.IO.Path.GetFileNameWithoutExtension(sCopiedFileName);
//4. we need to check if the type is a document, if it is then we don’t need to convert it
if (sDocType.ToLower() != “.pdf”)
{
Aspose.Words.Document objDoc = new Aspose.Words.Document(sCopiedFileName);
if (p_bRemoveSeal)
{
//remove the seal - return as txt file?
objDoc.Save(sTempLocation + sPDFName + “.txt”);
File.Delete(sCopiedFileName);
}
else
{
int iNumberSections = objDoc.Sections.Count;
//is there a blank page? if so remove it
if (objDoc.Sections[iNumberSections - 1].Body.GetText() == “\f”)
{
//Ciara - Image Issue - 06/05/2016
Aspose.Words.NodeCollection shapes = objDoc.GetChildNodes(Aspose.Words.NodeType.Shape, true);
foreach (Aspose.Words.Drawing.Shape shape in shapes)
{
if (!shape.HasImage)
{
//empty last page here do something with it
objDoc.Sections[iNumberSections - 1].Remove();
}
}
//Ciara end
}
//check for hidden report text - EJO fault fixed by this
if (objDoc.Sections[0].Body.GetText().ToLower().Contains(“this file was created by oracle reports. view this document in page layout mode”))
{
int ipara = objDoc.Sections[0].Body.Paragraphs.Count;
if (objDoc.Sections[0].Body.Paragraphs[1].GetText().ToLower().Contains(“this file was created by oracle reports. view this document in page layout mode”))
{
objDoc.Sections[0].Body.Paragraphs[1].Remove();
}
else if (objDoc.Sections[0].Body.Paragraphs[0].GetText().ToLower().Contains(“this file was created by oracle reports. view this document in page layout mode”))
{
objDoc.Sections[0].Body.Paragraphs[0].Remove();
}
}
//do we have more than one page? then we need to tidy our headers and footers
if (iNumberSections > 1)
{
//are there headers and footers?
if (objDoc.Sections[0].HeadersFooters.Count > 0)
{
//get the main header
Aspose.Words.HeaderFooter x = objDoc.Sections[0].HeadersFooters[0];
Aspose.Words.HeaderFooter BottomFooter = objDoc.Sections[0].HeadersFooters[1];
//strip all the headers & footers from the document
int iNumberDocSections = objDoc.Sections.Count;
for (int i = iNumberDocSections - 1; i >= 0; i–)
{
int iNumberHeaderFooters = objDoc.Sections[i].HeadersFooters.Count;
for (int j = iNumberHeaderFooters - 1; j >= 0; j–)
{
objDoc.Sections[i].HeadersFooters[j].Remove();
}
}
//at this stage headers should be clear
objDoc.UpdateFields();
objDoc.AcceptAllRevisions();
//insert our header and footer
objDoc.Sections[0].HeadersFooters.Insert(0, x);
objDoc.Sections[0].HeadersFooters.Insert(1, BottomFooter);
//convert the document
objDoc.Save(sTempLocation + sPDFName + “.pdf”);
}
else
{
//no headers or footers
objDoc.Save(sTempLocation + sPDFName + “.pdf”);
}
}
else
{
//we’ve only one page no work to do here
objDoc.Save(sTempLocation + sPDFName + “.pdf”);
}
objDoc.Save(sTempLocation + sPDFName + “.pdf”);
File.Delete(sCopiedFileName);
}
//TODO - need to check here if we need to remove the seal
//TODO - need to check to see if the file has been deleted?
}
}
}
You should also note that this has started happening all of a sudden, there were no issues previously and no changes have ben made to the code or the template.
Any help with this is much appreciated.
Thanks
Ciara