I am trying to display a text file content in Body of the JSP Page.I used BufferedReader and StringBuilder for it. The file contents contains tab instead of spaces between words.While displaying ,the tab between words were displaying as single space between words in browser.
Thanks
Use one of following
1. <PRE></PRE> blocks.
2. CSS - using padding
3. four times
After reading from file and while generating html you can use one of these options.
for more options refer this -
HTML: Tab space instead of multiple non-breaking spaces ("nbsp")?
Related
We have a project where we use pdf.js to render a PDF into webpage and it creates HTML container elements for the PDF pages. The content of the PDF is split as HTML span in the view.
Attached is the image which shows how pdf text is rendered in the view. It also shows, each span has a data-key does not corresponds to a line in PDF.
Now, I need a pdf reader for java which reads and breaks the content as span with data-key or just the span in the order.
There are lot of java libraries available to read PDF content which gets the content line by line but that does not solve my issue. I need a java library which could break the content equivalent to span in the view.
I have a requirement to add few lines at the top of an existing PDF.
I have done this using a PdfReader and a PdfStamper.
In order to have more space in the page header area, i need to move down the current contents by 1 or 2 lines.
Below is from the forum. but it doesn't solve the issue.
How to insert content in the middle of a page in a PDF using IText
Any suggestions?
-i can not upload the pdf or the image of the pdf because am a new user
Do I interpret your question correctly if I assume that you really want to move down everything on the page and add some lines above?
You can do that by changing the media box (and crop box and what other boxes might be explicitly defined for your page) and then add the few lines on top the same way you already do it now.
You can access those boxes in the respective page dictionary which you can retrieve via the PdfReader. Look up the PDF specification for details on those boxes.
Or do I interpret you incorrectly and you only want to move down some text while keeping existing headers and footers in place? In that case Alexis' answer to the other question you refer to still holds.
I try to escape and unescape large text using the StringEscapeUtils from Apache Commons library (v. 1.7) that will be stored and retrieved from a database, in this case a H2 database. Almost every special character is escaped and unescaped successfully except for the new line. I am using Spring Boot (v2.1.3.) with thymeleaf.
So for instance, if I try to store the following text:
He didn't say, "Stop!"
This is a new line!
It will store the text as:
He didn't say, \"Stop!\"\r\n\r\nThis is a new line!
Which is good. But when I unescape it with the unescapeJava method the new line character is not working correctly. I get
He didn't say, "Stop!" This is a new line!
Edit:
The unescapeJava method works when the text is displayed in a html textarea. But when it is rendered as plain html, the linebreak is not working.
The unescapeJava method works when the text is displayed in a html textarea. But when it is rendered as plain html, the linebreak is not working.
Please check your HTML source, it most likely is there
In HTML a newline in source does not introduce a newline on screen, if you want that you should replace newlines with for example <br/> tags.
See more at:
https://developer.mozilla.org/en-US/docs/Web/HTML/Element/br
What #Martin van Wingerden says is correct. A newline in source does not introduce / render it on screen. I found this thread
Render a string in HTML and preserve spaces and linebreaks
which explains that you can use CSS white-space: pre-wrap that will preserve white spaces and line breaks in formatting.
I have a section of a webpage I identified as my area of interest. It may contain multiple html tags in it, but I want to interpret it as a multiline text, or at least as close as possible to how it's rendered by the browser.
Let me give you an example.
<div>
<p>Line 1<p>
</div>
<div><p>Line 2<p></div> <div><p>Line 3 <p></div>
<p>Line 4<p></div><br />Line 5
In the browser, it is rendered like this:
Line 1
Line 2
Line 3
Line 4
Line 5
I want to run the original html through some sort of lib and get a text with the following contents (or close):
Line 1
Line 2
Line 3
Line 4
Line 5
Please note, I don't want to recover the original line breaks present in the Html (as this question points out. I want to interpret the html entities as line breaks similar to the way it is rendered by the browser. Is there any lib that can do it? I've used Jsoup's TextNode.getWholeText() but it doesn't parse the html tags.
Edit: for linux users out there, I want something similar to the result of:
$ lynx -dump file.html > file.txt
The <div> tags and <p> tags by default in HTML have padding and margin blocks around them. So it's obvious that is why the browser is rendering it like it is.
Create a CSS file and disable the padding and margin spacing.
Also, why is Java tagged? If you're doing this in a Java Servlet Page check your System.out.println statements.
I am trying to make a bizarre text editor for people with reading problems with Netbeans. You load the text you like and the editor starts highlighting it word by word with bold letters. The change from plain to bold constantly change the word dimensions and moves the line. One solution was the Monospaced Font but I would like to add a few more fonts available for the user to choose. Is there any way to do this with Arial for example by giving some orders to the JTextPane?
You can manually split the String with <br/> by counting characters and splitting at the right spot to keep the width under your desired character width. Give some leeway so if you get a big word, it won't still go to the next line.
Alternatively, you could use a JList to display your lines (instead of using <br/>). That way, there's no way the line would split to the next line. However, if you do it that way, the user will click on the list like a list and not be able to select text like in a normal text pane.