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 Mar 17, 2017 10:08 pm

Hi,
I'd like to create an anchored TextBox that stays at the bottom of the last page. I can accomplish this using Word by inserting a TextBox and setting the layout options as seen in the attached LayoutOptions.png. Also attached is an example Word document showing the functionality I'm looking for.
Is there a way I can accomplish this using Spire?
Thanks,
Mark

markeye3
 
Posts: 27
Joined: Wed Jul 29, 2015 5:59 pm

Mon Mar 20, 2017 9:51 am

Hello Mark,

Thanks for your inquiry and sorry for the late reply as weekend.
Concerning your need, here is the sample code for your kind reference:
Code: Select all
Document doc = new Spire.Doc.Document();
            Spire.Doc.Section section = doc.AddSection();
            Spire.Doc.Documents.Paragraph p = section.AddParagraph();
            p.Text = "The below textbox at the should stay at the bottom of the last page.";
            Spire.Doc.Fields.TextBox tb= p.AppendTextBox(400, 30);
            tb.Body.AddParagraph().Text = "The below textbox at the should stay at the bottom of the last page.";
            tb.Format.HorizontalAlignment = ShapeHorizontalAlignment.Center;
            tb.Format.VerticalAlignment = ShapeVerticalAlignment.Bottom;
            //give a certain position
            //tb.Format.VerticalPosition = 700;
            //tb.Format.HorizontalPosition = 50;
            tb.Format.HorizontalOrigin = Spire.Doc.Documents.HorizontalOrigin.Margin;
            tb.Format.VerticalOrigin = Spire.Doc.Documents.VerticalOrigin.Page;
            tb.Format.TextWrappingType=Spire.Doc.Documents.TextWrappingType.Both;
            tb.Format.TextWrappingStyle=Spire.Doc.Documents.TextWrappingStyle.Square;
            doc.SaveToFile("result.docx");

If there's still any doubt, please do not hesitate to contact us.

Sincerely,
Jane
E-iceblue support team
User avatar

Jane.Bai
 
Posts: 1156
Joined: Tue Nov 29, 2016 1:47 am

Mon Mar 20, 2017 2:47 pm

Hi Jane,
Thanks for the reply.
I had gotten the TextBox created working well in the Docx, the only problem now is doesn't export to Pdf quite right. I believe one of the issues maybe related to the use of IsFitShapeToText.
Here is my code:
Code: Select all
using (Document doc = new Document())
         {
            doc.CreateMinialDocument();
            Section section = doc.Sections[0];
            Paragraph paragraph = section.Paragraphs[0];
            paragraph.AppendText("The below textbox at the should stay at the bottom of the last page.");
            paragraph = section.AddParagraph();
            TextBox tb = paragraph.AppendTextBox(section.PageSetup.ClientWidth, section.PageSetup.ClientHeight);
            paragraph = tb.Body.AddParagraph();
            paragraph.AppendText("This textbox at the should stay at the bottom of the last page. This textbox at the should stay at the bottom of the last page. This textbox at the should stay at the bottom of the last page. This textbox at the should stay at the bottom of the last page.");
            tb.Format.IsFitShapeToText = true;
            tb.Format.TextWrappingStyle = TextWrappingStyle.Square;
            tb.Format.TextWrappingType = TextWrappingType.Both;
            tb.Format.HorizontalAlignment = ShapeHorizontalAlignment.Center;
            tb.Format.HorizontalOrigin = HorizontalOrigin.Column;
            tb.Format.VerticalAlignment = ShapeVerticalAlignment.Bottom;
            tb.Format.VerticalOrigin = VerticalOrigin.Margin;
            doc.SaveToFile(Path.Combine(Path.GetTempPath(), "TextBoxTest.docx"), FileFormat.Docx2013);
            ToPdfParameterList toPdf = new ToPdfParameterList() { CreateWordBookmarks = true };
            doc.SaveToFile(Path.Combine(Path.GetTempPath(), "TextBoxTest.pdf"), toPdf);
         }


Thanks,
Mark

markeye3
 
Posts: 27
Joined: Wed Jul 29, 2015 5:59 pm

Tue Mar 21, 2017 1:56 am

Hello Mark,

Thanks for your feedback.
I have reproduced the issue on my side and referred it to our Dev team for investigation and update. When it is fixed, I will inform you at once.
So sorry for the inconvenience caused.


Sincerely,
Jane
E-iceblue support team
User avatar

Jane.Bai
 
Posts: 1156
Joined: Tue Nov 29, 2016 1:47 am

Fri Apr 21, 2017 6:48 am

Hi Mark,

Glad to inform that your issue has been resolved and the hotfix(Spire.Office Platinum (Hot Fix) Version:2.15.8) is available now, please download and have a test.
Welcome to post if there's any doubt or issue.

Sincerely,
Jane
E-iceblue support team
User avatar

Jane.Bai
 
Posts: 1156
Joined: Tue Nov 29, 2016 1:47 am

Fri Apr 21, 2017 3:24 pm

Hi Jane,
Seems to be working now.
Thanks,
Mark

markeye3
 
Posts: 27
Joined: Wed Jul 29, 2015 5:59 pm

Mon Apr 24, 2017 2:00 am

Hello Mark,

Thanks for your feedback.
Welcome to post if you need any help!

Sincerely,
Jane
E-iceblue support team
User avatar

Jane.Bai
 
Posts: 1156
Joined: Tue Nov 29, 2016 1:47 am

Return to Spire.Doc