473,839 Members | 1,392 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

converting file formats to txt

Hi All,

Am looking for a python script that can convert fileformats to txt
format. Am unable to find anything in python. Currently the InfoCon
projects looks pretty good to use, but it is return in java.

Thanks and Regards,
Gaurav Agarwal

Jul 4 '06 #1
11 4667
In <11************ *********@m73g2 000cwd.googlegr oups.com>, Gaurav Agarwal
wrote:
Am looking for a python script that can convert fileformats to txt
format. Am unable to find anything in python. Currently the InfoCon
projects looks pretty good to use, but it is return in java.
What do you mean by 'fileformats'? A script that automagically converts
*anything* to text? What about pictures?

Ciao,
Marc 'BlackJack' Rintsch
Jul 4 '06 #2
Marc 'BlackJack' Rintsch wrote:
What do you mean by 'fileformats'? A script that automagically converts
*anything* to text? What about pictures?
that's a one-and-a-half-liner:

import Image, sys; print list(Image.open (sys.argv[1]).getdata())

</F>

Jul 4 '06 #3
Hi,

I wanted a script that can convert any file format (RTF/DOC/HTML/PDF/PS
etc) to text format.

Regards,
Gaurav Agarwal

Fredrik Lundh wrote:
Marc 'BlackJack' Rintsch wrote:
What do you mean by 'fileformats'? A script that automagically converts
*anything* to text? What about pictures?

that's a one-and-a-half-liner:

import Image, sys; print list(Image.open (sys.argv[1]).getdata())

</F>
Jul 4 '06 #4
On 2006-07-04, Gaurav Agarwal <ga************ ****@gmail.comw rote:
I wanted a script that can convert any file format (RTF/DOC/HTML/PDF/PS
etc) to text format.
And I want to win the lottery.

Without having to buy tickets.

--
Grant Edwards grante Yow! You can't hurt
at me!! I have an ASSUMABLE
visi.com MORTGAGE!!
Jul 4 '06 #5
On Tue, 04 Jul 2006 06:32:13 -0700, Gaurav Agarwal wrote:
Hi,

I wanted a script that can convert any file format (RTF/DOC/HTML/PDF/PS
etc) to text format.
RTF, HTML and PS are already text format.

DOC is a secret, closed proprietary format. It will be a lot of work
reverse-engineering it. Perhaps you should consider using existing tools
that already do it -- see, for example, the word processors Abiword and
OpenOffice. They are open-source, so you can read and learn from their
code. Alternatively, you could try some of the suggestions here:

http://www.linux.com/article.pl?sid=06/02/22/201247

Or you could just run through the .doc file, filtering out binary
characters, and display just the text characters. That's a quick-and-dirty
strategy that might help.

PDF is (I believe) a compressed, binary format of PS. Perhaps you should
look at the program pdf2ps -- maybe it will help.

If you explain your needs in a little more detail, perhaps people can give
you answers which are a little more helpful.

--
Steven.

Jul 4 '06 #6
Thanks Steven, Actually i wanted a do text processing for my office
where I can view all files in the system and use the first three to
give a summary of the document. Instead of having somebody actually
entering the summary. Seems there is no one code that can act as
convertor across formats, i'll have to check out convertors for
individual formats.

Thanks and Regards,
Gaurav Agarwal

Steven D'Aprano wrote:
On Tue, 04 Jul 2006 06:32:13 -0700, Gaurav Agarwal wrote:
Hi,

I wanted a script that can convert any file format (RTF/DOC/HTML/PDF/PS
etc) to text format.

RTF, HTML and PS are already text format.

DOC is a secret, closed proprietary format. It will be a lot of work
reverse-engineering it. Perhaps you should consider using existing tools
that already do it -- see, for example, the word processors Abiword and
OpenOffice. They are open-source, so you can read and learn from their
code. Alternatively, you could try some of the suggestions here:

http://www.linux.com/article.pl?sid=06/02/22/201247

Or you could just run through the .doc file, filtering out binary
characters, and display just the text characters. That's a quick-and-dirty
strategy that might help.

PDF is (I believe) a compressed, binary format of PS. Perhaps you should
look at the program pdf2ps -- maybe it will help.

If you explain your needs in a little more detail, perhaps people can give
you answers which are a little more helpful.

--
Steven.
Jul 4 '06 #7
Steven D'Aprano wrote:
On Tue, 04 Jul 2006 06:32:13 -0700, Gaurav Agarwal wrote:
Hi,

I wanted a script that can convert any file format (RTF/DOC/HTML/PDF/PS
etc) to text format.

PDF is (I believe) a compressed, binary format of PS. Perhaps you should
look at the program pdf2ps -- maybe it will help.
--
Steven.
Or try the program pdftotext?
-- Juho Schultz

Jul 4 '06 #8
I suspect you will have to process those formats separately. But the
good news, at least for doc files, is that there is a script in the
Python Cookbook 2Ed that does what you want for MS Word docs and
another script that does it for Open Office docs.

The scripts are 2.26 and 2.27 pages 101-102.

I think you can probably find them at the ActiveState repository also.

http://aspn.activestate.com/ASPN/Coo.../Recipe/279003

In the book, the title of the script is "Extracting Text from Microsoft
Word Documents"

It uses PyWin32 extension and COM to perform the conversion.

rd

Jul 5 '06 #9
Hi All,

Thanks for the advise. Am trying to play around with InfoCon, part of
from Dspace project. It does file conversions. But it is written in
java and uses open office plugin.

Regards,
Gaurav Agarwal

BartlebyScriven er wrote:
I suspect you will have to process those formats separately. But the
good news, at least for doc files, is that there is a script in the
Python Cookbook 2Ed that does what you want for MS Word docs and
another script that does it for Open Office docs.

The scripts are 2.26 and 2.27 pages 101-102.

I think you can probably find them at the ActiveState repository also.

http://aspn.activestate.com/ASPN/Coo.../Recipe/279003

In the book, the title of the script is "Extracting Text from Microsoft
Word Documents"

It uses PyWin32 extension and COM to perform the conversion.

rd
Jul 5 '06 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
1913
by: Sturnoff Megantic | last post by:
I would like to allow my users to upload a large wav file and have it converted to one of the following: a smaller wav file, an MP3, RA or WMA. My users have access to only large files, and it is not an option to ask them to do the converting on their own. I've done a little research, but can't seem to find anything on this. Can PHP do this. Should I have PHP call an outside program? which one? how? My server's OS is XP.
3
2987
by: Moritz Tacke | last post by:
Hi there! I have a problem concerning the file input to a c++ program: the expected input is either in binary or in some kind of text format; what I finally want is the binary version. I know how to translate between these two versions and would like to write some kind of wrapper. This wrapper should open the text file and provide an istream which behaves exactly like the ifstream of an equivalent binary file would. Is there a smart way...
5
1609
by: Rishit | last post by:
Hello All, I have to convert XML data (that may be received through a dataset) to other formats such as CSV, Excel etc. Are there any libraries or sample code that would help me do this task. I have also to decide on the approach for doing this. The Destination Format needs to be configurable so that the source XML that I have can be converted to the desired destination format looking at the schema stored in some configuration file. I need...
2
1803
by: Subodh | last post by:
Hi, Currently we get data from more then 200 different sources and all of our vendors provide data in different file formats. The problem is we have more then 100 DTS packages now and the maintainance is very diffucult. Every time our vendor changes the format we have to change in multiple DTS packages. Is anybody know what would be the right way of reducing the no. of DTS packages.
6
4843
by: Jim Davis | last post by:
Before I reinvent the wheel I thought I'd ask: anybody got a code snippet that will convert the common ISO8601 date formats to a JS date? By "common" I mean at the least ones described in this W3C note: http://www.w3.org/TR/NOTE-datetime For my requirements the code would be need to be open sourceable under the BSD license.
8
7858
by: spacepie | last post by:
Does anyone have sample coding to do this. I have a legacy app which generates great data but it's in PRN format. I need to convert this to CSV format for importing. I don't know C++ well enouch yet to code from scratch. I could learn quickly from an example that reads,formats then outputs. If anyone has an example code I would like to see it. Thanks, Spacepie
1
1551
by: Rishit | last post by:
Hello All, I have to convert XML data (that may be received through a dataset) to other formats such as CSV, Excel etc. Are there any libraries or sample code that would help me do this task. I have also to decide on the approach for doing this. The Destination Format needs to be configurable so that the source XML that I have can be converted to the desired destination format looking at the schema stored in some configuration file. I need...
8
2242
by: Michael B. Trausch | last post by:
I was wondering if anyone has had any experience with this. Someone I know is trying to move away from Microsoft Works, and I am trying to look into a solution that would convert their data in a lossless fashion to a more modern format. The database has more than 65K rows, so converting it to be an Excel spreadsheet, would, AFAIK, not be an option. It would seem that MS Works can export the database as a DBF format database, though I...
5
2179
by: yawnmoth | last post by:
XSL stylesheets can be used to convert an XML file into whatever binary format you want (DocBook, for example, does PDF's). My question is... what if you wanted to go in the other direction? (eg. convert a PDF to DocBook) Could you do that with existing XML utilities or would you have to write your own program to do that?
0
9698
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10589
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
10297
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9426
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7833
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
7021
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5683
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4493
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
4066
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.