Paragraph's size

A

Andrey Dzizenko

Hi all!

Could anyone please explain me how can I get a Word paragraph's height and
width?

Thank you in advance,
A. Dzizenko.
 
C

Cindy M -WordMVP-

Hi Andrey,
Could anyone please explain me how can I get a Word paragraph's height and
width?
Mmmm. The only thing, really, would be the Information property of the
Selection and Range objects. Your code would have to position the cursor in the
first line, the last line, at the far left, and at the far right of a paragraph
and get the wdVertical / wdHorinzontal positions, and do some calculations. The
worst part would be getting the right-most position if the text is not "full
justified", as each line could be a different length.

Unless calculating the width between the left and right margins would be enough
for the paragraph width?

Cindy Meister
INTER-Solutions, Switzerland
http://homepage.swissonline.ch/cindymeister (last update Jun 8 2004)
http://www.word.mvps.org

This reply is posted in the Newsgroup; please post any follow question or reply
in the newsgroup and not by e-mail :)
 
A

Andrey Dzizenko

I've found it :)

In Office 2003 object model a new property EnhMetaFileBits appears.

byte[] emfData = (byte[])paragraph.Range.EnhMetaFileBits;
System.IO.MemoryStream ms = new System.IO.MemoryStream(emfData);
Metafile picture = new Metafile(ms);

Then we can use Height and Width properties of Metafile-object.

Best regards,
A. Dzizenko.
 
C

Cindy M -WordMVP-

Hi Andrey,

New one on me, but then according to the Help it's meant for use with
Windows API or NET tools. Glad you found that, and came back and let
us know :)!
I've found it :)

In Office 2003 object model a new property EnhMetaFileBits appears.

byte[] emfData = (byte[])paragraph.Range.EnhMetaFileBits;
System.IO.MemoryStream ms = new System.IO.MemoryStream(emfData);
Metafile picture = new Metafile(ms);

Then we can use Height and Width properties of Metafile-object.

Cindy Meister
INTER-Solutions, Switzerland
http://homepage.swissonline.ch/cindymeister (last update Jun 8 2004)
http://www.word.mvps.org

This reply is posted in the Newsgroup; please post any follow
question or reply in the newsgroup and not by e-mail :)
 
A

Andrey Dzizenko

Hi!

I use .NET 2005 with Visual Studio Tools for Office, but I think that's
not the case.
I'm not sure what about using streams in VBA, I sure that EnhMetaFileBits
is accessible not only in .NET Framework.
ThisDocument.Paragraphs(i).Range.EnhMetaFileBits "returns a Variant that
represents a picture representation of how a selection or range of text
appears" according to the VBA-help. So I can conclude that it's means for
use not only with API or .NET tools.

Best regards,
A. Dzizenko.



Hi Andrey,

New one on me, but then according to the Help it's meant for use with
Windows API or NET tools. Glad you found that, and came back and let
us know :)!
I've found it :)

In Office 2003 object model a new property EnhMetaFileBits appears.

byte[] emfData = (byte[])paragraph.Range.EnhMetaFileBits;
System.IO.MemoryStream ms = new System.IO.MemoryStream(emfData);
Metafile picture = new Metafile(ms);

Then we can use Height and Width properties of Metafile-object.

Cindy Meister
INTER-Solutions, Switzerland
http://homepage.swissonline.ch/cindymeister (last update Jun 8 2004)


This reply is posted in the Newsgroup; please post any follow
question or reply in the newsgroup and not by e-mail :)
 
C

Cindy M -WordMVP-

Hi Andrey,
ThisDocument.Paragraphs(i).Range.EnhMetaFileBits "returns a Variant that
represents a picture representation of how a selection or range of text
appears" according to the VBA-help. So I can conclude that it's means for
use not only with API or .NET tools.
Yes, but one needs to use the Windows API or similar in order to DO anything
with what the property returns (that also stands in the Help you quoted).

Cindy Meister
INTER-Solutions, Switzerland
http://homepage.swissonline.ch/cindymeister (last update Jun 8 2004)
http://www.word.mvps.org

This reply is posted in the Newsgroup; please post any follow question or
reply in the newsgroup and not by e-mail :)
 
A

Andrey Dzizenko

I'm upset.

EnhMetaFileBits returns page width. It's strange why
ActiveDocument.Paragraph(1).Range.EnhMetaFileBits' width and
ActiveDocument.Paragraph(1).Word(1).EnhMetaFileBits' width are the same,
but it's so.

On top of that, if there's a picture, all ranges (Paragraph, Sentence,
Word and even Character) contain this picture. But I'd like to know text
width. With no pictures.

So I can say that using margins is also helpless.

As I see the one solution is to calculate text width manually.
Of course, I would know more stylish solution.

Best regards,
A. Dzizenko.
 
C

Cindy M -WordMVP-

Hi Andrey,
I'm upset.

EnhMetaFileBits returns page width. It's strange why
ActiveDocument.Paragraph(1).Range.EnhMetaFileBits' width and
ActiveDocument.Paragraph(1).Word(1).EnhMetaFileBits' width are the same,
but it's so.

On top of that, if there's a picture, all ranges (Paragraph, Sentence,
Word and even Character) contain this picture. But I'd like to know text
width. With no pictures.
Hmmm. If you don't want the text "as it appears" in the
document, to what purpose do you need to "measure" the text?
Wouldn't it make more sense to simply count the number of
characters a range contains?
As I see the one solution is to calculate text width manually.
Of course, I would know more stylish solution.
Yes, that's what I said, originally :) (But I'm still very glad
to have learned about the EnhMetaFielBits method.)

Cindy Meister
INTER-Solutions, Switzerland
http://homepage.swissonline.ch/cindymeister (last update Jun 8
2004)
http://www.word.mvps.org

This reply is posted in the Newsgroup; please post any follow
question or reply in the newsgroup and not by e-mail :)
 
A

Andrey Dzizenko

Hi!

Calculating text parameters manually has some problems.
I should know if the text is multiline. And I have no guarantees that the
first line is not larger than the second one. This method will be not so
light and quick.

After several days of using EnhMetaFileBits I can say the following.
This method returns an object, which represents an array of bytes.
Essentially it's 8-bit representation of area. You can use it as array of
bytes, .NET streams can work with these arrays.
The area is strange. Its height equals Range width, its width always
equals page width.
Also I've noticed that if a bit has no information it equals "0". When
converting to image, "0" become black color. Up till now I don't know what
to do with that.

To my mind EnhMetaFileBits is unfinished method, it's a good idea with no
good realization.

Give me a sign if you want to know something concrete.

Best regards,
A. Dzizenko.
 
C

Cindy M -WordMVP-

Hi Andrey,
After several days of using EnhMetaFileBits I can say the following.
This method returns an object, which represents an array of bytes.
Essentially it's 8-bit representation of area. You can use it as array of
bytes, .NET streams can work with these arrays.
The area is strange. Its height equals Range width, its width always
equals page width.
Also I've noticed that if a bit has no information it equals "0". When
converting to image, "0" become black color. Up till now I don't know what
to do with that.

To my mind EnhMetaFileBits is unfinished method, it's a good idea with no
good realization.
Thank you for the information you've gleaned from experimenting with the
method. It sounds as if this method is using a similar principle as when
inserting a frame around selected text (select the text, then "Insert frame"
from the Forms toolbar). That also includes the entire width between the
margins.

In another group, a colleague showed a method to "stream" the data to a file,
using ADODB. I tried that on a selected graphic, and the result was just the
graphic (InlineShape object). So, to that extent, it does work to extract
graphical objects from a document.

Cindy Meister
INTER-Solutions, Switzerland
http://homepage.swissonline.ch/cindymeister (last update Jun 8 2004)
http://www.word.mvps.org

This reply is posted in the Newsgroup; please post any follow question or reply
in the newsgroup and not by e-mail :)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top