I’m developing a system which converts Word documents into PDFs and I need to be able to add a date to the resulting pdf when it is printed to show when it is to expire, basically 2 weeks from the date of printing.
I have Aspose.Words and Aspose.Pdf. I started with this article:
and am trying to adapt it to the Aspose technology. After reading through your documentation and forums I have developed the following technique, which adds a form field to the source Word document, converts it to PDF while preserving the form fields, and added Javascript to the resulting PDF to add the date when the document is opened:
MemoryStream xmlStream = new MemoryStream();
Document doc = new Document(path);
DocumentBuilder db = new DocumentBuilder(doc);
db.Document.SaveOptions.PdfExportFormFieldsAsText = false;
Aspose.Words.Fields.FormField ff = db.InsertTextInput ("DateField", Aspose.Words.Fields.TextFormFieldType.RegularText, "", "Adding a text field to word: ", 100);
ff.Enabled = true;
ff.Name = "DateField";
db.Document.Save(xmlStream, SaveFormat.AsposePdf);
Pdf pdf = new Pdf();
MemoryStream pdfStream = new MemoryStream();
pdf.BindXML(xmlStream, null);
// Save to a stream first to check for conversion problems.
// Saving to a file with conversion problems causes the file to
// become locked and requires an IIS reset to correct.
pdf.Save(pdfStream);
Pdf pdfFile = new Pdf();
pdfFile.BindXML(xmlStream, null);
string pdfOutputPath = "";
pdfOutputPath = path2
pdfFile.IsImagesInXmlDeleteNeeded = true;
pdfFile.JavaScripts = new JavaScripts();
pdfFile.JavaScripts.Add("this.getField(\"DateField\").value = \"Date Added by javascript\";");
pdfFile.Save(outputpath);
This code successfully adds the form field and it shows up in the PDF, but the text is not altered by the Javascript. From what I read you only have support for adding document level Javascript so I can’t add script to the print event, but if it were to alter the text when opened it would serve my purpose. Can anyone help me figure out how to get this done?
As a side note, the form fields seem to disappear when I try to put them in the footer. Is this a known issue?
Let me share something related to one of our component named Aspose.Pdf.Kit which is used to manipulate/edit Pdf files. This component offers the capability to insert the watermark over the Pdf file, and also offers the capability to Print the Pdf files. According to your requirement, you can first convert the word file into Pdf and then use PdfFileStamp to add text watermark showing the current system date and finally Print the Pdf file using PdfViewer.
FYI: In recent version of Aspose.Words, you can save the Word file directly into Pdf format, without using Aspose.Pdf. So in this case, you would have to use Aspose.Words to generate the Pdf file, and Aspose.Pdf.Kit to add watermark and Print the resultant file.
Regarding the issue of adding form field in Footer section, we are looking into this matter and will reply to you soon.
In case, it does not satisfy your requirement, please feel free to share.
In Aspose.Pdf, it is known that form field is not supported in Header/Footer. I will contact with our developers and confirm if we plan to support it. Sorry for inconvenience.
I am afraid we have no plan to support form field in Header/Footer at present. Would you please let us know what is your intention of adding form field to Header/Footer ? We may find you some workarounds on it. Sorry for inconvenience.
This won’t work because another system is responsible for printing the documents. I need to be able to convert the Word Document to PDF, insert the system date mark, and send it to the other system. Then when that system opens the PDF in Adobe Reader and prints it, the date printed needs to be 14 days from the date it was printed (not the date I converted the PDF and sent it to the other system). I am not able to alter the other system.
I am afraid you may need Aspose.Pdf.Kit to achieve it. Aspose.Pdf.Kit is used to editing an exist pdf file. For further help, please contact Aspose.Pdf.Kit’s forum. Sorry for inconvenience.
I'm looking into your requirement. Can you please clarify one thing so I'll be able to help you out?
As I have understood your requirement, you want to add a placeholder for date when you convert a word document to pdf, and when that created pdf will be printed, or opened on the other system for that matter, you want this place holder to have date equal to current date plus the 14 days from this current date. Have I understood your requirement or you want to add something more?
Please confirm so I'll proceed to look into your requirement in detail.
Yes that is correct. The date field doesn’t need to be added before the conversion, that’s just how I was trying to do it. If it could be added to the pdf that would be fine too. The key though, is to be able to have the date be 14 days from the time the pdf is opened or printed. I assume this would need to be done with Adobe Javascipt.
Sets consent for sending user data to Google for online advertising purposes.
Sets consent for personalized advertising.
Cookie Notice
To provide you with the best experience, we use cookies for personalization, analytics, and ads. By using our site, you agree to our cookie policy.
More info
Enables storage, such as cookies, related to analytics.
Enables storage, such as cookies, related to advertising.
Sets consent for sending user data to Google for online advertising purposes.
Sets consent for personalized advertising.
Cookie Notice
To provide you with the best experience, we use cookies for personalization, analytics, and ads. By using our site, you agree to our cookie policy.
More info
Enables storage, such as cookies, related to analytics.
Enables storage, such as cookies, related to advertising.
Sets consent for sending user data to Google for online advertising purposes.