Ckeditor Simply add break - php

For my Ckeditor text box, I need a line break after a certain amount of characters. The site I manage converts this rich text using tcpdf to generate over a pdf. Long story short, the box lets them type to much in and it carries over with a break at the wrong point from what they can see. So my solution is to shrink the box to the appropriate size, and so that it adds the break at the appropriate spot, or if there is a forcible way to make it put a line break in after a certain amount of text is entered that would be very helpful.

Related

PHP GD Image processing

I am merging text in an image using GD in php.
I am taking the text from the user input so my problem is that when users input long text it overflows and is not merged in the image.
you can check the below image i tried to merge 26 alphabets but had problem so i want the text to split in several lines remaining within the image.
One way would be to work out how many characters can fit per line. (19 characters may work for your example). Then add new line characters to your user supplied text ("\n") every 19 characters.
This isn't a perfect solution because some characters have different widths (except in the case of monotype fonts). You may need to experiment in order to find the best character limit per line.
Also you probably only have room for three lines (based on your example).
UPDATE:
This solution could be improved by calculating the bounding box of the inserted text using the gd function 'imagettfbbox'. This function returns the x/y coordinates for the bounding box of inserted text. This information could tell you how wide and how high the inserted text will be. Allowing you to adjust where you insert new line characters or even the font size.

Splitting a long page into a number of pages

I want to pull a dynamic content, which consists of a long text input with some images, into a div with a fixed width (300px) and height (1000px), the challenge is I cannot use overflow: auto in css when the content's length is exceeding the div's height (1000px), instead, I am asked to split the long content into pages with a pagination.
Is it possible to achieve with PHP or do I have to use javascript (jquery)?
I was thinking to count the number of characters and splitting them, but it doesn't seem correct when the content comes with different sizes of images...
Any ideas??
This might be very complicated(I'd like to say "impossible") to do it on the serverside, because there are too many clientside effects that can't be calculated(browser-default-settings for margins, paddings, line-height, font-size and user-setting for zooming), I would prefer to do this on clientside.
I made a little example using jQuery: http://jsfiddle.net/doktormolle/XwUuA/
It takes the childnodes of the target-element, and wraps them into new elements which have the same dimensions like the target-element(as long as the height of the wrapper does'nt exceed the height of the target-element).
Maybe it's useful to you(It's a draft, of course there still has to be worked on it to match your needs)
You could use PHP. Find out how many characters you can get per line, and how many lines of characters will fit in your div. Then, with PHP, count characters, divide by characters/line, then you'll have how many lines your text will take up. Then you can use getimagesize() to get an images dimensions, and go from there.
See the PHP function for more info.
I wanted to do something similar with HTML but in a C# Windows Forms application.
What I wanted to do was to generate some contents based on some database tables and send them out to the printer. The contents had to fit into A4 papers.
After lots of trial and error I measured the maximum size of the contents based on their size, place etc. and wrote the numbers in the CSS portion of my HTML.
With that I could get a nice result. Still some slight errors on some inputs, but that worked for me!

printing prints slowly for bold text

i have page , in this page i have around 45 lines ,
the first 5 lines are document heading, and this document heading css style is just font-family-arial, font-weight bold ,
and heading inserted inside the td , no more style,
problem is , this first 5 line print very dead slow, after 5the printer print the text very fastly, obviously the reset of the
text are just fonr-weight:normel, Pleawse advise some tip/ideas to increase the printing fast ,
(Am using dot matrix printer ,)
It is a known issue with DMP (Dot Matrix Printer) as the printing from a web page goes as a image print. For bold-face printing it normally prints twice or very slowly (depending on the number of pins in the printer).
For one such issue, I rolled out a component to convert RTF to plain text with printer escape characters (for bold facing, double sizing, compressing fonts) and sent it as a text file to the printer.
This may be a design issue with your printer: as you're saying, it's dot-matrix. These types of printers have very low DPI, so they're working around it by printing bolded text as normal text, but several times in the same area, slightly offset each time (whereas normal text is only printed once). That means that a line in bold text will take a multiple of the time necessary to print a normal line.
If this is a major issue, consider getting a laser printer - those print in near-constant time, regardless of page coverage.

PHP & FPDF: Calculating justified text width

so I'm using FPDF in PHP to programmatically generate a PDF file from images and text (not HTML).
One of the biggest issues I've been having is being able to wordwrap text around an image. My current algorithm looks like:
Get text as an array of words
Add words one at a time to a 'current line' variable, and call GetStringWidth() on it to determine the width of the current line
Once I reach a pre-determined max width, I pass off the current line to an array of lines, and start on a new 'current line'.
Doing this allows me to get an array of lines that shouldn't be breaking improperly, however I've discovered that because my text is justified-aligned, GetStringWidth() can't accurately give me the width of the line when it has been justified.
I've dug into FPDF's MultiCell method to try and figure out how it breaks justified text properly but can't really make heads nor tails of it. It seems to boil down to a similar algorithim (and it writes each line using Cell ) but it never actually seems to calculate the width, it writes out PDF "code" such as 0.375 Tw.
Does anyone know how to calculate the width of justified text, given a string and a max width?
Answering a really old Question.
In the end, I took the function that does justification out of the library and rewrote it to allow for another parameter that makes it continue justifying text even on the last line.
This would result in text that was fully justified for a specific paragraph, then you write the final paragraph without the parameter and have the final line not justified (as per normal).
not sure if this helps but I have a related problem - needing to know how many lines a MultiCell will take up.
I did this by using GetStringWidth() / $maxWidth and getting the ceil() of that.
I can then work out the estimated height (as I know the line height I am using) and use that figure (in my case to switch columns or not).
Perhaps feeding the base text into GetStringWidth() and estimating height this way will allow you to determine an appropriate place to break the text into the multiple MultiCell()s.

Pagination of text from xml file onto html page

O.K. so I'm developing a website to feature my fiction writings. I'm putting all of my documents into XML files, pulling and parsing them from the server with PHP and displaying them on the page. You can visit the page here for an example.
As implied from the background image, What I would like to do is take the text and split it into two columns, (with the text from the first spilling into the second), then allow for the overflow to be paginated so that there is no scrolling necessary. In other words, I'd like for the text to read like a book with the paging based on how long the body of the XML document is.
I would like for this to be done on the server side using PHP or something similar. Is there a way I can do this with an xsl stylesheet or a server-side script? I've been looking everywhere and can't seem to find anything.
Any help is appreciated.
Mr. Mutant
This is a surprisingly hard problem in general, and it's one you'll have no end of trouble with if you try to do it on the server. The problem with paginating HTML text is that where the page breaks go are entirely contingent on the client. The server doesn't know the client's screen resolution, font selection, or window size, and apart from the text itself those are the dependent variables for the problem.
I'd be surprised if at this point there weren't some jQuery library that just does this, but when I had to implement it myself about 7 years ago, here's the approach I took:
Create a div for each column. Each one contains the entirety of the document text. Style the divs with fixed line height. Put the column divs bottom in the document's z-order. Now you can lay out the rest of the page, leaving holes of known size in the layout that the divs can show through, and by manipulating the vertical position of each div you can control which line is the first to appear inside a given hole.
You can then let the client manipulate the font size, and as long as you recalculate the height of the holes and then reposition the divs properly, it will all magically work.
There may be ways of doing this in HTML5 that are easier; I would definitely look into that.

Categories