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')
------------------------------------------------------------------- 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
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')
-------------------------------------------------------------------
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
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
"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
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.
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')
------------------------------------------------------------------- This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
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...
|
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...
|
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:...
|
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...
|
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...
|
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...
|
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...
|
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++:
...
|
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,...
|
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...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
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
|
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...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
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...
|
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...
|
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,...
|
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...
|
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,...
| |