How do you detect if a specific string will either fit or take up a second line in a textbox in Crystal Reports/VB.NET/SQL? - sql

So basically I have a textbox with a specific width and I need to know if the string I will put into it will either fit nicely in one line or take a second line. For example: I have
string v = "WERTYUIOSDFGHJKWERTYUISDFGHJKXCVBNSDFGHJ"
and a textbox that's 3000 in width.
At first I tried: if v.length = x then... where x is the length of the string that can fit into the textbox. But I soon found out that strings with mostly 'I' can fit more inside compared to a string of mostly 'M'. And that is where the problem lies. Is there a function that detects if the string is going to take/need a second line?

Another option is to create or use a 3rd-party Crystal Reports UFL (User Function Library). A list of 3rd-party UFLs is maintained by Ken Hamady here.
At least one of these UFLs provides functions that allow Crystal formulas to either:
a. specify as input the text, font name, font size, bold and italics status and get the required width (in pixels or twips), or
b. specify the available width for the text and get the maximum font size to fit, or the number of lines required for a given font size.
The advantage of using a UFL approach is that Crystal supports dynamic property expressions. That means that the result of the function call can dynamically control a property such as font size, height, position, etc.

Related

Add text box at specific location in report base on value

I'm working on a cut list generator but I'm having difficulty on the final report. I'd like to display a rectangle that represents the factory length piece with lines indicating cut points. In each segment I'd like to have the length of the piece shown. Using Report.line I've created the rectangles needed but I'm not sure how to get text in each box. Here is a sample output so far As an example I want the three rectangles for Piece #1 to have 48" in them, probably all the way to the left. Any suggestions? I thought createReportControl might work but I'm not sure that is the correct approach. I'm also thinking about one text box with a monospace font so I can scale the input across the entire width. Any suggestions are appreciated.
Thanks,
Dave
I played around with the monospace font idea. It isn't as pretty as I would like but I'm getting closer.
The issue is that I cannot keep the text in the same spot in each box. There is one line lower on the page that pushes the number almost out the right side of the box.
Sample Output
This code is functional but I'm looking at the cosmetics. I'm inserting spaces between my values using the following function:
Private Function InsertSpaces(CutLen, PieceLen) As String
MaxChar = 50 ' 6 inch 14pt Courier text box
cutchar = Int(CutLen / PieceLen * MaxChar)
Cutcharcount = Len(Str(CutLen))
cutchar = cutchar - Cutcharcount + 1
For i = 1 To cutchar
InsertSpaces = InsertSpaces + " "
Next
End Function
I'm just trying to clean it up. CreateReportControl was giving me a error because I wasn't in design mode. I'm guessing that is because it ran as part of OnFormat of the Detail section.

How to make long text fit into a text_frame? Python-pptx

I'm working with python-ppt to create a portfolio of candidates in a Powerpoint presentation. There is one candidate per slide and each of them has provided information about themselves like name, contacts and a minibio (the problem I'm here to solve)
The text_frame, created with values of height and width, must fit the slide but must a contain all lenght of minibios, which is not happening.
In a long phase (>200 char, with font size 12) it exceeds the size of the text box and get "out" of the slide, so, in presentation mode or a PDF file, the "overrun" of text is lost
Is there any way to confine the text to the shape/size of the text_frame? (extra help if the solution wont change font size)
Just found one parameter that helped to find the answer
When creating a text_box object with slides.shapes.add_textbox() and adding a text_frame to it, the text_frame.word_wrap = True limits the text to be contained inside the dimentions of the text_box
The code shows it better
# creates text box with add_textbox(left, top, width, height)
txBox = slide.shapes.add_textbox(Cm(16),Cm(5),Cm(17),Cm(13))
tf = txBox.text_frame
tf.word_wrap = True
Before word_wrap parameter
After word_wrap parameter
The short answer is "No". PowerPoint is a page-layout environment, and much like the front page of a newspaper, text "story" content needs to be trimmed to fit the allotted space.
We're perhaps not used to this because word-processing, spreadsheet, and web-page content is "flowed" into a (practically) unlimited space, but the area of a PowerPoint slide is quite finite. Also, using it for large text blocks is somewhat of an off-label use. There is a certain amount of flexibility provided by reducing the font size, but not as much as one might expect. Even accommodating 20% additional text requires what appears as a pretty radical change in font size.
I've encountered this problem again and again, and the only solution I have ever seen work reliably is hand-curating the content to fit.
python-pptx has one experimental feature to address this but its operation has never been very satisfactory and it's tricky to get working. https://python-pptx.readthedocs.io/en/latest/api/text.html#pptx.text.text.TextFrame.fit_text
The business of fitting text is the role of a rendering engine, which python-pptx is not.

vb.net I am trying to size a control (label, textbox, richtextbox) so that it is the smallest square that contains a given string

I need to present arbitrary text, which might include line breaks, in a square control with word wrap such that the square is as small as possible but sufficiently large to display the text in its entirety.
This is the closest I've gotten so far:
Load the text into a temporary rich text box, Rich, with BorderStyle = none
I increment the value of size, width=height=size until Rich.ClientRectangle.Width = Rich.Width.
If I could now extract the visual lines one by one I would be done, as I could then save the original string with appropriate line breaks for later display.
Visual lines are not, of course, the same as Rich.Lines array.
Any ideas?
Thank you.

convert text to single type

Dim fontsize As Single = CSng(SynopsisTSCmbFontSize.Text)
rtbSynopsis.Font = New Font(SynopsisTSCmbFonts.Text, fontsize)
to change the fontsize to the value selected in a combo box, the value has to be of the Single type.
the combobox is populated with numbers entered at the design mode, ranging from 7-78. I know that these are entered as strings.
the error is :
I have tried a number of things to convert the text (which are numbers, no letters) from the combobox to single to no avail. try parse did not work, trimming did not work, first convert to INT or DBL, then to SNG did not work.
What is the correct syntax here?
I would have thought that it was pretty standard stuff to change the fontsize.
I found a solution : instead of populating the combobox at design time, I populated it at runtime where I had full control over the type.
Dim i As Single
For i = 5 To 70
SynopsisTSCmbFontSize.Items.Add(i)
TreatmentTSCmbFontSize.Items.Add(i)
Next
once the comboboxes are correctly populated, I can run the rest of the code with no errors
thank you all for your time!

Set a PDFFormField's value with a specific font size

I have a very simple use-case for a filling up an acroform. I have a non-multi line text field. I would like to resize the font size to fit in the width of the text field.
The PDF spec mentions that a font size of 0 implies auto fit to width. However PDFBox - 1419 & PDFBOX-1402 mention that this isn’t supported in pdfbox.
Hence I have some small logic to calculate the font-sizes based on the widths etc. However I’m facing problems setting the font size.
I’m seeing the behavior mentioned in PDFBox - 1419.
Starts out with incorrect font size. If I click into the field, it displays correctly. Click outside the field, it reverts back to the wrong display.
Code :
pdfFormField.getDictionary.setString(COSName.DA, "/Helv 10 Tf 0 g”)
pdfFormField.setValue("Hello")
Any pointers or help would be much appreciated.
A simple example of such a PDF is here
Pdfbox form field classes read the default appearance into a member variable early in their life-cycle and don't follow-up to changes in the form field dictionary they are based on. Thus, when creating the appearance stream during pdfFormField.setValue("Hello"), the former DA value is used.
After setting the default appearance, therefore, you have to instantiate the form field object anew. Then set the field value using this new object.
For sample code look at this answer to How to set the text of a PDTextbox to a color?; here the existing DA value of a text field is changed to contain a color setting operation before the field value is set.