PDF Picks Up Current Date - Need CreateDate

We have millions Microsoft Word letters sent to customers, mostly 10 - 20 years old, that we

will use ASPOSE.Words (the one product in the suite we own), called from a VB.NET console application,

to deposit into an archival location as PDF’s.

In many cases, the date of the letter was stored as a Date field, in the original template. As a

result, when the document is opened in Word – or converted to a PDF with the ASPOSE.Words Save method

– the date of the letter becomes the day that the document was archived.

In Microsoft Word, one can right-click on the visible date, click on Update Field, change the field

name from Date to CreateDate, and then see the original date the letter was created and mailed to the

customer. That’s the date we want for the PDF.

So, the question is – what would be the easiest way to have the PDF permanently show the original

date? Another way to phrase it may be: How can we most easily turn off bookmarks and fields?

I’ve looked at the PdfSaveOptions, and the rest of the Saving class, and don’t see it there – although

it may be staring me in the face.

All ideas will be appreciated.

@Eisenberg,

You may lock Date fields before saving to PDF. For example,

Document doc = new Document(MyDir + @"input.docx");
            
foreach(Field field in doc.Range.Fields)
{
    if (field.Type == FieldType.FieldCreateDate || 
        field.Type == FieldType.FieldDate || 
        field.Type == FieldType.FieldPrintDate || 
        field.Type == FieldType.FieldSaveDate)
    {
        field.IsLocked = true;
    }
}

doc.Save(MyDir + @"18.4.pdf");

Thank you, thank you! This was extremely helpful.

It turns out that some of our Word documents have a Time field that also needed locking, so I added that. Our old documents, being archived, are all .doc rather than .docx. Works fine. For the record, here is, with apologies for ugliness, the VB.NET code, working for me this morning, to save MS Word letters as much smaller PDF’s:

Dim sPdfName As String = “”
Dim MyTemplateVariable As Aspose.Words.Document = New Aspose.Words.Document(“<path for old .doc>”)
For Each field As Aspose.Words.Fields.Field In MyTemplateVariable.Range.Fields
If ((field.Type = Aspose.Words.Fields.FieldType.FieldCreateDate) _
OrElse ((field.Type = Aspose.Words.Fields.FieldType.FieldDate) _
OrElse ((field.Type = Aspose.Words.Fields.FieldType.FieldTime) _
OrElse ((field.Type = Aspose.Words.Fields.FieldType.FieldPrintDate) _
OrElse (field.Type = Aspose.Words.Fields.FieldType.FieldSaveDate))))) Then
field.IsLocked = True
End If
Next
Dim MyBuilderVariable = New Aspose.Words.DocumentBuilder(MyTemplateVariable)
Dim optionsToPDF As Aspose.Words.Saving.PdfSaveOptions =
New Aspose.Words.Saving.PdfSaveOptions
optionsToPDF.ImageCompression = Aspose.Words.Saving.PdfTextCompression.Flate
optionsToPDF.ImageCompression = Aspose.Words.Saving.PdfImageCompression.Jpeg
optionsToPDF.FontEmbeddingMode = Aspose.Words.Saving.PdfFontEmbeddingMode.EmbedNone
optionsToPDF.JpegQuality = 80
MyTemplateVariable.Save(sPdfName, optionsToPDF)

@Eisenberg,

Thanks for the feedback. Please let us know anytime you have any further queries.