foliojs / pdfkit

A JavaScript PDF generation library for Node and the browser
http://pdfkit.org/
MIT License
9.91k stars 1.15k forks source link

Edit existing PDF #83

Open haywoood opened 12 years ago

haywoood commented 12 years ago

I have a brochure that is in pdf form, and want to make parts of the text dynamic. Is there currently a way to do something like this?

misbach commented 11 years ago

+1 Can anyone comment on how much work it would take to add this functionality? Thanks. great project.

adamdunkley commented 10 years ago

+1 Would be a very useful feature

altmind commented 10 years ago

:+1:

aroman commented 10 years ago

+100 this would be invaluable

AlinaNova21 commented 10 years ago

+1 Would love this, using Zend PDF (PHP) right now, but would love to do a rewrite in NodeJS, only feature lacking is loading an existing PDF. One thing that would make implementation easier, only support opening the older 1.4 format like Zend does, after 1.4 the format got more complex.

misbach commented 9 years ago

I wish we could put a bounty on this feature request. It's been reported as an issue 4 times(#101, #105, #168 ), and all four times it had strong interest.

devongovett commented 9 years ago

IMHO this should be a separate library. This functionality would add significant code size requirements to PDFKit and not everyone needs it. It could use mozilla's pdf.js project to read the PDFs, and you'd need some sort of glue code to hook that into PDFKit somehow. I haven't looked into it enough to see exactly how it would work, but I think it is possible with a bit of effort. Unfortunately, it is not something I need, and I don't have time to work on it at the moment. However, if someone wants to take this on, I'm definitely available to help answer questions about the PDF format, PDFKit, etc.

misbach commented 9 years ago

@devongovett Good points. How about an optional add-on module rather than a completely separate library. Thanks for all you do.

If it helps it could be ported from https://github.com/hanneskod/fpdf which I'm currently using.

aadamsx commented 9 years ago

I would gladly pay a big bounty to be able populate "fields" with data from a collection within a pdf template. The template would have text, layout, and fields -- just fill in the fields with data. It seems no package does this at the moment. This seems to be something very common in the business world.

aadamsx commented 9 years ago

It looks like what I'm trying to do is called PDF form fill. It seems the pdftk command line tool can do this.

AlinaNova21 commented 9 years ago

I have started working on a seperate library for editing PDFs, (http://github.com/ags131/pdfedit) it works by appending to the PDF file itself so that existing objects and their offsets remain the same.

Currently it is capable of adding pages and text, I plan on extending it out to generate PDF pages from a template. Technically, with this code, it should be possible to fairly easily fill Form values also, its just a matter of reading the right data structures and adjusting the values.

Its still highly WIP so please don't expect fully working and neat code in its current state

I originally planned on modifying pdfkit to where the data from a loaded PDF could be inserted, but my lack of coffeescript knowledge and pdfkit's assumption that its working from a clear state makes that much trickier.

misbach commented 9 years ago

@ags131 Fantastic!

aadamsx commented 9 years ago

@ags131 great, I'll check it out, if it does form fills and looks good, it's still not too late for me to switch to using it over PDFtk server.

AlinaNova21 commented 9 years ago

@aadamsx Its still early WIP at the moment, but I'm developing it on out to hopefully replace the current Zend_PDF system I'm using for mass mailer generation. I'm about to look into form filling to see how complicated that part is.

MadLittleMods commented 9 years ago

:+1:

My use case is to append some text boxes on top of an existing document, annotate a pdf. Related to #227

tdbs commented 9 years ago

:+1:

pgAdmin commented 8 years ago

I am using HummusJS now. But it converts to native library.

I and my team were seriously hoping for PDFKit to be able to support modification.

AlinaNova21 commented 8 years ago

I have also moved to HummusJS, its annoying having to use a native library, but allows editing existing. PDFs (Something my previous WIP library was designed for but was missing many features)

linus-amg commented 8 years ago

@pgAdmin @ags131 how are you adding images with hummus? (to existing pdfs)

pgAdmin commented 8 years ago

@elgubenis https://github.com/galkahana/HummusJS/wiki/Show-images

pageContext.drawImage(10, 10, path_of_image , {index:2});

ZachMoreno commented 8 years ago

:+1:

dzoba commented 7 years ago

This feature would also be huge for us. We really need to be able to add custom text to a PDF template that already exists.

brandonburkett commented 7 years ago

We are running into this as well. My goal is not even to edit a PDF, just have page 1 and 2 be a cover sheet pdf, we do dynamic workon page 3, then have page 4 be static from existing pdf.

NearlyNormal commented 6 years ago

Sad to see this frature rewuest went nowhere. We have essentially dumped pdfkit due to this missing basic functionality.

rokyed commented 6 years ago

+1000000 i needed this feature badly today, expected it was already built in... since it seems it's something you would expect right from the beginning. But that means I will have to find something else meanwhile :(

misbach commented 6 years ago

For those who are leaving this project for another. May I ask which project you are now using that allows you to edit PDFs? @NearlyNormal @rokyed

rokyed commented 6 years ago

i am still searching @misbach, but i would have loved more to be able to use pdfkit for this

rokyed commented 6 years ago

@misbach I will be using pdfrw and reportlab on python to handle this

radoslavpetranov commented 5 years ago

To anyone who's run into this issue while looking for a way to edit PDF documents in NodeJS:

As of March 2019 I couldn't find a single feature-complete PDF library for NodeJS that lets me do everything I need. What I ended up doing is using PDFBox - this is an outstanding Java PDF library with all the features you can possibly need. I am using it to parse existing documents, populate form fields from JSON and insert images in pre-defined templates and form fields. I created a simple webservice that basically handles all the PDF-related work and the PDF-related code that I wrote is about 200-300 lines.

Just leaving this here for 2 reasons:

  1. To give someone an idea of how they could handle PDF editing "in" their NodeJS project
  2. To keep track of this issue in case PDF editing is ever implemented - I would love not to rely on Java for this.
PolGuixe commented 5 years ago

@radoslavpetranov have you tried HummusJS https://github.com/galkahana/HummusJS ?

jarommadsen commented 5 years ago

pdf-lib just published v1.0 https://github.com/Hopding/pdf-lib. It has all the basic features you would need for pdf generation and pdf manipulation but lacks a lot of the niceties that pdfkit provides such as line wrapping, lists, stroke, etc. and their documentation is pretty bare bones. Currently planning to use pdfkit to create pdf's from scratch and then import into pdf-lib to form fill existing pdf's. https://github.com/Hopding/pdf-lib/issues/9

It would be wonderful to just use one library to do this and pdfkit has a huge leg up on pdf-lib. Given enough time, pdf-lib will likely replace pdfkit entirely if they keep up what they're doing because of existing pdf modification.

haywoood commented 5 years ago

Crazy to get a notification on this issue, what feels like a world away when I opened it. I was just starting to program back then 😂

For context of use, I worked for a company that had to add a lot of text to HP brochures, and we were looking to possibly automate that by templatizing the designs.

joaovct commented 4 years ago

+1 I need to edit 120 pdf files to change one word (😪), and i thought that would be nice if we have a feature to edit and replace texxt

bobiscool commented 4 years ago

👍

My use case is to append some text boxes on top of an existing document, annotate a pdf. Related to #227

giao

kishaningithub commented 4 years ago

I just stumbled upon, https://itextpdf.com/en/blog/itext-news/introducing-itext-dito-powerful-template-engine-converts-data-itext-quality-pdfs This is unfortunately in java and is paid. Would love to see if pdf kit can do something like this. Given the scope and usefulness of this i think putting a bounty on this is pretty much reasonable :-)

Eventhough the issue title is "Edit existing PDF" i think the core problem is having a templating system which both designers and developers can use