How To Read RTF file in JAVA? Using iText?
How To Read RTF file in JAVA? Using iText?.....
import java.io.*;
import com.lowagie.text.*;
import com.lowagie.text.rtf.*;
public class RTF3 {
public static void main(String[] args) {
// System.out.println("This example generate a RTF file name Sample.rtf");
// Create Document object
Document myDoc = new Document();
try {
// Create writer to listen document object
// and directs RTF Stream to the file Sample.rtf
RtfWriter2.getInstance(myDoc, new FileOutputStream("Sample.rtf"));
// open the document object
myDoc.open();
// Create a paragraph
Paragraph p = new Paragraph();
p.add("Helloworld in Rtf file..amazing isn't");
// Add the paragraph to document object
myDoc.add(p);
catch(Exception e) {
System.out.println(e);
//close the document
myDoc.close();
Exception in thread "main" java.lang.NoSuchMethodError: com.lowagie.text.Rectangle.width()F
at com.lowagie.text.rtf.document.RtfPageSetting.rectEquals(RtfPageSetting.java:433)
at com.lowagie.text.rtf.document.RtfPageSetting.guessFormat(RtfPageSetting.java:362)
at com.lowagie.text.rtf.document.RtfPageSetting.setPageSize(RtfPageSetting.java:341)
at com.lowagie.text.rtf.RtfWriter2.setPageSize(RtfWriter2.java:248)
at com.lowagie.text.Document.open(Unknown Source)
at view.RTF3.main(RTF3.java:23)
CAN you HELP me?
import com.lowagie.text.Document;
import com.lowagie.text.rtf.parser.RtfParser;
import java.io.FileInputStream;
String inputFile = "sample.rtf";
Document document = new Document();
document.open();
RtfParser parser = new RtfParser(null);
parser.convertRtfDocument(new FileInputStream(inputFile), document);
Similar Messages
-
How to display RTF File in Browser Using Servlets/JSPs
Hi All,
I have some RTF Files, which contains some data.
The data needs to be displayed in the frame of jsp page .
How i can display the RTF File Content using either servlets/jsps
Can any body have idea on this.
Help me out on this.
With Regards
HariIf you only need to display it, consider your HttpServletRequest just as byte stream. :) Just read from ServletInputStream and write it back into ServletOutputStream of HttpServletResponse.
If you want to process incoming XML, please give some details first, what exactly you want to do. :) -
hi
i have an rtf or doc file. some text in thisfile is italic,bold,underlined etc. i want to read this from a java prog and find out what text is bold,underlined or formatted in other way.
how can i do this. please help with prob.
thankssomeone please help
-
How to read XML files from java
i need a sugession that how to read a xml file using java code
and i need to parse using some parsers and display attributes and entity seperately
as a string.......import org.dom4j.Document;
import org.dom4j.DocumentException;
import org.dom4j.io.SAXReader;
import java.io.File;
import java.text.AttributedCharacterIterator.Attribute;
import java.util.Iterator;
import java.util.StringTokenizer;
public class XmlParser
private String Result="";
private String Final="";
private String Delim="";
public void bar1(Document document) throws DocumentException
org.dom4j.Element root = document.getRootElement();
// System.out.println(root.getName());
bar2(root);
System.out.println(this.Result);
process();
public void bar2(org.dom4j.Element e)
for(Iterator i = e.elementIterator();i.hasNext();)
org.dom4j.Element Element = (org.dom4j.Element) i.next();
Result += Element.getName()+"\t"+Element.getText()+"\n";
bar2(Element);
public void process()
StringTokenizer Tokenizer = new StringTokenizer(this.Result,"\n");
String element;
while(Tokenizer.hasMoreTokens())
element = Tokenizer.nextToken();
StringTokenizer Tokenizer2 = new StringTokenizer(element,"\t");
// Do what ever String Process here Example
this.Final += element.getName();
this.Final += this.Delim;
System.out.println(this.Final);
public static void main(String s[])throws Exception
Document document = null;
SAXReader reader = new SAXReader();
File f1= new File("D:/Rajesh/EDI to XML/EDI.xml");
document = reader.read(f1);
Demo obj = new Demo();
obj.bar1(document);
i think this will hep full....... -
How to read Excel file in java
Respected sir/madam
I want to read the values from Excel file in Java program. How can I do that. When I searched over the net I came to know that you can treat Excel file as a Database and write the code as u write for making DB connections .
I did that but i am getting the following error ..can anybody please help..
This is the code what i have written
import java.io.*;
import java.sql.*;
public class ReadExcelFile {
Connection c;
Statement stmnt;
public void checkABA_Number()
try
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
c = DriverManager.getConnection("jdbc:odbc:ExcelTest","",""); // ExcelTest is the DSN name
stmnt = c.createStatement();
ResultSet rs = stmnt.executeQuery("select * from abadata"); // abadata is my Excel file name
while(rs.next())
System.out.println(rs.getString(1)+" "+rs.getString(2));
}catch(Exception e)
System.out.println(""+e.toString());
finally
try
stmnt.close();
c.close();
catch( Exception e )
System.err.println( e );
public static void main(String[] args)
new ReadExcelFile().checkABA_Number();
My Excel file starts from the first row and first column and also the first row contains the names of the column.
It give me the following error..
java.sql.SQLException: [Microsoft][ODBC Excel Driver] The Microsoft Jet database engine could not find the object 'abadata'. Make sure the object exists and that you spell its name and the path name correctly.
How can I deal with this.?I have properly selected the worksheet while giving the DSN . Is there any versionig problem with Excel or some drivers are in appropriate..and yes i chose Microsoft Excel Driver (.xsl) from ODBC .
I created System DSN.
Can anybody please help me with this ? I will be very gratefull for replies
Thanks in advancehere is the code to read excel file
public void readexel(String filename)
Connection c = null;
Statement stmnt = null;
try
Class.forName( "sun.jdbc.odbc.JdbcOdbcDriver" );
c = DriverManager.getConnection("jdbc:odbc:Driver={Microsoft Excel Driver (*.xls)};DBQ=" + filename);
stmnt = c.createStatement();
String query = "Select * from [Sheet1$]" ;
ResultSet rs = stmnt.executeQuery( query );
while( rs.next() )
System.out.println( rs.getString(1) );
catch( Exception e )
System.err.println( e );
} -
How to display .swf files in java using eclips platform ???
Here my java code plz some one help me...
import javax.swing.*;
import java.io.*;
import java.net.MalformedURLException;
import java.awt.*;
import java.awt.event.*;
public class DisplaySWF extends JFrame
public JPanel window_panel;//address_panel,
public JLabel address_label;
public JTextField address_tf;
public JEditorPane window_pane,tree_pane,attr_pane;
public JScrollPane window_scroll,tree_scroll,attr_scroll;
TextArea t1,t2;
JPanel pane;
public JButton address_b, browse;
public JLabel l,m;
private Go go = new Go();
JFrame f ;
public DisplaySWF() throws IOException
// Define address bar
//tree_pane=new JEditorPane();
//tree_pane.setBounds(650,50,300,250);
//address_panel = new JPanel();
//address_panel.setLayout(null);
f= new JFrame("Web browser");
f.setSize(1000,700);
pane=new JPanel();
pane.setVisible(true);
pane.setLayout(null);
f.setContentPane(pane);
address_label = new JLabel(" address: ", SwingConstants.CENTER);
address_label.setBounds(10, 10, 70, 30);
pane.add(address_label);
address_tf = new JTextField("",25);
address_tf.setBounds(80,10,250,30);
pane.add(address_tf);
browse = new JButton("Browse");
browse.setBounds(340, 10, 140, 30);
browse.addActionListener(go);
pane.add(browse);
window_pane=new JEditorPane();
window_pane.setBounds(10, 50, 600, 600);
pane.add(window_pane);
l=new JLabel("DOM Structure");
l.setBounds(650,30,100,10);
pane.add(l);
t1=new TextArea();
t1.setBounds(650,50,300,250);
pane.add(t1);
m=new JLabel("Attribute");
m.setBounds(650,350,100,10);
pane.add(m);
t2=new TextArea();
t2.setBounds(650,380,300,280);
pane.add(t2);
f.setVisible(true);
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
window_pane = new JEditorPane("http://www.yahoo.com")
public boolean getScrollableTracksViewportWidth()
return true;
public class Go implements ActionListener
public void actionPerformed(ActionEvent ae)
JFileChooser fc = new JFileChooser();
int result = fc.showOpenDialog(null);
if (result == JFileChooser.APPROVE_OPTION)
File file = fc.getSelectedFile();
String sname = file.getAbsolutePath();
address_tf.setText(sname);
String ext=getFileExtension(sname);
try
if(ext.equals("swf"))
window_pane.setPage(address_tf.getText());
System.out.println("hi");
catch (MalformedURLException e)
{ // new URL() failed
window_pane.setText("MalformedURLException: " + e);
catch (IOException e)
{ // openConnection() failed
window_pane.setText("IOException: " + e);
public String getFileExtension(String filename)
if (filename == null)
return null;
int lastUnixPos = filename.lastIndexOf('/');
int lastWindowsPos = filename.lastIndexOf('\\');
int indexOfLastSeparator = Math.max(lastUnixPos, lastWindowsPos);
int extensionPos = filename.lastIndexOf('.');
int lastSeparator = indexOfLastSeparator;
int indexOfExtension = lastSeparator > extensionPos ? -1 : extensionPos;
int index = indexOfExtension;
if (index == -1)
return "";
else
return filename.substring(index + 1);
public static void main(String args[]) throws IOException
DisplaySWF wb = new DisplaySWF();Thanks for reply...
but i search in the google about this topic...there is no results will appear..
the problem is "i have to run program in the MacOS like extract all the
.sit(StuffIt) extension files. These sit files same as zip files in the windows... we have one tool called StuffIt Expander but it is 3rd party tool. but here requirement is i have to write my own program to extract all the files same as zip file program...
please do the needful..i am waiting for ur reply,,, -
Hi,
can any one help me on how to read pdf files in java using itext. I have written some piece of code but it is of no use. It is giving some garbage.
import java.io.*;
import java.util.*;
import java.lang.*;
import com.lowagie.text.pdf.PdfReader;
public class PdfAccess
public static void main(String[] args)
try {
String pdfFile = args[0];
PdfReader reader = new PdfReader(pdfFile);
int pageCount = reader.getNumberOfPages();
System.out.println(pageCount);
String content = " ";
for(int i=1;i<=pageCount;i++) {
byte[] pageContent = reader.getPageContent(i);
content = content+(pageContent.toString());
System.out.println(content.trim());
} catch(Exception e) { }
can any one help me on how to get contents of the file. Are there examples avalilable??* Try this by PDFBOX , it will execute well as per ur request..........
public void getPdfText(String fileName) throws IOException {
StringWriter sw = new StringWriter();
PDDocument doc = null;
try {
doc = PDDocument.load(fileName);
PDFTextStripper stripper = new PDFTextStripper();
stripper.setStartPage(1);
stripper.setEndPage(Integer.MAX_VALUE);
stripper.writeText(doc, sw);
OutputStream out=new FileOutputStream(new File("d://PDFText.txt"));
PrintStream write=new PrintStream(out,true,"UTF-8");
write.print(sw.toString());
//System.out.println(sw.toString());
} finally {
if (doc != null) {
doc.close();
Can..Can...If we Try...! -
How to read HTML files using UTL_FILE
Hello Friends,
How to read HTML files using UTL_FILE package ? According
to Oracle documentation UTL_FILE can read or write OS Text Files.
Thanx in advance..
AdiHI Hareesh,
i have gone through that blog.
i tried it...but i am getting mapping error no receiver determination fond because there are so many excel files.
my data is available on sharedString.xml but also it is in not same order.
i have no clue how to handle this part form the blog.
"This way our mapping will receive all data from the sheet in an XML format. The only thing that's left is to create an XSD file from the XML file we received in order to be able to use it in the mapping and as our Service Interface and we can proceed with mapping. As you can see from the sheet.xml files all the data is placed with column name and row number so it's not that difficult to map it to an table type format using the Message Mapping only (no java, abap mapping required)." -
How to extract .sit files(in MAC) using java program
Hi,
please help me , i want to simple program for
" how to extract .sit files(in MAC) using java program"
that sit files same as zip files in windows..[Thanks for reply...
but i search in the google about this topic...there is no results will appear..
the problem is "i have to run program in the MacOS like extract all the
.sit(StuffIt) extension files. These sit files same as zip files in the windows... we have one tool called StuffIt Expander but it is 3rd party tool. but here requirement is i have to write my own program to extract all the files same as zip file program...
please do the needful..i am waiting for ur reply,,, -
How to read svg file by Xerces2 -j java
How can we read svg file data by using Xerces2 -j java
Hi Dharma,
There is a new beta release for [java-libpst|http://code.google.com/p/java-libpst/] that adds 32bit (ANSI) PST support. -
How To read/write file on remote server in java
Hi All,
How To read/write file on remote server in java? I mean using URL - http://www.xyz.com can I right file to that perticular server.
Thanks in advanceIf your server support a means of uploading files you can.
A popular means is [http://en.wikipedia.org/wiki/WebDAV]
However, by default web server don't allow you upload files, its usually something you need to configure or install.
I suggest you have a look at your web servers documentation. -
How to read pdf file using file adapter
Hi..
How to read pdf file using file adapter?
regards
ArunHi
This may help you
/people/sap.user72/blog/2005/07/27/xi-generate-pdf-file-out-of-file-adapter
/people/alessandro.guarneri/blog/2007/02/21/sap-xi-acting-as-a-huge-file-mover
---Ram -
How 2 read two files from 2 diff. directories, using single adapter
How 2 read two files from 2 diff. directories in same system, using single file adapter.
you can use advanced selection for source file
see
http://help.sap.com/saphelp_nw04/helpdata/en/e3/94007075cae04f930cc4c034e411e1/frameset.htm -
How to transfer pc file to Samsung using the adobe reader app?
how to transfer pc file to Samsung using the adobe reader app?
I solved the problem. I manually created my own Adobe PDF folder by connecting the phone via usb to my PC, Windows Autoplay gave me the option to 'Open device to view files'. Explorer then displayed all the folders on the phone. I created an Adobe PDF folder manually and copied the PDFs I wanted to view into that folder. Adobe Reader then found the files without a problem. I clearly was missing something quite simple but something I'm sure a lot of people would miss. Perhaps if the next version of Adobe Reader for Android created this folder automatically, like Kindle and Kobo and other readers do, it might save a lot of people a bit of a headache.
-
How to read a file with data in Hierarchical Structure using XSD Schema
Hi
We have requirement in which we have to read a FIXED LENGTH file with FILE ADAPTER. File contains the data in hierarchical structure. Hierarchy in the file is identified by the first 3 characters of every line which could be any of these : 000,001,002,003 and 004. Rest files are followed after these. So structure is like:
000 -- Header of File. Will come only once in file. Length of this line is 43 characters
-- 001 -- Sub Header. Child for 000. Can repeat in file. Length of this line is 51 characters
--- 002 -- Detail record. Child for 001. Can repeat multiple times in given 001. Length of this line is 43 characters 1353
-- 003 -- Sub Footer record at same level of 001. Will always come once with 001 record. Child for 000. Length of this line is 48 characters
004 -- Footer of file.At same level of 000. Will come only once in file. Length of this line is 48 characters
Requirement is to create an XSD which should validate this Hierarchical Structure also i.e data should come in this hierarchy only else raise an error while parsing the file.
Now while configuring the FILE ADAPTER to read this file we are using Native Schema UI to create the XSD to parse this structure using an example data file. But we are not able to create a valid XSD for this file which should validate the Hierarchy also on the file.
Pls provide any pointers or solution for this.
Link to download the file, file structure details and XSD that we have created:
https://docs.google.com/file/d/0B9mCtbxc3m-oUmZuSWRlUTBIcUE/edit?usp=sharing
Thanks
Amit Rattan
Edited by: user11207269 on May 28, 2013 10:16 PM
Edited by: user11207269 on May 28, 2013 10:31 PM
Edited by: user11207269 on May 28, 2013 10:33 PMHeloo.. Can anyone help me on this. I need to do Hierarchial read / validation while reading the file using File Adapter using Native XSD schema.
Maybe you are looking for
-
My MacBook Pro is running SUPER slow. When I start up my computer it takes forever to load up, when I play World of Warcraft it is painfully slow with logging in etc. Everything about starting a program takes forever to load up and then once you
-
Equium L350D with Vista wont go into sleep mode
Equium L350D with Vista wont go into sleep mode i just reinstalled windows and sleep was working but now the screen just goes off but its clearly not on standbye please help
-
2 Out Of 9 Short FCE Videos Mysteriously Stretched In iDVD.
I posted this in the iDVD forum yesterday but have received no response and it now appears it could equally be an FCE problem. Yesterday I made 9 short slideshow videos in Final Cut Express, exported them as QuickTime Movies (NOT self-contained) and
-
Can't download Acrobat 9.3 after recovering computer.
Here's my problem. I just had to recover my computer. Before the problem that caused the recovery I had downloaded Acrobat 9.3 and it worked fine. Now I can't download 9.3. When I try to download 9.3 as soon and the down load manager downloads I
-
After I SL mail stopped working. At first I thought it was only mail with attachments but i tried a simple text only email and it will not send, it just stays in outbox... Anyone else having the same issue?