Get text fitting into box using ColumnText - coldfusion

I am using iText library in a ColdFusion application for creating PDFs and the goal is to add various texts into box of certain size at certain position.
It can be perfectly done using ColumnText (details skipped):
<cfset directContent = writer.getDirectContent()>
<cfset ct = CreateObject("java", "com.lowagie.text.pdf.ColumnText").init(directContent)>
<cfset ct.setSimpleColumn(100, 50, 400, 400, 18, Element.ALIGN_JUSTIFIED)>
<cfset ct.setText( createObject("java", "com.lowagie.text.Phrase").init("#text_var#") ) >
<cfset ct.go()>
The problem is: long texts are cut, as expected (go() returns ColumnText.NO_MORE_COLUMN).
But I need in this case to show that text is not finished by putting for example '...' in the end (adding dots or if needed replacing one or two last symbols with '...').
Is there a simple way to achieve this? For example, after I call go(true) - I can see number of lines used to output the text without actually outputting it. But I need somehow to get actual text fitting into box.

You're using a mighty old version of iText, and I don't know if what I'm about to answer is supported in the packages that were named after me.
Q1: I want to add ... in the end.
A1: if go() returns NO_MORE_COLUMN, you can get the X position of the last X position of the last line that has been written. See http://api.itextpdf.com/itext/com/itextpdf/text/pdf/ColumnText.html#getLastX%28%29
You can get the Y position with getYLine. See http://api.itextpdf.com/itext/com/itextpdf/text/pdf/ColumnText.html#getYLine%28%29
You could use this X and Y to add '...' at the appropriate place.
Q2: I don't want the text to be cut; I want to fit the text inside a Rectangle.
A2: that's exactly what is done in this example: http://itextpdf.com/examples/iia.php?id=163
In the method addParagraph(), text is added in simulation mode to see if it fits. If it does, the text is added for real; if it doesn't the text is added again, but using a smaller font.

Related

Adding new lines and spaces to the old Qt PieMenu

I need to use the old Qt pieMenu, I know it's deprecated, But I've found the source code here, and the installations instructions here(they are in the zip file as well)
I've successfully compiled and ran the examples, but my problem is that I need to add spaces and manipulate the font in the text of the pie menu
for example in the editor.cpp example, these lines insert items to the pie menu with the first parameter as the displayed text :
markMenu->insertItem("Cut", this, SLOT(cut()));
markMenu->insertItem("Del", this, SLOT(del()));
markMenu->insertItem("Copy", this, SLOT(copy()));
I tried setting the lines like this as a test :
markMenu->insertItem("item cut", this, SLOT(cut()));
markMenu->insertItem(tr("Del item"), this, SLOT(del()));
markMenu->insertItem("test on item", this, SLOT(copy()));
and the results are like in the photo(everything after the space character is not displayed)
then I used the '\t' instead of using space directly, it worked as one space instead of a tab.
markMenu->insertItem("test\ton\titem", this, SLOT(copy()));
but when trying to add a new line to the text things didn't work right.
I tried using '\n' but didn't work for me.
Another issue, I was trying to change the font settings of the menu, I tried :
markMenu->setFont(QFont("Arial", 9, 5, true)); // size 9, weight 5, italic
but this didn't affect the font, I tried styleSheets as well but no success.
Any ideas how can I display the new liens and adjust the font of the text?
In the link provided by OP, scrolling to bottom, the source code can be found:
painter.drawText(center.x() + x
- metrics.width(itemText(i)) / 2,
center.y() + y, itemText(i));
Now, a look into the Qt doc. of QPainter::drawText() provides the explanation:
This function does not handle the newline character (\n), as it cannot break text into multiple lines, and it cannot display the newline character. Use the QPainter::drawText() overload that takes a rectangle instead if you want to draw multiple lines of text with the newline character, or if you want the text to be wrapped.
...and a possible fix as well. (Emphasize by me.)
As the source code is available, this can be fixed.
To achieve a proper pre-calculation of boundary rectangle, QFontMetrics can be used.
The answer to How to automatically increase/decrease text size in label in Qt shows an example for text boundary determining with QFontMetrics which even considers automatic word-wrapping.

Change text in aepx file programmatically

I am trying to develop an API using PHP, Which will receive Text from user as Input.
I need to change text inside the aepx file. On my research I found <string> tag and <ldata> contains text value and corresponding its hexadecimal value respectively.
I am able to parse and replace text of <string> tags in aepx.
I am also able to change the hexadecimal values of bdata attribute of <ldata>.
But after all the changes I have made, it is not rendering(tried to run using aerender command). Also After Effect Application(latest -cc 2018) is crashing while opening changed aepx file.
Example:
Original
<ldta bdata="0000000c00020000000000010000000000005da80000000000005da8000afc8000005da80000008700 0000000000000000000000000000000000000100010000506c616365686f6c6465722074657874000000000000 000000000000000000000000000200000000000000000000000100000000000000000000000000000000000000 0300000000000000000000000000000000000000000000000000000000"/>
<string>Placeholder text</string>
After Change
<ldta bdata="0000000c00020000000000010000000000005da80000000000005da8000afc8000005da80000008700 000000000000000000000000000000000000010001000048656C6C6F20576F726C642100000000000000000000 000000000000000000020000000000000000000000010000000000000000000000000000000000000003000000 00000000000000000000000000000000000000000000000000"/>
<string>Hello World!</string>
You can do this using After Effects Expressions. Following are the steps which worked for me:
Open the project in AfterEffects
Go to Text layer you wish to modify
Click arrow icon which shows a sub section with a stopwatch icon and the text "Source Text"
ALT + click the stopwatch icon, you will see another section underneath it with text "Expression Source Text"
Give its value as "thisLayer.name"
Click File > Save as > Save as xml
This will create you a aepx file.
Open aepx file in any text editor and search for the text you wish to modify. Confirm that it looks like in the attached sample aepx image. The following is the expression line "thisLayer.name" that we created through AfterEffects in above steps.
Now change the text "This is the text to be changed" to whatever you wish,
Render and check. If all ok then it must be changed.
Attached images:
After Effects steps to setup expression
Sample aepx glimpse.
Consider: Placeholder text has 16 characters (since also counting the space char).
Make sure your new input text is same length as Placeholder text length in total characters (you can use spaces to increase length, where needed for shorter text).
The easiest fix is to:
Make Placeholder text have max expected length, (example: 30 chars), so in AE you create a textfield and press space 30 times (or make 10 spaces then copy these 10 blank chars and re-paste them another 2 times).
Your PHP API should check the input text length and if below 30 chars, fill remainder with space " " maybe using a For loop. If input is above the 30 limit, then trim down to first 30 chars and ignore the rest.
The final string should be same length as the text-field you made in A.E. Your API can now safely place the final text into your AEPX file.

TextWrangler: line-number in a replace string

I'm looking for the best way to search all the occurrences of a string and replace them with something related to the line number.
For example, line 857 must become:
z-index: 96;
where 96 = (linenumber +7) / 9.
And line 848 must become:
z-index: 95;
where 95 = (linenumber +7) / 9.
sample screenshot of my document
If you are willing to switch half way through to some kind of spreadsheet application, please, read on.
Using TextWrangler (4.5.11) with grep enabled for searches:
Start adding line numbers using TextWrangler's -> Text -> Add/Remove line numbers.
Search for ^[[:digit:]]+ (?!z-index)(.*)$ and replace with \t\1.
Search for ^([[:digit:]]+) and replace with =(\1+7)/9\t.
Mark everything and copy.
Sorry - no clue, how to calculate inside TextWrangler. Thus:
Paste into some spreadsheet application. (Did test with Google table and Excel. Might need to adjust formula if other software is being used.)
Wait for the formulas to be calculated.
Mark everything and copy.
Go back to TextWrangler. Paste replacing original selection.
Verify the calculations' result to persist.
Search for ^([[:digit:]]+)\t(\s+z-index: )0; and replace with \2\1.
Verify the file's content (and provide more detail if necessary to address the problem in full; significant chunk of data would facilitate proper testing…).

long text printed on screen creating a horizontal line and going of of bounds while printing

I am working on textarea where the user can enter text to create the letter. now if they keep typing continuously, it creates a lengthy string and once they save it in database, the same letter is available for print. Now while printing, it shows a very long horizontal bar. While printing, text is being cut off
I tried using the WRAP function of Function, but that creates extra Tags where they are not needed, Although in letter, there are couple of instances where they are needed. using the Following Code replaces all &NBSP;.
#Wrap(qryGetLetterDetails.letter,'([[:print:]])( )([[:print:]])','\1 \3','all'),75)#
My Next Approach was using the Custom Lib Function WRAP available on CFLIB.org
Again with this Tag, it generated the source HTML on screen while wrapping the Letter. It did not worked as expected.
I tried searching CSS ways to force to break word but in vain. I am using IE7+ versions only, No other Browser Support is provided.
can you try with
#ReplaceList(qryGetLetterDetails.letter, "#chr(10)#,#chr(13)#", "<br />")#

How to prevent OpenOffice/LibreOffice Calc from changing what you input (data, numbers,...)

Basically, I want LibreOffice Calc to do what I tell it, not what it wants.
For example:
when I input 1.1.12, I want to have 1.1.12 in that cell, not 01.01.2012 or whatever.
when I input 001, I want to have 001 in that cell, not 1
and so on and so forth
I want it to never ever touch my data until I explicitly tell it to. Is that possible at all?
I know I can set format of a cell to text. It doesn't help at all. Example:
Input 1.1.12, it gets displayed as 01.01.12, format as text, it becomes "40909", original input is lost
Format empty cells as text. Paste "000 001 002 ..." separated by line breaks. Displays "0 1 2 ..."
I know I can write ' in front of anything for it to be forced text. Again it doesn't help, because when I paste in text, I cannot have ' auto-appended to it.
I hope this is possible. I tried googling for different problems and never found a good answer.
If you want your input to be interpreted as text and preventing Calc to do fancy (and annoying) things with your input, you have to change the format before entering any value.
Select the cells/columns/rows.
Right-click 'Format Cells...'
Select the tab 'Numbers'
In the list 'Category', select 'Text' (the last option)
Select the format '#' (it is the only one in this category)
Click on 'Ok'
You may need to tweak the 'autocorrect' options as well. Go to 'Tools > Auotcorrect Options...'. Here is a link that may help: https://help.libreoffice.org/Calc/Deactivating_Automatic_Changes
I understand your problem with pasting pure unformatted text. This may be more work than you like (we can try to automate that later) but when I paste data from Notepad, I am prompted with an import screen as you can see below. Select the column header(s) and then select Column type: Text. This should solve your paste/import problem. An alternative is to handle this with an AutoHotKey script.
Oh b.t.w. the # is the format type for text, just like you have HH for 24 hour or ddd for weekdays...
When you are importing, you're given a bunch of options. Select "Quoted field as text" so any text inside quotes is treated as text which is interpreted by LibreOffice as sacred and they do not modify it in the way they they modify something that they identify as number
When you have your data in the clipboard click Edit -> Paste as... in main menu. In next window choose "Paste as text". All your data will be pasted as is.
I initially arrived at this page with a very similar (but not identical) problem. I am posting the solution here for the benefit of those who might be visiting with the same issue.
Every time I would save, close, and then re-open my .XSLX spreadsheet in OpenOffice, it would delete the spaces I had entered in between text. For example:
"Did not attend" would become "Didnotattend".
"John DOE" would become "JohnDOE", etc.
Specifying "text" (#) as the format (as recommended above) did not help me, unfortunately.
What ultimately did solve it was saving it as an .ODS file instead of .XSLX .
just simply put character ' before the text, '0.1.16 and calc will interprate it as text data
My issue was currency, properly formatted would change to a much larger number if the numbers entered could represent a date; such as 4.22 becoming $42,482. I discovered that adding a trailing zero solved the problem.
I had pasted numbers from another site and it kept coming up with dates. I just messed around and hit the arrow that's on the paste board to give me the option of unformatted text or HTML format. I selected unformatted, a window opened to show me the text I wanted so I pressed o.k.