Spire.Doc is a professional Word .NET library specifically designed for developers to create, read, write, convert and print Word document files. Get free and professional technical support for Spire.Doc for .NET, Java, Android, C++, Python.

Thu Nov 29, 2018 3:03 pm

I am trying to convert .doc file to PDF. The .doc file has form fields and one of them is type of Current Date. When I save to pdf format the form field get update to the current date. How can I avoid this? I want to keep the original date.

scmisysdev
 
Posts: 2
Joined: Tue Nov 27, 2018 7:19 pm

Fri Nov 30, 2018 6:39 am

Hi,

Thanks for your inquiry.
After investigation, I found the locked field would not be updated, but using Spire.Doc to lock the field didn't work. I have forwarded the issue to our dev team for further investigation. If there is any update, I will inform you.
Besides, to make sure your problem can be fixed finally, please share us your sample file here or via email(support@e-iceblue.com).
Sincerely,
Mike
E-iceblue support team
User avatar

Mike.Zhang
 
Posts: 93
Joined: Thu Sep 27, 2018 7:11 am

Fri Nov 30, 2018 2:07 pm

Hi,

I can't share the original file, but if you create a doc file with a form field with the same options of the post I posted, you should replicate the issue.

For now this is what I did to make it work:

Get the value of the form field and append after and delete the text from the form text.

Code: Select all
                var currentDate = DateTime.Now.ToString("M/d/yyyy");
                foreach (FormField field in document.Sections[0].Body.FormFields)
                {
                    if (field is TextFormField)
                    {
                        var textFormField = (TextFormField)field;
                        if(textFormField.TextFieldType == TextFormFieldType.CurrentDate)
                        {
                            var text = textFormField.FieldText;
                            var newText = text.Replace(currentDate, "");
                            textFormField.OwnerParagraph.AppendText(newText);

                            textFormField.TextFieldType = TextFormFieldType.RegularText;
                            textFormField.Text = "";
                        }
                    }
                }
                document.SaveToFile(newFilePath, FileFormat.PDF);


Please let me know if there is a fix and a better way to do this.

Thanks.

scmisysdev
 
Posts: 2
Joined: Tue Nov 27, 2018 7:19 pm

Mon Dec 03, 2018 9:21 am

Hi,

Thanks for sharing your solution. As I said before, there is another solution, that is locking the field. And I got information from our Dev team, the issue I mentioned before has been fixed and now it is in test phase. Once the hotfix is available, I will inform you.
Sincerely,
Mike
E-iceblue support team
User avatar

Mike.Zhang
 
Posts: 93
Joined: Thu Sep 27, 2018 7:11 am

Tue Dec 04, 2018 10:28 am

Hi,

Glad to inform you that the issue of locking the field has been fixed and the hotfix is available now. Welcome to download Spire.Doc Pack(hot fix) Version:6.12.1.
Please refer to below code.
Code: Select all
                foreach (FormField field in document.Sections[0].Body.FormFields)
                {
                    if (field is TextFormField)
                    {
                        var textFormField = (TextFormField)field;
                        if(textFormField.TextFieldType == TextFormFieldType.CurrentDate)
                        {
                             textFormField.IsLocked = true;
                        }
                    }
                }
Sincerely,
Mike
E-iceblue support team
User avatar

Mike.Zhang
 
Posts: 93
Joined: Thu Sep 27, 2018 7:11 am

Return to Spire.Doc