If you have any complaints or suggestions about our service or products, please post them here. Your comments will help us to make continuous progress.

Wed Dec 16, 2020 8:27 pm

Hello,

I am using the Spire reference to get a document template and replace an word with a Table. The problem that I am having is that whenever I replace the word with the table and save the document to PDF, it adds an extra blank page.

code sample:

Section section = document.AddSection();
TextSelection selection = document.FindString(Word, True, True);
TextRange range = selection.GetAsOneRange();
Paragraph paragraph = range.OwnerParagraph;
Body body = paragraph.OwnerTextBody;
int index = body.ChildObject.IndexOf(paragraph);

Table table = section.AddTable(true);
table.ResetCells(#,#);
table.AutoFit(AutoFitBehaviorType.AutoFitContents);
table.TableFormat.IsBreakAcrossPage = True;

body.ChildObjects.Remove(paragraph);
body.ChildObjects.Insert(index, table);

triplespropiedad
 
Posts: 1
Joined: Tue Feb 25, 2020 1:21 am

Thu Dec 17, 2020 2:09 am

Hello,

Thanks for your inquiry.
To remove the blank page, please refer to the modified code below. Feel free to contact us if you have further questions.
Code: Select all
            String Word = "and";
            Document document = new Document();
            document.LoadFromFile("test.docx");
            //Section section = document.AddSection();
            Section section = document.Sections[0];

            TextSelection selection = document.FindString(Word, true, true);
            TextRange range = selection.GetAsOneRange();
            Paragraph paragraph = range.OwnerParagraph;
            Body body = paragraph.OwnerTextBody;
            int index = body.ChildObjects.IndexOf(paragraph);

            Table table = section.AddTable(true);
            table.ResetCells(3, 3);
            table.AutoFit(AutoFitBehaviorType.AutoFitToContents);
            table.TableFormat.IsBreakAcrossPages = true;
            body.ChildObjects.Remove(paragraph);
            body.ChildObjects.Insert(index, table);


Sincerely,
Brian
E-iceblue support team
User avatar

Brian.Li
 
Posts: 1271
Joined: Mon Oct 19, 2020 3:04 am

Mon Dec 28, 2020 6:26 am

Hello,

How is your issue now? Could you please give us some feedback at your convenience?

Sincerely,
Brian
E-iceblue support team
User avatar

Brian.Li
 
Posts: 1271
Joined: Mon Oct 19, 2020 3:04 am

Return to Complaints & Suggestions