Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Need help editing a PDF
#1
I want to find out what I can do in Python for editing PDFs.
The PDF's will have many pages, each page with have 4 labels.
I need to add extra information on each label. It's super important that each label is left in it's original format and nothing is added or removed - but... I do need to read the information from each label and compare with a file in a CSV record.

I want 2 versions...

First version:
I want to add extra information on a specific location on the label.
The extra information will be a simple clipart graphic.

Second version:
I want to shrink the labels by 20% from the top left - so I can add my extra information below in the extra space that will be made when I reduce by 20%.
Ideally... I would like to NOT reduce my reducing an image of the labels. The labels contain text and a barcode and a QR code. It's important that all these still remain in tact but just reduced.

Just looking for ideas right now 🙂
What libraries and tools are there that I can use to do what I want?
I want to know what I can and cannot do in Python given the above description.

Thanks.
Reply
#2
I've also been looking into PDF editing and I think I'll be using PyPDF2 2.11.1

Not had time to go in deep, but what I've found so far looks good (for my usage, least ways).

I hope it helps you.
omar likes this post
Sig:
>>> import this

The UNIX philosophy: "Do one thing, and do it well."

"The danger of computers becoming like humans is not as great as the danger of humans becoming like computers." :~ Konrad Zuse

"Everything should be made as simple as possible, but not simpler." :~ Albert Einstein
Reply
#3
I think what you need to do is make a new pdf and copy stuff from the old pdf to the new one, modifying on the way.

Have a look here for a simple example.

I use reportlab to create pdfs sometimes. Once you have the format set, the rest is easy! I only use pypdf2 for getting sections, chapters, pages of a pdf.

reportlab seems complicated at first, but you have absolute control over everything.

Read the reportlab user guide! (But I don't think it contains exhaustive info on all possibilities within reportlab, you have to ask around.)
omar likes this post
Reply
#4
Thanks for the replies guys.
It would be much much more preferable for me to edit and add to the existing PDF as opposed to create a new one.

The existing PDF has square outlines as well.

Just wondering... do PDF's have some sort of structure like HTML? 🧐
That would definitely help my cause.

See the pic below. I want to write code that searches for 'Code 123456' and below if inserts text and graphics that I want to add.

[Image: mNd1f2C.png]

Hoping the pic helps to explain what I want. Thanks.

@Pedroski55 Your link looks perfect... just read the sample code. I think it's got the start of what I'm looking for. 🙂
My PDF will be 10 - 50 pages, for each page there are 4 sections where new content needs to be added. I'm sure if I can master editing 2 pages, then I'll be good to go from there.
Reply
#5
FYI:

If you are interested in getting down to the nitty gritty of pdf's start here, this is useful when writing partial handlers, or if you had something greater in mind.
omar likes this post
Reply


Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020