473,594 Members | 2,778 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 'cGV0ZXIubWFhc0 BtcGx1c3IuZGU=\ n'.decode('base 64')
-------------------------------------------------------------------
Jul 18 '05 #1
7 1333
In article <cm**********@s wifty.westend.c om>,
Peter Maas <pe***@somewher e.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 'cGV0ZXIubWFhc0 BtcGx1c3IuZGU=\ n'.decode('base 64')
-------------------------------------------------------------------
Jul 18 '05 #3
In article <cm**********@s wifty.westend.c om>,
Peter Maas <pe***@somewher e.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***@somewher e.com> wrote in message
news:cm******** **@swifty.weste nd.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 'cGV0ZXIubWFhc0 BtcGx1c3IuZGU=\ n'.decode('base 64')
-------------------------------------------------------------------
Jul 18 '05 #8

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

Similar topics

16
6433
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 I want to to this: f = file(filename, 'rb') data = f.read(1024) while len(data) > 0: someobj.update(data) data = f.read(1024)
3
1811
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 over the collection using indexing, something like: for i in range(len(collection)-1, -1, -1): item = collection
4
4531
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: newList.append((i, element)) i += 1
7
1690
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 colleague did, got an unexpected result, and asked me why. I think I can infer what is occurring, and I was able to find a simple work-around. But I thought I'd ask about it anyway. I've been pushing Python at work for use as a scripting...
6
6041
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 try to modify the objects in the array while iterating through it. I marked the bugs in this code: // Loop through all previously added accounts foreach(Account a in a1) // a1 is an ArrayList { // If name and context is the same if(a.Name ==...
2
2160
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 check, is of same type as one of these fields. Is there a method or technique for iterating through a class's public properties, such as maybe using something from the reflection namespace?
9
2345
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 important. BTW, does anyone has another profile for this? thanks.
5
12093
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++: for each element of the vector for each subsequent element of the vector if the belong together <some code to compare them> then merge the elements (add the 2nd to the 1st, then delete the 1st)
2
2415
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, bmp.Height), System.Drawing.Imaging.ImageLockMode.WriteOnly, bmp.PixelFormat); byte* buff = refData.Scan0.ToPointer(); And on this buff I'm iterating to set its data.
4
2811
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 great deal of help from gits, I've developed a DOM creation and deletion script, which can be used in multiple applications. You simply feed the script a JSON list of any size, and the script will create multiple DOM elements with as many attributes...
0
7946
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
7876
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
8251
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
6654
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
5739
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
3859
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...
0
3897
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1478
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
1210
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.