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.

Fri Jul 28, 2017 1:17 pm

Hi,

we generate the document form template and we don't know how long will be the text, that we paste to the document. We get the document with empty pages now. How can we remove these empty pages (Pages C, D and E in the sample document)?

I have sent the sample document to email support@e-iceblue.com

Best regards.
Josef

mardla
 
Posts: 5
Joined: Fri Jun 09, 2017 12:32 pm

Mon Jul 31, 2017 5:48 am

Dear Josef,

Sorry for late reply as weekend.
Please note that MS Word document is flow document and does not contain any information about its layout into lines and pages. Therefore, technically there is no “Page” and “Line” concept in Word document, our Spire.Doc product is based on MS Word specification, so it is impossible to remove empty pages.

Moreover, I checked your sample file and noticed the "empty page" you mentioned only has one row. So you could remove the three rows, then the "empty pages" will be removed.
Code: Select all
            Document doc = new Document(@"F:\UnitTestTemplate-success.docx");
            Table table = doc.Sections[0].Tables[0] as Table;
            int count = table.Rows.Count;
            //From the third row, delete these rows
            for (int i = 2; i < count;i++ )
            {
                //remove the rows
                table.Rows.RemoveAt(2);               
            }
            doc.SaveToFile("11239.docx", FileFormat.Docx);

If there is any question, please let me know.

Sincerely,
Betsy
E-iceblue support team
User avatar

Betsy.jiang
 
Posts: 3099
Joined: Tue Sep 06, 2016 8:30 am

Return to Spire.Doc