Spire.Doc is a professional Word .NET library specifically designed for developers to create, read, write, convert and print Word document files from any .NET platform (C#, VB.NET, ASP.NET, .NET Core) and Java applications (J2SE and J2EE) with fast and high quality performance.

Thu Mar 19, 2020 2:13 pm

Hi Team,

I am using free spire for my pdf conversion from dotx.i am facing some issue while converting dotx to pdf.The issue is i am inserting a field content in between of two field. while converting following field getting disaappered when i am giving more character conntent. Please find the code sample i have


private void btnMerge_Click(object sender, EventArgs e)
{
Document document = new Document();
var path = String.IsNullOrEmpty (this.txtPath.Text) ? "C:\\temp\\commentfield.dotx" : this.txtPath.Text;
var mergefield = this.txtMergeField.Text;
string htmlstring = this.rTxtContext.Text;

document.LoadFromFile(path);
//htmlstring = "<html><b><u>HTML string<u></b><html>";
var fild = document.Fields;
string code = string.Empty;
for (int i = 0; i <= fild.Count - 1; i++)
{
if (fild[i].Code.Contains(mergefield))
{
var o = fild[i];
int para = ((Spire.Doc.BodyRegion)o.Owner).OwnerTextBody.ChildObjects.IndexOf(o.OwnerParagraph);
for (int x = 0; x < o.OwnerParagraph.Items.Count; x++)
{

if (o.OwnerParagraph.Items[x].GetType() == typeof(Spire.Doc.Fields.Field))
{
var ab = (Spire.Doc.Fields.Field)o.OwnerParagraph.Items[x];
if (ab.Value.Equals(o.Value))
{

((Spire.Doc.BodyRegion)o.Owner).OwnerTextBody.InsertXHTML(htmlstring, para, x - 1);
ab.Code = string.Empty;
ab.Text= string.Empty;
ab.FieldText = string.Empty;
break;
}
}
}


}
}
document.SaveToFile("C:\\temp\\output.doc");
MessageBox.Show("Its completed");
}
You do not have the required permissions to view the files attached to this post.

Karthick07nkl
 
Posts: 5
Joined: Thu Mar 19, 2020 1:39 pm

Fri Mar 20, 2020 9:10 am

Hello,

Thanks for your inquiry.
I simulated a .dotx file and tested your case with both Free Spire.Doc for .NET Version:7.11 and the latest commercial version Spire.Doc Pack(hot fix) Version:8.3.8, but didn't reproduce your issue.
To help us better look into it, please provide the following information.
1) Your input .dotx file as well as you output .doc file.
2) Did your html string include any other tags? Please also share the htmlstring you used.
3) Your testing environment information, such as OS information (E.g. Windows 7, 64bit) and Region setting (E.g. China, Chinese).
You could attach them here or send them to us(support@e-iceblue.com) via email. Thanks in advance.

Sincerely,
Rachel
E-iceblue support team
User avatar

rachel.lei
 
Posts: 654
Joined: Tue Jul 09, 2019 2:22 am

Fri Mar 20, 2020 10:35 am

Hi Rachel,

Thank you very much for the reply.Even for latest version i am getting the same problem.Please find the templates what i have used .Please help on this.

Files Attached:
1.1_Templated file- This file has template fields and it is passed as input file.
2.Then replacing input content in the middle of sentence and generating anothor dotx file for our reuirement.
3.2_GeneratedDotxFile - this is output dotx file for another process.
4.3_Filnal Document-Final file - Finaly we are generating pdf or docx file.

Thanks
Karthick
You do not have the required permissions to view the files attached to this post.

Karthick07nkl
 
Posts: 5
Joined: Thu Mar 19, 2020 1:39 pm

Fri Mar 20, 2020 10:56 am

Please find the steps to reproduce the issue
You do not have the required permissions to view the files attached to this post.

Karthick07nkl
 
Posts: 5
Joined: Thu Mar 19, 2020 1:39 pm

Mon Mar 23, 2020 10:49 am

Hello,

Thanks for your more information.
When inserting multiple paragraphs, using your code would break the structure of the field, which causes the issue. Generally, we recommend inserting objects after the end tag of the field, or you could place the two fields into different paragraphs like the attachment modified document, so that the structure of the second field of wouldn't be destroyed. Hope you can understand.

Sincerely,
Rachel
E-iceblue support team
You do not have the required permissions to view the files attached to this post.
User avatar

rachel.lei
 
Posts: 654
Joined: Tue Jul 09, 2019 2:22 am

Mon Mar 23, 2020 1:33 pm

Thank you for your response. However in our use cases we have more than one field code in a paragraph. Can you suggest any available options for that .
Or could you elaborate the option "We recommend inserting objects after the end tag of the field ". with an example .?

Karthick07nkl
 
Posts: 5
Joined: Thu Mar 19, 2020 1:39 pm

Tue Mar 24, 2020 11:39 am

Hello,

Thanks for your response.
Sorry I didn't make it clear enough in my last post. Regarding the field mentioned in " after the end tag of the field", I mean the last field of the paragraph. However, what you want is to insert multiple paragraphs before the second field in the paragraph, this would break its structure. Anyway, I have posted this issue to our Dev team with the ticket SPIREDOC-4126 for further investigation to see if there is any solution. If there is any update, we will inform you.

Sincerely,
Rachel
E-iceblue support team
User avatar

rachel.lei
 
Posts: 654
Joined: Tue Jul 09, 2019 2:22 am

Tue Mar 24, 2020 12:28 pm

Thanks for the kind reply .Please let me know once your ticket resolved.

Karthick07nkl
 
Posts: 5
Joined: Thu Mar 19, 2020 1:39 pm

Wed Mar 25, 2020 1:54 am

Hello,

Ok, once there is any good news, we will let you know ASAP.
Wish you all the best!

Sincerely,
Rachel
E-iceblue support team
User avatar

rachel.lei
 
Posts: 654
Joined: Tue Jul 09, 2019 2:22 am

Wed Apr 29, 2020 9:54 am

Hello,

Thanks for your patient waiting.
Glad to tell you that the issue SPIREDOC-4126 has been fixed. Welcome to download the newly released Spire.Doc Pack(hot fix) Version:8.4.10 from the following links.
Website link: https://www.e-iceblue.com/Download/down ... t-now.html
Nuget link: https://www.nuget.org/packages/Spire.Doc/8.4.10

Code for your reference:
Code: Select all
        Document document = new Document();
        var path = "1_Templated file.dotx";
        var mergefield = "{field2}";
        string htmlstring = File.ReadAllText("html.txt");
        document.LoadFromFile(path);
        var fild = document.Fields;
        string code = string.Empty;

        for (int i = 0; i <= fild.Count - 1; i++)
        {
            if (fild[i].Code.Contains(mergefield))
            {
                var o = fild[i];
                int para = ((BodyRegion)o.Owner).OwnerTextBody.ChildObjects.IndexOf(o.OwnerParagraph);
                for (int x = 0; x < o.OwnerParagraph.Items.Count; x++)
                {
                    if (o.OwnerParagraph.Items[x].DocumentObjectType == DocumentObjectType.FieldMark)
                    {
                        var fieldMark = (FieldMark)o.OwnerParagraph.Items[x];
                        if (fieldMark.Type == FieldMarkType.FieldEnd)
                        {   
                            ((Spire.Doc.BodyRegion)o.Owner).OwnerTextBody.InsertXHTML(htmlstring, para, x + 1);
                            o.Code = string.Empty;
                            o.Text = string.Empty;
                            o.FieldText = string.Empty;
                            break;
                        }
                    }
                }
            }
        }
        document.SaveToFile("output.docx");


Sincerely,
Rachel
E-iceblue support team
User avatar

rachel.lei
 
Posts: 654
Joined: Tue Jul 09, 2019 2:22 am

Tue May 12, 2020 9:55 am

Hello,

Hope you are doing well.
Has your issue been resolved? Could you please give us some feedback at your convenience?
Thanks in advance.

Sincerely,
Rachel
E-iceblue support team
User avatar

rachel.lei
 
Posts: 654
Joined: Tue Jul 09, 2019 2:22 am

Return to Spire.Doc