Daniel Koch
Daniel Koch

Reputation: 287

Get height of rendered text and images in MS Word

I'm creating a newspaper authoring system. Today I'm using Aspose.Words library to generate newspaper using Docx format as output, based on a lot of other documents as input.

The basic idea is to load a lot of articles documents into a List, then generate a final docx with newspaper.

We need to get the total height of a text (with images and tables) inside columns. As libraries like Aspose.Words deal with Docx format like DOM, there isn't way to know how text will be arranged inside columns. Then I can't know the real height.

We've worked in our own way to get this height. I'm using MeasureString() function from System.Drawing.Graphics namespace. It returns width and height used by string and I can estimate how many lines (and points or inches) it will use inside a column.

But it is very poor and we need a more decent solution. We are thinking to use OpenXML SDK to get this Height, can we?

Aspose.Words doesn't support a way to know it and all Render classes are private to the library.

Can you think a new way to get this height?

Thank you, Daniel Koch

Upvotes: 5

Views: 1977

Answers (3)

Daniel Koch
Daniel Koch

Reputation: 287

Thank all for answer.

I finished it changing Aspose.Words to PDFLib. Now I can control pages, columns or anything using Postscript Points.

We keep Aspose.Words only to content import, but it isn't indicate to print newsletter.

Upvotes: 0

Bruno Oliveira
Bruno Oliveira

Reputation: 1

I have almost the same problem that you have.. But in my case I'm dealing with Questions inside an Test Exam.. Well nowadays, we are using RTF to build the questions and a RichTextBox the measure the height.. Just like that (http://blogs.technet.com/david_bennett/archive/2005/04/06/403402.aspx).. And I wanna to migrate to DOCX.. But still no luck on how to measure the question with tables and images.. :-( Right now I'm studying the Document Members (http://msdn.microsoft.com/en-us/library/microsoft.office.interop.word._document_members.aspx), to try to do with Word Automation..

Regards,

Bruno

Upvotes: 0

Todd Main
Todd Main

Reputation: 29155

This property isn't exposed in Open XML or the SDK (or VBA/VSTO for that matter). How exactly the height is calculated is not in any documentation. Possibly the way you are doing it is a way to proceed.

Another possible way is to put your TextColumns in a Table Column/Cell and grab that height (but if it is two text columns in the cell and the first one "fills" the cell top to bottom and the second one doesn't, you'll still have the issue of not being able to calculate the size of the second one).

Upvotes: 1

Related Questions