I am using Java 6, Windows XP, Eclipce Java EE IDE Juno, Swing.
Im looking for the simplest solution without adding any new librarys.
To describe my question i will first start with describing my goal.
My idea is to print out in the following format:
Heading
subHeading
stuffs stuffs stuffs
stuffs stuffs stuffs
I would like to get to this goal by using RTF file format.
What i have concluded is that i should probably use JEditorPane and some how add line by line formated text into the editor.
After im done i would like to write the JEditorPane to file and save it.
So, that said. There are some questionmarks here i do not seem to figure out.
What "standard" class can i use to create RTF formated string lines?
Is JEditorPane the best container for a RTF document?
Thanks for your time!
The documentation has everything you need. (http://goo.gl/EJSpx)
Create javax.swing.text.rtf.RTFEditorKit by calling createEditorKitForContentType
Add newly created editorkit to JEditorPane by calling registerEditorKitForContentType (notice that support for RTF is limited)
Hope this put you on the right path.
See this thread as well Can anyone recommend a Java rich text editor?
Related
I have a JTextArea, and I have this being populated with a chosen .java file, the problem is that the file is appearing as just normal text. I would like to add some pretty print so that the user will be able to see the file as if the file was open in eclipse (keywords different color, comments will be in grey... etc)
I have not been able to find any good examples online for how to do this. what would be the best way to do this?
EDIT:
I got this to finally work, i added the JSyntaxPane jar file to my classpath (jsyntaxpane-0.9.5-b29.jar to be exact) then i added the following two lines of code to get it working for my JEditorPane.
jsyntaxpane.DefaultSyntaxKit.initKit();
JEditorPane.setContentType("text/java");
This can also be used on the following languages: JavaScript, Properties, Groovy, C, C++, XML, SQL, Ruby and Python... just by simply changing text/java to text/LANGUAGE_YOU_WANT in the above code
JTextArea can only display plain text (like notepad in Windows). If you want to show pretty printed source code with colors, you need JEditorPane, which allows you to display HTML.
Now you can either generate HTML manually with syntax-highlighted Java source code or use some library.
See also
Where can I find a syntax highlighting library for Java?
JEdit-Syntax has a JEditTextArea class that will do syntax highlighting. This project was spun off to package some subcomponents of the JEdit project.
All! When I use MS office 2010 Word to write an article about Java, I always need to embed some Java code into the document. I wonder whether there is such a plugin for Word, or another software tool, that can help me do such a job.
Especially features on code formatting and keywords highlighting are welcome!
There are several ways to get syntax highlighted text in Word. Here are some I know:
Eclipse + OpenOffice Writer (Word should do this as well)
Mark and copy a code section in Eclipse
Paste into Writer (Ctrl+Shift+V) or Word (Ctrl+Alt+V) as HTML or RTF text
Using Notepad++
Paste the code section to Notepad++
Select the appropriate syntax highlighting
Use the NppExport Plugin to export to a RTF file
Open the file with Word
http://www.ifcx.org/wiki/Wings.html will let you embed live code and execute it in a document, but it requires open office and some plugins.
There is also Highlight, which can export to multiple formats (including HTML, RTF and even SVG!), and has many themes.
I am creating a window application using java swing.
Now I want to show the Excel(xls) document inside the swing component(Frame/Panel) like this.
How can I get this. Any one have idea about this???
I have used jxl (http://jxl.sourceforge.net/) to parse and read excel files in Java. Displaying it in Swing can then be a map dump of excel cells.
Apache POI will help reading your excel file. It helps extracting the values from the sheets (and can do much more, of course). But of course, you'll still have to design the UI.
Here something that may help (pretty old stuff but maybe still valuable):
Forum entry mentioning JavaSheet, Jeks and PoiBrowser
i've been searching on the internet on how to convert a HTML page into a PDF file using Java. i found a lot of pointers, and in short, they don't work or are too difficult to implement. i also downloaded a commercial product, pdf4ml; the API is something i'd be happy to work with, except that when i crawled a simple page on wikipedia, i get a out of memory error (setting Xmx to 1024 M). in some approaches, they suggest converting HTML -> XHTML -> FO -> PDF. however, i am getting a lot of exceptions for the XHTML-to-FO XLS file; and reading the documentations, it's not something that i have enough time to understand right now.
here are my questions/concerns.
1. is there another cohesive API out there that will easily convert HTML to PDF (commercial or not)?
2. is there a way i can simply capture a HTML page and store it as a single file. this approach would be similar to using internet explorer's way of saving a web page as a web archive (single file, MHT format)?
any help is appreciated. (btw, i know this question has been asked repeatedly, but in addition to the original spirit of the question, i'm opened to other ways). thanks.
Try wkhtmltopdf, which is using WebKit. Another option (I'm using that currently) is using OpenOffice (remote controlled via macros).
you may use iText open source Java lib for that, and read this
or use YaHPConverter open source Java lib.
or do this whith help of icepdf popular open source lib
or use pd4ml, but it not free, only trial.
or use this, and this is man for it.
My 2 cents using opensource tools:
You can use either Capture screenshots with Selenium or WebDriver to save html page's screenshot in an image file from your Java code. And once you have image file you can convert it to pdf again from your Java code.
EDIT:
It seems you can do all that in 1 step using itext Html to Pdf
I am not sure but you could Try
1) cobra html rendering engine http://lobobrowser.org/cobra.jsp
2) htmleditorkit -- part of jdk
3) JWebPane
Use the rendering kit to parse and render html. The rendered out put is a swing component. Swing component can be used by itext to generate pdf file out put
You can try out Pdfcrowd. It is an easy to use commercial online API with many options and with support for Java.
It can create PDF either from web pages or raw HTML code.
Is there any free Java library for extracting text from PDF, that is compatible with Google Application Engine?
I've read about PDFJet, but it can't read PDF, can it?
Is there perhaps other way how to extract text from PDF? I tried http://www.pdfdownload.org/, unfortunately they don't handle non-English characters correctly.
iText now has a text parsing module (I'm one of the parser authors). See the com.itextpdf.text.pdf.parser.PdfContentReaderTool class for an example of how to use it.
PdfBox does not run on GAE. It uses not-allowed java classes.
(GAE only permits these http://code.google.com/appengine/docs/java/jrewhitelist.html)
I have partially modified a very old version of PdfBox (0.7.3) to be GAE complaiant. Now I'm able to extract text from PDF (whole page or rectangular area). I only modified a minumum part of the pdf text extraction and not the whole PdfBox. :)
The idea was to remove refences to java.awt.retangle & C. using my own "rectangle" class.
More info: http://fhtino.blogspot.com/2010/04/pdfbox-text-extration-gae.html
I modified the latest (1.8.0-Snapshot) version to run on Google AppEngine. Had to disable one Unit-Test, but it runs fine for simple text extraction.
Following the simple try-fail-fix approach i had to modify 5 files in total. Pretty doable.
You'll also have to explicitly use a RandomAccessBuffer, like Fabrizio explained.
For the extra lazy, heres the compiled jar, dependencies for text extraction, and the patch. Note that it might not work for every usecase (i.e. rectangle based extraction). Used it to extract text of a whole page.
https://docs.google.com/folder/d/0B53n_gP2oU6iVjhOOVBNZHk0a0E/edit
I know there is http://pdfbox.apache.org/index.html
Apache PDFBox is an open source Java
PDF library for working with PDF
documents. This project allows
creation of new PDF documents,
manipulation of existing documents and
the ability to extract content from
documents.
but I've never tested it.
Last month, I'd just finished extracting text from pdf file in my project. I used XPDF tool for getting text, and text coordinates, but I used it in Xcode (Objective-C). This tool was open source, written by C++, and able to be encoded in many language. However, I didn't know whether XPdf would be work on your java, or not. Anyway, You can try this tool.