Word Openxml: how to get a text box the right size? - textbox

I'm using PHP to generate docx documents from a database. The generated document contains column charts which have labels attached (i.e. user shapes containing textboxes). In an attempt to get the textboxes to accommodate and display all of the text (i.e. it shouldn't be necessary for the user to resize a textbox to see all the text) my code calculates how many characters will fit into 3cm, adds linefeeds to the string as required and tells me how many lines of text are needed. I have:
<a:xfrm xmlns:a="http://schemas.openxmlformats.org/drawingml/2006/main">
<a:off x="1638276" y="1676399"/>
<a:ext cx="1257325" cy="'.(252000 * $labelLeftLines).'"/>
</a:xfrm>
which I believe should give me a text box around 3.5cm wide (extra .5 for the internal padding) and a height of .7cm multiplied by whatever is the value of $labelLeftLines. However, the text box always turns up as 3.cm wide by .86cm high, which only ever displays one line of text.
If I add in 'autofit':
<a:bodyPr xmlns:a="http://schemas.openxmlformats.org/drawingml/2006/main" vertOverflow="clip" wrap="square" rtlCol="0">
<a:spAutoFit/>
</a:bodyPr>
the generated file looks just the same, though, when I right click on the textbox to inspect the properties, 'autofit' is indeed applied. I have to uncheck it and recheck it to make it affect the textbox.
Any openXML gurus out there?

Hmm, some random floundering around revealed that the values I need to manipulate are here:
<cdr:relSizeAnchor xmlns:cdr="http://schemas.openxmlformats.org/drawingml/2006/chartDrawing">
<cdr:from>
<cdr:x>0.47</cdr:x>
<cdr:y>0.75</cdr:y>
</cdr:from>
<cdr:to>
<cdr:x>0.67</cdr:x>
<cdr:y>1</cdr:y>
</cdr:to>
Changing those values does actually change the size of the texbox, though I haven't a clue what units are being used. From 0.75 to 1 produces a height of 1.43cm.
One day I'll maybe be able to find my way around the doucmentation.

Related

Convert text to image breaking the text down into multiple columns when it exceedes the defined dimensions

I have seen this thread, but I wish to convert, say poetry, into a wallpaper. (something more advanced I suppose)
Poetry is usually long, and in order to fit it in one wallpaper (fullHD), there should be some way to break it down into columns, creating a new column, once the height of the image was exceeded.
Is there a way to do this via ImageMagick?
Or should I edit the text manually, namely:
figure out the proper height of the text and how much fits in,
break down the text file into multiple text files where appropriate,
create an image using each of those text files taking into account the proper gap between columns.

Checking location of word range relative to the page

I am writing a vba macro that checks that word documents are formatted correctly to meet certain specifications. One of the things I have to check for are the left margins of each line - different paragraphs are supposed to have different first indents and hanging indents depending on the context. This should be as simple as checking the style, but unfortunately it is not - some of the documents use styles to change the indents, but others use manual spaces and tabs to position the text correctly. So I need some way to check the actual physical position of the first physical character in each Document.Paragraphs. I have no problem getting a range with the first visible character in the paragraph, but I'm not sure about getting the distance from the margin (or from the left side of the page - doesn't make a difference because the margins are consistent).
I found the Window.GetPoint method, but I'm nervous to use it, because that is based on the actual physical location on the screen. This macro is going to be used on different computers, with different versions of word, and I'm not sure about how it is affected by other view settings (like print layout, zoom, etc.) Is there a consistent way to use this method to determine the distance from the margin?
The other method would be (because all of the documents are in Courier New 12) to look at the firstindent property of the style, and the count manually all of the spaces and tabs (but that would need to take into account tabstops). This I'm also not sure how to do.
I would think that there should be a much simpler way of doing this, but I can't find it, so if anyone has any suggestions I would really appreciate any help.
It was there after all! Range.Information(wdHorizontalPositionRelativeToPage)

When programatically creating a report, how can I scale it so that all data fits?

Description of Application:
I have an application that allows a user to output a report to a document. The data that is written to the document is in the form of a table. The number of columns in the table and the width of the strings contained in each cell in the table are unknown until runtime (it depends on what query the user runs, what they want to see in the report etc.).
I'm using Delphi XE and Gnostice's eDocEngine to create a PDF document, and then creating a table in the document and writing the report data into it.
Problem:
The problem that I'm having is that you can only write a certain number of columns (6 or 7) into the document before they disappear off the right hand side of the document. It isn't unknown for a user to produce a report with 30 or 40 columns in the table (as they correspond to fields in a database, which they run a query over), so I need to be able to get the table to fit entirely into the document, no matter how many columns it contains.
As a PDF can be zoomed, I suppose I could shrink the font size and column widths down and fit everything in that way, as the user could then zoom in and scroll around the table using their PDF reader. What I need to know is:
Is there a better way of getting the entire table to fit onto a page?
If shrinking/zooming is the best/only way of doing this, what is the most efficient way of ensuring that everything fits without making the document look strange (i.e. the table should ideally stretch across the page, rather than be bunched up to the left hand side because of some random scaling algorithm).
Edit
I've just done some more digging around and I've found "inputXRes" and "inputYRes" properties that change the scale of the canvas in the document, which looks promising, but I can't get it to work properly at the moment. Can anyone shed any light on how those properties are used? The text itself is scaling, but the size of the table stays the same, meaning that I've now got a tiny piece of text in the middle of a huge table cell, and the table is still only displaying 7 columns in the report.
Don't mess with scaling and font size.
Your customers will use PDF Reader and there are some options that will help to read the informations e.g. 1:1. But when you change the scaling or font size you cannot read the information, because it is too small.
Get a font size that fits perfect the needs of your customers and extend the page size to fit the table size.
With PDF Reader your customers will have the choice to view and print (shrink to fit) as they like and which paper size their print can handle.
BTW:
If you change the resolution and draw a line with a length of 2 inch on the canvas it will be 2 inch long, but a text with font size 12 (pixels) will grow or shrink.

How to set space between lines in a rdlc textbox

How can we set the space between lines in an rdlc textbox?
Scenario:
The application shall be printing a report to a pre-printed stationary sheet.
One string field of the report is usually having about 400 characters of data (description input by user), which shall be printed in multiple lines.
As a workaround to the problem of not able to set LineHeight property of textbox control in rdlc, I have written a custom code which will insert new line characters into the string (by adding Environment.NewLine) such that the string is splitted into multiple lines. However, I am not able to set the space between each line in the text box. I have tried setting both SpaceAfter and SpaceBefore property. No change :-(
I also tried using VbCrLf and combination of Chr(10) and Chr(13) instead of Environment.NewLine. Did not help... Can you help!!!
I am using VS2010 Premium Edition and Application Target of 4.0 framework.
I added new textboxes for each lines to my report and set position for them with necessary line spacing.
because Line spacing in textbox properties is not applied.
This is how I do it. (It works only between paragraphs, not within a single paragraph where the lines wrap.) Say the font is 12 pt, and I want a little space between paragraphs, but not full double-spacing. I put the extra line between paragraphs, and then I select that empty line and set the font to 6 pt. If I wanted 1.5 spacing, I'd set it to a larger font.

How to fully justify texts programmatically (Delphi)?

How can I fully justify a block of text (like MS Word does, not only on the right and not only on the left but on both sides)?
I want to justify some texts (mainly arabic text) adjusted to certain screen size (some handheld device screen actually, and its text viewer doesn't have this function) and save this text as justified. So I can reload and reuse it again elsewhere.
(The problem with MS word is, that if you copy the justified text from MS Word and paste it to another editor it'll copy it un-justified).
Update : for now I'm thinking of doing it like this:
get-a-word
get-word-width
add-word-to-total-Word and add-Word-width-to-total-word-width
check if total-Word-width = myscreen-width then continue
else if total-Word-width is between myscree-wdith and (myscreen-width -3) then
add-spaces-To-total-word until it = myscreen-width
This is what I'm thinking now, but I put this question up and hope to see if there is a better solution, or somebody else already implemented it.
PS: I hope I have made my question clear and I'm sorry for bad expression if there is.
edit1 : changed the title to make it more clear.
If you want to justify plain text, you can only add extra spaces to the lines to get them align on the left and right. Unfortunately the character widths differ in fonts; so doing it this way will only work for a certain font, unless you limit yourself to monospaced fonts where all characters have the same size.
If you want a result like in Word, adding spaces won't cut it. Word will not add spaces, but stretch and shrink the existing spaces. This information is lost when you copy and paste it into another app.
Either way, justifying is an optimization problem. If you are interested in a good solution and its implementation: have a look a TeX. For an implementation that works on plain text with monospaced fonts have a look at par
There are some API calls that may help:
ExtTextOut and GetCharacterPlacement
Look at the GCP_JUSTIFY flag for GetCharacterPlacement
ExtTextOut is used by Canvas.TextRect
The problem you are going to face is always going to be differences in the rendering of the font. Word handles full justification by adjusting kerning as well as adjusting the number of pixels between words by a few (either way). The end result is lined up both margins. This pixel adjustment is done BOTH ways, and as evenly as possible.
To properly handle this in your portable device you will have to also perform the same algorithm for the display of the text there.
If this is not possible, then the ONLY way you can even get somewhat close would be to add whitespace between words.
As has been pointed out in other answers Word does full justification by stretching the existing spaces often by very small amounts. This is only possible if you have full control over how your text is drawn on the screen (which word - or any other windows program has).
You only real option in this regard would be to implement your own text viewer on the platform you are targeting. Eg you would need to draw the text on the screen yourself (any platform that allows games should allow you to draw on the screen). However this seems like an awful lot of trouble to get justified text.
Sorry couldn't be of more help.

Resources