pdftk | An unofficial fork of Pdftk | Document Editor library
kandi X-RAY | pdftk Summary
kandi X-RAY | pdftk Summary
The excellent Pdftk toolkit is only rarely updated, and the upstream maintainer has been unresponsive to email for at least a year, hence this repository that collects together a few bug fixes and other small improvements. The code here is based on Pdftk 1.45, which was released in December 2012. Since it is awkward to build Pdftk from source on OS X, we also maintain a binary installer package for OS X. -- Robin Houston, January 2013.
Support
Quality
Security
License
Reuse
Top functions reviewed by kandi - BETA
- Gets a single font
- Reads the dict
- Creates a range item for an index
- Read bytes into the stream
- Adds an imported page to the output
- Translates a PRDictionary to a PdfDictionary
- Translate a PR - object to a Pdf - object
- Translate a PRIndirectReference to a PdfIndirectReference
- Replies the barcode of the barcode
- Writes the font to the document
- Types 1
- Returns an image that displays the bars without the given color
- Creates an image that displays the bars of the specified code
- Fill the fields
- Adds an element to the page
- Gets the viewer preferences
- Reads the font data
- Gets a new text field
- Encodes the given data into an OutputStream
- Writes the font to the specified writer
- Read font metrics
- Sets a field property
- Replies the barcode position
- Replies the barcode in the content
- Converts a string into a barcode
- Stream data to a stream
pdftk Key Features
pdftk Examples and Code Snippets
Community Discussions
Trending Discussions on pdftk
QUESTION
I am using the PDFtk to remove last 2 pages of a bunch of PDF from a specific folder.
For removing it individually on a file, this code works perfectly fine as the last two pages are removed from original.pdf and a newly created reduced.pdf copy is created without the last two pages
...ANSWER
Answered 2022-Mar-13 at 12:07The task can be done with a batch file with only following single command line:
QUESTION
I'm using nodejs
and I'm processing PDFs. One thing I'd like to do is to outline all the fonts of the PDF (so that they are not selectable with the mouse cursor afterwards).
I tried the pdftk
's flatten
command (using a node wrapper), but I did not get what I wanted.
I may have a track in using inkscape
(command line), but I'm not even sure about how to do it. I really am looking for the easiest way to do that using nodejs
.
There might also be a track using ghostscript: https://stackoverflow.com/a/28798374/11348232. One notable thing to notice is that I don't use files on disk, but Buffer
objects, so it'd be painful to save the PDF locally then use the gs
command.
Thanks a lot.
...ANSWER
Answered 2022-Feb-25 at 09:04I finally followed @KenS way:
QUESTION
I have tried to use pdftk
to fill a PDF form with text and images.
Filling out text fields works fine, but it cant seem to add an image to an PDF form image field.
Is there any way to add an image to a form field with pdftk
? Or any other way to do this?
Heres my pdf: https://easyupload.io/b1emej
Heres my code
...ANSWER
Answered 2022-Jan-27 at 13:54It is possible to carry an image via FDF however the aim of Forms Data is to carry simple text objects such as text field entries or other comments. So for an image it needs to be as separate annotation stamp and unsure if that can be attached to a field as such.
Here is a stamp added to the "clean" file ( note it is "under" the field entries)
QUESTION
I am working on editing a PDF
form/template in Ruby On Rails application.
I want to populate some of form fields with data from database and make few fields editable to take the input from user.
I found PDFtf
but I read that this is very old library and hardly works with the new Linux/Mac versions.
I checked https://www.adamalbrecht.com/blog/2014/01/31/pre-filling-pdf-form-templates-in-ruby-on-rails-with-pdftk/
ANSWER
Answered 2022-Jan-20 at 22:48Form fields are in FDF/XFDF files (very similar to a PDF as they are the data overlay) they are old hat but in constant use daily the library you link to is maintained this year and last stable release was October 2020 it is the old proprietary Adobe Forms methodology that is very much stable since turn of the century.
see https://github.com/jkraemer/pdf-forms#fdfxfdf-creation for how it uses PDFtk to adjust the FDFs
It does not matter which language or library you use the data is best kept static . I can write PDF via cmd so i guess fdf as text or xfdf as xml is just as easy.
best kept in simpler FDF format since for users its easiest to use a PDF/FDF reader / forms modifier such as Acrobat, Tracker or Foxit etc.
You can use any of those API s or just as simply use a find and replace method but its easiest to use a paid tool like PDFTK that can resolve the backgound mathematics. $79 for your server version will pay for itself quickly. Even $3 for a personal pro version is a bargain.
For a Ruby specific method using PDFtk last updated 28 Dec 2021 see https://github.com/ruby-journal/nguyen
QUESTION
I'm trying to use the update_info
command in order to add some bookmarks to an existing pdf's metadata using pdftk
and powershell.
I first dump the metadata into a file as follows:
pdftk .\test.pdf dump_data > test.info
Then, I edit the test.info
file by adding the bookmarks, I believe I am using the right syntax. I save the test.info
file and attempt to write the metadata to a new pdf file using update_info
:
pdftk test.pdf update_info test.info output out.pdf
Unfortunately, I get a warning as follows:
pdftk Warning: unexpected case 1 in LoadDataFile(); continuing
out.pdf
is generated, but contains no bookmarks. Just to be sure it is not a syntax problem, I also ran it without editing the metadata file, by simply overwriting the same metadata. I still got the same warning.
Why is this warning occurring? Why are no bookmarks getting written to my resulting pdf?
...ANSWER
Answered 2022-Jan-18 at 15:15using redirection in that fashion
pdftk .\test.pdf dump_data > test.info
will cause this known problem by building wrong file structure, so change to
QUESTION
After some initial problems I was finally able to set up a self-hosted GitLab Runner on my personal laptop.
I'm now looking into how this runner works and how I can tweak it's environment to my needs. I modified the YML file to run a simple command echoing the PATH
environment variable:
ANSWER
Answered 2021-Dec-30 at 16:53There's a few reasons why environment variables may be different. Chiefly:
- The user account being used by the runner
- The powershell profile you're using locally (which will not be used by the runner)
- Any changes to environment variables made in the runner's config.toml
- environment variables changed/added through CI/CD variables.
The effective PATH
is a combination of both the system environment variables as well as user environment variables. For your runner to reflect the same environment variables that you see locally when running powershell, you must use the same user account, otherwise user environment variables you're seeing may be missing/different based on the user account.
One way to fix differences that may be caused by the user would be to change the user used by the gitlab service
To change the user used by the GitLab runner, go to services -> gitlab-runner -> (right-click) properties -> Log On tab and choose the account the runner should use.
Alternatively, specify this when installing the runner:
QUESTION
I was given a .zip file that had an external library called Python PDF Toolkit, often abbreviated as pdftk or pypdftk.
To my current knowledge, this external dependency was built on a EC2 instance of CentOS6, because the pdftk has its own dependency called libgcj.
As you can see from the image, most of the files are Unix Executable Files, and are missing their file extensions.
Will this create problems in Lambda? I believe the pdftk needs to be uploaded as a Lambda Layer to help extend the standard core Python Library.
If this will create problems executing Lambda, are there any steps I can take to find the file extensions?
Lastly, I can edit this question and add the code within these files if you believe that will help.
WHEEL
...ANSWER
Answered 2021-Nov-22 at 21:09pypdftk is a wrapper for pdftk binary. So you need 2 things:
- Install the pdftk binary as a Lambda Layer. For more details look here.
- You also need the python code. It seems that this is only a python file. You can either copy it directly or your code or install it with pip. It should work with python 3.
You have been provided with a wheel package. Chances are that it won't work with lambda and python 3, although it isn't impossible to properly configure everything. It should be easier to install pypdftk and binary dependencies from scratch.
QUESTION
EDIT 3:
So the problem may likely be in the set-up and configuration of my Lambda Layer Dependencies. I have a /bin directory containing 3 files:
- lambdazip.sh
- pdftk
- libgcj.so.10
pdftk is a pdf library, and libgcj is a dependency for PDFtk.
lambdazip.sh seems to set & modify PATH Variables.
I have tried uploading all 3 as 1 lambda layer.
I have tried uploading all 3 as 3 separate lambda layers.
I have not tried customizing the .zip file names, I know sometimes the Lambda Layer wants you to name the .zip file a specific name dependent on the language.
I have not tried customizing the "compatible architectures" & "compatible runtime" lambda layer settings.
EDIT 2:
I tried renaming the Lambda Layer as Python.zip because I heard that sometimes you need a specific naming convention for the Lambda Layer to work correctly. This also failed & produced the same error.
EDIT:
I have tried pulling the .py files out of the /surveys directory, so when they are zipped, they are in the root folder, but I still receive the same error: Runtime.ImportModuleError: Unable to import module 'lambda_function': No module named 'surveys
Which files do I need to zip? Do I need to move certain files to the root?
I learned that I had accidentally zipped the directory which commonly caused this error.
I needed to zip the contents of the directory, which is a common solution.
Unfortunately this did not work for me.
I have a Lambda Function, and the code I have uploaded is a zipped folder of my /Archive directory.
From what I understand, many of the people who run into this "[ERROR] Runtime.ImportModuleError: Unable to import module 'lambda_function':" have issues because of their Lambda Handler.
My Lambda handler is: lambda_function.lambda_handler so this doesn't appear to be my issue.
Another common problem I've noticed on Stackoverflow, appears to be with how people are compressing & zipping the files they upload to the Lambda Function.
Do I need to move my lambda_function.py? Sometimes this CloudWatch error occurs because the lambda_function.py is not in the ROOT directory.
Does my survey directory need to move?
I think the folders & directories I have here may be causing my issue.
Do I need to zip the directories individually?
Can I resolve this error by Zipping the entire project?
For more information, I also have a Lambda Layer for PDF Toolkit, called pyPDFtk in the codebase. In that Lambda layer is a zipped /bin with binaries inside.
If there is anything I can alter/change within my code or AWS configuration, please let me know, and I can return new CloudWatch error logs for you.
lambda_function.py
...ANSWER
Answered 2021-Nov-14 at 10:26I tried to replicate the issue, but it all works as expected. My setup was (Lambda with Python 3.9):
It seems to me that either your directory struct is not what you posted in the question. Similarly your real code that you present in SO could be different.
QUESTION
I would like to include the result of a string concatenation command as part of a call using the pdftk
command line tool. Here's what I tried:
ANSWER
Answered 2021-Nov-15 at 09:49In this kind of situation invoke-expression
is your friend:
QUESTION
I have several python executables available from within a default powershell prompt as shown by where.exe python
:
ANSWER
Answered 2021-Oct-23 at 21:36What Windows will execute is not trivial, since it might depend on the API used.
One of them is CreateProcessW:
- The directory from which the application loaded.
- The current directory for the parent process.
- The 32-bit Windows system directory. Use the GetSystemDirectory function to get the path of this directory.
- The 16-bit Windows system directory. There is no function that obtains the path of this directory, but it is searched. The name of this directory is System.
- The Windows directory. Use the GetWindowsDirectory function to get the path of this directory.
- The directories that are listed in the PATH environment variable. Note that this function does not search the per-application path specified by the App Paths registry key. To include this per-application path in the search sequence, use the ShellExecute function.
Since Windows Vista, the environment variable %NoDefaultCurrentDirectoryInExePath% configures whether or not the current directory should be searched (Source: MSDN).
Also: if you just run python
without an extension, the environment variable %PathExt% is used to find executable extensions. (Source: MSDN).
The default value for the PATHEXT variable is: .COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH;.MSC
A great tool for troubleshooting such issues is SysInternals Process Monitor. Set a filter for "path contains python" (not python.exe) and you'll see the exact search order. It will report "NO SUCH FILE" for directories which do not contain a Python executable.
Also note: the search order for DLLs may be different.
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
Vulnerabilities
No vulnerabilities reported
Install pdftk
You can use pdftk like any standard Java library. Please include the the jar files in your classpath. You can also use any IDE and you can run and debug the pdftk component as you would do with any other Java program. Best practice is to use a build tool that supports dependency management such as Maven or Gradle. For Maven installation, please refer maven.apache.org. For Gradle installation, please refer gradle.org .
Support
Reuse Trending Solutions
Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items
Find more librariesStay Updated
Subscribe to our newsletter for trending solutions and developer bootcamps
Share this Page