473,396 Members | 1,917 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Iterating over PDF documents

Hi,

I'm trying to edit a PDF document line-wise. This is more difficult
than I thought, because PDF uses a mixture of all line terminators
available in *X, Mac and Win so that utilizing "for line in file"
is difficult. I tried universal newline but that spoils the document
apparently. What other options do I have besides writing my own PDF
line iterator?. All options have to be quick hacks as I have already
invested some time in existing code and the deadline is approaching
fast :)

Thanks for your help.

Mit freundlichen Gruessen,

Peter Maas

--
-------------------------------------------------------------------
Peter Maas, M+R Infosysteme, D-52070 Aachen, Tel +49-241-93878-0
E-mail 'cGV0ZXIubWFhc0BtcGx1c3IuZGU=\n'.decode('base64')
-------------------------------------------------------------------
Jul 18 '05 #1
7 1319
In article <cm**********@swifty.westend.com>,
Peter Maas <pe***@somewhere.com> wrote:
Hi,

I'm trying to edit a PDF document line-wise. This is more difficult
than I thought, because PDF uses a mixture of all line terminators
available in *X, Mac and Win so that utilizing "for line in file"
is difficult. I tried universal newline but that spoils the document
apparently. What other options do I have besides writing my own PDF
line iterator?. All options have to be quick hacks as I have already
invested some time in existing code and the deadline is approaching
fast :)


try this:

for line in open(path, "U"): # universal newline mode
...

Just
Jul 18 '05 #2
Just schrieb:
try this:

for line in open(path, "U"): # universal newline mode


Thanks, Just, I tried this but the edited PDF was damaged.

--
-------------------------------------------------------------------
Peter Maas, M+R Infosysteme, D-52070 Aachen, Tel +49-241-93878-0
E-mail 'cGV0ZXIubWFhc0BtcGx1c3IuZGU=\n'.decode('base64')
-------------------------------------------------------------------
Jul 18 '05 #3
In article <cm**********@swifty.westend.com>,
Peter Maas <pe***@somewhere.com> wrote:
Just schrieb:
try this:

for line in open(path, "U"): # universal newline mode


Thanks, Just, I tried this but the edited PDF was damaged.


That's probably because PDF can also contain arbitrary binary data,
which would indeed break if all occurances of \r\n and \r were replaced
by \n...

Just
Jul 18 '05 #4
Peter Maas wrote:
I'm trying to edit a PDF document line-wise. This is more difficult
than I thought, because PDF uses a mixture of all line terminators


It should also be pretty difficult because PDFs are binary, not
text...

(They might contain a whole lot of stuff that looks like text, but
there are binary sections mixed into many of them, and I believe
the header at least is binary. The sample files I'm looking at
definitely are, in any case. Your solution could not be general.)

-Peter
Jul 18 '05 #5
"Peter Maas" <pe***@somewhere.com> wrote in message
news:cm**********@swifty.westend.com...
I'm trying to edit a PDF document line-wise. This is more difficult
than I thought, because PDF uses a mixture of all line terminators
available in *X, Mac and Win so that utilizing "for line in file"
is difficult.


If you're just going to extract some text or do searching, you can try the
pdftotext utility and convert the document(s) to plain text.
http://www.snapfiles.com/get/pdftotext.html (Windows).

-Tomas
Jul 18 '05 #6
Would this Python/PDF handling library be useful to you:

<http://www.boddie.org.uk/david/Projects/Python/pdftools/>

I don't think it specifically handles re-writing, but it might be a
useful starting point.

--Phil.
Jul 18 '05 #7
I solved the problem by writing an iterator that takes care of all
eol types without changing/deleting them. So I could edit the parts
that looked like text while leaving the binary parts alone.

Thanks to you all for your useful input.

--
-------------------------------------------------------------------
Peter Maas, M+R Infosysteme, D-52070 Aachen, Tel +49-241-93878-0
E-mail 'cGV0ZXIubWFhc0BtcGx1c3IuZGU=\n'.decode('base64')
-------------------------------------------------------------------
Jul 18 '05 #8

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

Similar topics

16
by: Derek | last post by:
Pardon the newbie question, but how can I iterate over blocks of data from a binary file (i.e., I can't just iterate over lines, because there may be no end-of-line delimiters at all). Essentially...
3
by: Patrick von Harsdorf | last post by:
I want to iterate over a collection and delete all unwanted entries. for item in collection: del item of course doesn´t do anything useful. Two things come to mind: a) iterating backwards...
4
by: Fernando Rodríguez | last post by:
Hi, While iterating through a list I'd like to know not just the current element, but also its index. Is there a better way than this: i = 0 newList = for element in aList:...
7
by: Dave Hansen | last post by:
OK, first, I don't often have the time to read this group, so apologies if this is a FAQ, though I couldn't find anything at python.org. Second, this isn't my code. I wouldn't do this. But a...
6
by: Gustaf Liljegren | last post by:
I ran into this problem today: I got an array with Account objects. I need to iterate through this array to supplement the accounts in the array with more data. But the compiler complains when I...
2
by: Nick | last post by:
Hi all, Just a quick question. I have a class that exposes a number of fields (which are themselves custom types) through public properties. At run time, I have an object whom I'd like to...
9
by: krbyxtrm | last post by:
hello i have this profile for iterating empty vectors: +0.3us (microsecond) delay on intel pentium 2.4Ghz can this added delay to my application be reduced? i mean near zero delay, its very...
5
by: Alan | last post by:
I was wondering whether it is good programming practice or asking for trouble to modify a vector while iterating through it. That is, I want to do something like the following pseudocode in C++: ...
2
by: =?Utf-8?B?U2hhcm9u?= | last post by:
I'm using a Bitmap that has a palette of 256 colors (256 bytes). I'm taking the Bitmap data by: System.Drawing.Imaging.BitmapData refData = myBitmap.LockBits(new Rectangle(0, 0, bmp.Width,...
4
RMWChaos
by: RMWChaos | last post by:
The next episode in the continuing saga of trying to develop a modular, automated DOM create and remove script asks the question, "Where should I put this code?" Alright, here's the story: with a...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
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,...

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.