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”)
{
string bodyType = objDoc.Sections[iNumberSections - 1].
//empty last page here do something with it
objDoc.Sections[iNumberSections - 1].Remove();
}
//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);
//Ciara - 06/05/2016
objDoc.UpdatePageLayout();
//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);
}
}
}
}
All we really do with this is pass in the document location, convert it to pdf (using this method) then save the pdf. What I think we could do is where I check for an empty page which is:
//is there a blank page? if so remove it
if (objDoc.Sections[iNumberSections - 1].Body.GetText() == “\f”)
{
string bodyType = objDoc.Sections[iNumberSections - 1].
//empty last page here do something with it
objDoc.Sections[iNumberSections - 1].Remove();
}
I would like to bypass the line objDoc.Sections[iNumberSections - 1].Remove(); if an image exists in this section. Do you know how I could do this?
Thanks
Ciara