We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Adding date/time stamp to Word doc converted to TIFF

We’re evaluating Aspose.Words to use in a Windows service that takes emailed documents in various formats and converts them to TIFF format, one TIFF file per page in the original document. This process also imprints a date/time stamp at the top of each page, much as a faxed document would have. I’m using the following code to accomplish this with Aspose.Words for the Word documents that we receive, but the resulting TIFF files do not have the date/time stamp. I added this line of code - document.Save(destinationPath + fileName); - to ensure that the date/time stamp is being added to the Word document object. Is what I’m trying to accomplish possible and the code just isn’t correct?

static string[] SplitEmailedWordFile(string destinationPath, string archivePath, ref string fileName, string timeStamp)

Document document;
int NumberOfPages = 0;
int iPage = 0;
int start = 0;

string baseFileName = “”;

if (fileName.LastIndexOf(".") > 0)
baseFileName = fileName.Substring(0, fileName.LastIndexOf("."));
baseFileName = fileName;

document = new Document(archivePath + fileName);

NumberOfPages = document.PageCount;

string[] filenames = new string[NumberOfPages];

string outputFormat = “”;

outputFormat = System.Configuration.ConfigurationManager.AppSettings[“OutputImageFormat”];

int fileFormat = GetFileTypeConstant(outputFormat);

string extension = GetFileExtension(fileFormat, “”);

Shape fax_timeStamp = new Shape(document, ShapeType.TextPlainText);

fax_timeStamp.TextPath.Text = timeStamp;

fax_timeStamp.TextPath.FontFamily = “Arial”;

fax_timeStamp.TextPath.Size = 5;

fax_timeStamp.Width = 100;

fax_timeStamp.Height = 5;

fax_timeStamp.Rotation = 0;

fax_timeStamp.Fill.Color = Color.Black;

fax_timeStamp.StrokeColor = Color.Black;

fax_timeStamp.RelativeHorizontalPosition = RelativeHorizontalPosition.Page;

fax_timeStamp.RelativeVerticalPosition = RelativeVerticalPosition.Page;

fax_timeStamp.VerticalAlignment = VerticalAlignment.Top;

fax_timeStamp.HorizontalAlignment = HorizontalAlignment.Left;

Paragraph timeStampPara = new Paragraph(document);


foreach(Section sect in document.Sections)
AddTimeStamp(timeStampPara, sect, HeaderFooterType.HeaderPrimary);
AddTimeStamp(timeStampPara, sect, HeaderFooterType.HeaderFirst);
AddTimeStamp(timeStampPara, sect, HeaderFooterType.HeaderEven);

for (iPage = start; iPage < NumberOfPages; iPage++)
filenames[iPage] = baseFileName + (iPage + 1).ToString(“0000”) + extension;

if (File.Exists(destinationPath + filenames[iPage]))
File.Delete(destinationPath + filenames[iPage]);

document.SaveToImage(iPage, 1, destinationPath + filenames[iPage], null);


document.Save(destinationPath + fileName);

return filenames;
catch(Exception ex){
ExceptionHandling.ExceptionHandling.WriteToEventLog(ex.Message + " " + NumberOfPages.ToString() + " " + iPage.ToString(), “ProcessDocumentsService”, “ProcessDocuments.cs”, “SplitEmailedWordFile”);
throw ex;


static void AddTimeStamp(Paragraph timeStampPara, Section sect, HeaderFooterType headerType)

HeaderFooter header = sect.HeadersFooters[headerType];

if (header == null)
header = new HeaderFooter(sect.Document, headerType);



<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

Thanks for your request. It seems the problem occurs because you call Document.PageCount property before doing modification in the document. Solution of this problem is very simple – just call Document.UpdatePageLayout method before saving document to TIF.

Best regards.

Thanks for the rapid response, Alexey. That did the trick!