RelativeVerticalPosition is not working as expected


#1

Hello.
I need to setup relative(in percent 96%) vertical position for the Shape inside the footer.
And I use this code:

// Insert a shape that contains a TextBox
Shape textBoxShape = documentBuilder.insertShape(ShapeType.TEXT_BOX,
RelativeHorizontalPosition.LEFT_MARGIN, 30,
RelativeVerticalPosition.PAGE, 96,
540.0, 100.0,
WrapType.NONE);
textBoxShape.setWrapType(WrapType.NONE);
textBoxShape.setStroked(false);
textBoxShape.setFilled(false);

I expect that it will look like:expected.jpg (122.8 KB)

But in fact an absolute position is set. Please, help.
Screenshot_1.jpg (135.2 KB)


#2

@AWD,

We have logged your problem in our issue tracking system. Your ticket number is WORDSNET-19229. We will further look into the details of this problem and will keep you updated on the status of the linked issue. We apologize for any inconvenience.


#3

@AWD,

Regarding WORDSNET-19229, please check if the following solution is acceptable for you?

DocumentBuilder documentBuilder = new DocumentBuilder(doc);

double textBoxHeight = 100.0;
double textBoxWidth = 540.0;

// Insert a shape that contains a TextBox
Shape textBoxShape = documentBuilder.InsertShape(ShapeType.TextBox, 
    RelativeHorizontalPosition.LeftMargin, 30,
    RelativeVerticalPosition.Page, (doc.FirstSection.PageSetup.PageHeight-(textBoxHeight / 2)),
    textBoxWidth, textBoxHeight,
WrapType.None);
textBoxShape.WrapType = WrapType.None;
textBoxShape.Stroked = true;
textBoxShape.Filled = false;

#4

Hi, awais.hafeez. Thanks for your reply.

I’m not sure that this is acceptable because if the document will contain both of landscape and portrait orientation pages, then absolute position will not work as expected for both page orientation options (I insert a Shape into the footer which is the same for all pages, but pages have different orientations)

I think only the relative position in% is a suitable solution.


#5

@AWD,

We have logged your concern in our issue tracking system and will keep you posted on any further updates.


#6

@AWD,

In the meantime while you are waiting for a fix, I think, you can build logic on the following code to get the desired output.

Document doc = new Document();
DocumentBuilder documentBuilder = new DocumentBuilder(doc);

documentBuilder.Writeln("Portrait Section");
documentBuilder.InsertBreak(BreakType.SectionBreakNewPage);
documentBuilder.PageSetup.Orientation = Orientation.Landscape;
documentBuilder.Writeln("Landscape Section");

foreach (Section sec in doc.Sections)
{
    documentBuilder.MoveTo(sec.Body.FirstParagraph);

    double textBoxHeight = 100.0;
    double textBoxWidth = 540.0;

    // Insert a shape that contains a TextBox
    Shape textBoxShape = documentBuilder.InsertShape(ShapeType.TextBox,
        RelativeHorizontalPosition.LeftMargin, 30,
        RelativeVerticalPosition.Page, (sec.PageSetup.PageHeight - (textBoxHeight / 2)),
        textBoxWidth, textBoxHeight,
    WrapType.None);

    textBoxShape.WrapType = WrapType.None;
    textBoxShape.Stroked = true;
    textBoxShape.Filled = false;
}

doc.Save("E:\\temp\\19.9.docx");

#7

Thanks for the help!