We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Vertical Position Relative To Page

I’m trying to programmatically set the vertical position of the “return” and “to” address blocks in a document.

I have a unique bookmark set at the beginning of each block. I need to be able to determine the vertical position relative to the top of the page. In MS Word VBA I would use Selection.Information(wdVerticalPositionRelativeToPage).

<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

Once I know the vertical position, I can adjust the points before the paragraphs in order to align the addresses in a double windowed envelope.

Is there an equivalent method in Words 8.1.0?

Hi,

<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

Thanks for your request. MS Word document is flow document and does not contain any information about its layout into lines and pages. So there is no way to determine on which page and where on the page some particular node is located.

In Aspose.Words we use our own Rendering Engine, which layouts Word document into pages. Using this Rendering Engine it is possible to determine position of the particular node. But currently there is no public API to achieve this.

Could you please attach your input and expected output document here? I will investigate them and provide you more information. Maybe there is the easier way to achieve what you need.

Best regards.

Ok, let me take a different approach and explain the problem at a higher level. We are in the process of switching our entire document fulfillment printing from MS Word to Words. We have over 500 different letters we merge on a daily basis. The envelope used for the document depends on the document and attachments printed. Different envelops have different positions for their windows. We have to be able to position the return address block and the address block base on the document printed and the envelop used for that letter. We currently do this in MS-Word VBA by call the function below.

How would you suggest we position a merge field block exactly 6.2 centimeters from the top of the page during one print and 5.8 centimeter from the top on the next print?

Sub SetWindowPostionOfAddressBlock(HeightToSetInCentimeters As Single)
If ActiveDocument.Bookmarks.Exists("AddressBlock") = True Then
Selection.GoTo What:=wdGoToBookmark, Name:="AddressBlock"
Else
GoTo EndNow
End If
Dim SpaceBeforeAddressBlockParagraph
Dim ContinueLoop As Boolean
Dim CurrentHeight As Single
' Determine the direction. Does the address block need to move up or down?
ContinueLoop = True
CurrentHeight = PointsToCentimeters(Selection.Information(wdVerticalPositionRelativeToPage))

If CurrentHeight >= HeightToSetInCentimeters Then
' Reduce the current height
Do While (ContinueLoop)
CurrentHeight = PointsToCentimeters(Selection.Information(wdVerticalPositionRelativeToPage))
SpaceBeforeAddressBlockParagraph = Selection.ParagraphFormat.SpaceBefore
If SpaceBeforeAddressBlockParagraph = 0 Then
' The space above the address block can not be decreased any further, so exit.
Exit Do
End If
If CurrentHeight >= HeightToSetInCentimeters Then
Selection.ParagraphFormat.SpaceBefore = SpaceBeforeAddressBlockParagraph - 1
Else
ContinueLoop = False
End If
Loop
Else
' Increase the current height
Do While (ContinueLoop)
CurrentHeight = PointsToCentimeters(Selection.Information(wdVerticalPositionRelativeToPage))
SpaceBeforeAddressBlockParagraph = Selection.ParagraphFormat.SpaceBefore

If CurrentHeight <= HeightToSetInCentimeters Then
Selection.ParagraphFormat.SpaceBefore = SpaceBeforeAddressBlockParagraph + 1
Else
ContinueLoop = False
End If
Loop
End If
EndNow:
End Sub

Hi

<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

Thank you for additional information. Maybe in your case you can try using textbox as an address block. You can specify position of textbox relative to page. For instance see the following code:

// Create or open document.

Document doc = new Document();

// Create address bloch shape.

Shape addressBlock = GetAddressBlock(doc, 100, 400, "This is my address block");

// Insert addressbloch into the document.

doc.FirstSection.Body.FirstParagraph.AppendChild(addressBlock);

// Save output document.

doc.Save(@"Test001\out.doc");

==============================================================================

private Shape GetAddressBlock(Document doc, double top, double left, string text)

{

// Create new textbox.

Shape addressBlock = new Shape(doc, ShapeType.TextBox);

// Specify size.

addressBlock.Width = 100;

addressBlock.Height = 100;

// Set position.

addressBlock.WrapType = WrapType.None;

addressBlock.RelativeHorizontalPosition = RelativeHorizontalPosition.Page;

addressBlock.RelativeVerticalPosition = RelativeVerticalPosition.Page;

addressBlock.Top = top;

addressBlock.Left = left;

// Create paragraph, which will represent text of the textbox.

Paragraph paragraph = new Paragraph(doc);

Run run = new Run(doc, text);

paragraph.AppendChild(run);

addressBlock.AppendChild(paragraph);

return addressBlock;

}

Hope this could help you.

Best regards.

The issues you have found earlier (filed as WORDSNET-2978) have been fixed in this .NET update and this Java update.


This message was posted using Notification2Forum from Downloads module by aspose.notifier.
(79)