I am looking for some way to code a function (I'm open to any language or library at this point) to take an already existing PDF file as input and return a modified PDF file that links certain words to different URLs. I know PHP and ColdFusion both have good tools for dealing with PDF's, but I haven't been able to find anything that works.
I've been doing this by going through Acrobat and linking the text by hand and was wondering if there was any way to automate the procedure.
Thanks!
With ColdFusion you can extract the text with DDX (see Extracting text from a PDF document on the page), modify it using search/replace and generate new document.
If I understand what you're trying to do, you should be able to use CFPDF (http://livedocs.adobe.com/coldfusion/8/htmldocs/Tags_p-q_02.html#2922772) to read the pdf file into a ColdFusion variable, replace whatever content you want in that variable, then save the content back to pdf.
Related
I have one issue about PDF file.
I generate dynamic PDF template (Like Certificate). The file content some fields like Firstname, Lastname, Course type, etc.
I want to write dynamic content into PDF as firstname, lastname etc.
I have tried MPDF, FPDF etc tools, but they are not working. I also used PDF to HTML conversation but after converting HTML regenerates not possible from html into proper format.
Please let me know if anyone have other idea to direct replace content into Existing pdf using PHP.
I have sample pdf files.
I want to replace content into given attachment. This is a demo file I have many files with different templates.
Okay, get away from your thoughts one could easiely change anything in a pdf from PHP.
The one way to do such thing like generating a certificate for anyone is to generate a "blank" pdf and then put in the names with names with a php libarary (like Zend_Pdf or anything else).
To make it short: There is no (easy, free) way to manipulate data in a PDF.
To make it complicated: Yes, there is a way. One have to open the file, read it's content, understand where to search for the variables, manipulate the data and regenerate the pdf with a pdf generator. And yes, i know, it is very complicated, so stay at the short and easy way: Generate a blanko and put in the variables as needed ;)
I am brand new to the TCPDF library and after reading through the documentation I am not sure if it is possible to do what I need. I have an image file, lets call it background.tiff, and I want to place this image inside a new pdf and write some text ontop of this image in certain positions. I can't find any information or documentation on writing text onto an image, or even positioning text absolutely on the page. Is this something that should be done with writeHTML() instead? Ideally this pdf will be printed later - is it possible to 'outline' the text for printing purposes in TCPDF? Any help would be much appreciated, I am feeling a bit lost here.
edit: I am completely open to switching to another library if it would be a better solution.
Altough solution is already given in comment here's what u need to know:
Image() - read about inserting an image into PDF document.
SetX(), SetY(), SetXY(), GetX(), GetY() - read about setting/getting pointers. Keep in mind that PDF generation is pretty similar to printing process. If you generate some content, move pointer back over that content, and generate something new, it will appear on top of content u've 'printed' before.
Cell(), MultiCell(), Write() etc.
Oh, and if u want to be precise with generating PDFs try to avoid converting HTML to PDF. Use pointers instead. It's much more precise, works better with page breaks and u don't need to worry about CSS compatibility.
I am working on a project that allows a user to upload text or content from an HTML page in Japanese and then use their cursor to select words in the text/content to translate into English. However, I would like to be able to expand this functionality to PDF files. Essentially, I'd like the user to be able to submit a PDF file and have the browser render that PDF file in such a way that when the user selects/highlights words in the PDF, the browser can somehow relay what the text of the highlighted section is, such as via javascript, to be then relayed to a PHP variable.
I know there are a lot of posts on stackoverflow asking similar questions (I've spent hours upon hours trying to sort through them all!), but I can't seem to find a definitive answer on whether this is possible. It seems there are lots of options for converting PDF to HTML or extracting text from PDF, but to be quite honest, I'm confused if any of those options are relevant to what I am trying to accomplish. And I know there's a javascript API for Adobe, but I'm under the impression the javascript needs to be embedded in the PDF already, which will not be true if the user is uploading their own PDF files to render. Even if that is possible, it seems there's no native text selection support in the Adobe javascript API....
Is there a straightforward workaround (oxymoron?) to doing this? Again, I want to be able to pass text selected in a PDF to a variable -- the effect is the user highlights words they don't know so those words can be added to a word bank for retrieval in a dictionary.
Let me know if I can be clearer on anything. Thank you!
I think your best bet is to convert the PDF to HTML (see this answers) and then you are already set as you already implemented everything for regular HTML.
I want to give users a preview of certain files on my site and will be using scribd API. Does anyone know how I can access the full file from my server and save the file under a different name , which I will then show to users..Can't think of a way to do this with PHP for .docx and image files...Help is much appreciated.
For "splitting" images, use an image processing library like gd to crop the image (lots of examples to be found on how to do that all over the place). For Word documents, use a library like PHPWord (or one of the other myriad such libraries) to open the document, remove/extract as much text as you need, then save that into a new Word file.
For other file types, find the appropriate method that allows you to manipulate that format, then do whatever you need to do with it.
I have some random PDF that I need to edit. And by edit, to replace an image and some text.
All of the PHP PDF libraries that I saw, create a PDF from scratch.
Is there a way to edit a page of the PDF by replacing images and text ?
There was another recent discussion on this: PHP PDF template library with PDF output? - There is no ready-made library for that.
While technically it's doable (PDF is actually a simple text based registry format, looked through specification once); the internal structure and encoding of text make it awfully difficult to locate and replace text. If you hardcode the object ids, and just create a new 25 1 obj revision for example, then a simple programmatic update might work. But neither FPDF nor TCPDF can do that AFAIK. (Look into FPDI import however.) And if you say you have some "random pdf" it's even less likely.
Try one of the format conversion methods (openoffice to pdf). You could manually convert PDF to OpenDraw probably, and after PHP-based editing convert it back. I'm very unsure if it brings usable results though.