Kevsoft.PDFtk
0.0.57
dotnet add package Kevsoft.PDFtk --version 0.0.57
NuGet\Install-Package Kevsoft.PDFtk -Version 0.0.57
<PackageReference Include="Kevsoft.PDFtk" Version="0.0.57" />
paket add Kevsoft.PDFtk --version 0.0.57
#r "nuget: Kevsoft.PDFtk, 0.0.57"
// Install Kevsoft.PDFtk as a Cake Addin #addin nuget:?package=Kevsoft.PDFtk&version=0.0.57 // Install Kevsoft.PDFtk as a Cake Tool #tool nuget:?package=Kevsoft.PDFtk&version=0.0.57
Kevsoft.PDFtk
.NET Library to drive the awesome pdftk binary.
Inspired by pypdftk from revolunet.
Getting Started
Prerequisites
You'll need to have PDFtk Server installed and the bin directory included within your PATH environment variable.
Windows
If you're on windows this can be installed directly from chocolatey.
choco install pdftk-server
Alternatively you can download the exe from PDFtk from their main site and install it manually.
Linux
This is very dependant on your Linux distribution, but you can install this from the package manager of choice.
Ubuntu
apt-get install pdftk
macOS
I don't have a mac anymore, but it seems you can install this with brew.
brew tap spl/pdftk
brew install pdftk
Installing Package
Kevsoft.PDFtk can be installed directly via the package manager console by executing the following commandlet:
Install-Package Kevsoft.PDFtk
alternative you can use the dotnet CLI.
dotnet add package Kevsoft.PDFtk
Usage
Filling a PDF Form.
Fill a PDF with given data and returns the PDF bytes.
var pdftk = new PDFtk();
var fieldData = new Dictionary<string, string>()
{
["Given Name Text Box"] = "Kevin",
["Language 3 Check Box"] = "Yes"
};
var result = await pdftk.FillFormAsync(
pdfFile: await File.ReadAllBytesAsync("myForm.pdf"),
fieldData: FieldData,
flatten: false,
dropXfa: dropfalse
);
if(result.Success)
{
// Do something with result.Result (bytes[])
}
Get Field Information
Read PDF and output form field statistics.
var pdftk = new PDFtk();
var pdfBytes = await File.ReadAllBytesAsync("Form.pdf");
var result = await pdftk.GetDataFieldsAsync(pdfBytes);
if(result.Success)
{
// Do something with result.Result (IDataField[])
}
IDataField
interface:
public interface IDataField
{
string? FieldValue { get; }
string? FieldValueDefault { get; }
string? FieldType { get; }
string? FieldName { get; }
string? FieldNameAlt { get; }
string? FieldFlags { get; }
string? FieldJustification { get; }
string[] FieldStateOption { get; }
string? FieldMaxLength { get; }
}
Concatenate Multiple PDFs
Merge multiple PDFs into one single PDF and returns the PDF bytes.
var pdftk = new PDFtk();
var result = await pdftk.ConcatAsync(new[]
{
await File.ReadAllBytesAsync("Pdf1.pdf"),
await File.ReadAllBytesAsync("Pdf2.pdf")
});
if(result.Success)
{
// Do something with result.Result (bytes[])
}
Concatenate a List of Pages
Concatenate a list of page ranges into one single file and returns the PDF bytes.
var pdftk = new PDFtk();
var pages = new []{ 1, 5, 6, 7, 10 };
var pdfBytes = await File.ReadAllBytesAsync("Form.pdf");
var result = await pdftk.GetPagesAsync(pdfBytes, pages);
if(result.Success)
{
// Do something with result.Result (bytes[])
}
Splitting a PDF into Many PDFs
Split a single PDF in many pages and return a list of PDF bytes.
var pdftk = new PDFtk();
var pdfBytes = await File.ReadAllBytesAsync("Form.pdf");
var result = await pdftk.SplitAsync(pdfBytes);
if(result.Success)
{
foreach (var (fileName, bytes) in result.Result)
{
// Do something with each pdfPage.
}
}
Getting Total Pages
Return the number of pages for a PDF bytes.
var pdftk = new PDFtk();
var pdfBytes = await File.ReadAllBytesAsync("Form.pdf");
var result = await pdftk.GetNumberOfPagesAsync(pdfBytes);
if(result.Success)
{
// result.Result is the number of pages.
}
Stamping a PDF
Applies a stamp to the PDF file.
var pdftk = new PDFtk();
var result = await pdftk.StampAsync(
await File.ReadAllBytesAsync("MyDocument.pdf"),
await File.ReadAllBytesAsync("Stamp.pdf")
);
if(result.Success)
{
// Do something with result.Result (bytes[])
}
Replace a Page
Replace a page in a PDF with another PDF.
var pdftk = new PDFtk();
var result = await pdftk.ReplacePage(
await File.ReadAllBytesAsync("MyDocument.pdf"),
page: 3,
await File.ReadAllBytesAsync("replacement.pdf")
);
if(result.Success)
{
// Do something with result.Result (bytes[])
}
Replace Pages
Replace multiple pages within a PDF with another PDF.
var pdftk = new PDFtk();
var result = await pdftk.ReplacePage(
await File.ReadAllBytesAsync("MyDocument.pdf"),
startPage: 3,
endPage: 5,
await File.ReadAllBytesAsync("replacement.pdf")
);
if(result.Success)
{
// Do something with result.Result (bytes[])
}
Attach files
Attaches files to a PDF, if page
argument is supplied then files are attached to a given page, if page
argument is not specified then files are attached at document level.
var pdftk = new PDFtk();
var result = await _pdFtk.AttachFiles(
await File.ReadAllBytesAsync("MyDocument.pdf"),
new Dictionary<string, byte[]>
{
["test-file1.txt"] = Encoding.ASCII.GetBytes("Hello"),
["test-file2.txt"] = Encoding.ASCII.GetBytes("World")
},
page: 10 // Optional page to attach files
);
if(result.Success)
{
// Do something with result.Result (bytes[])
}
Extract Attachments
Extracts attachments from a PDF file.
var pdftk = new PDFtk();
var result = await _pdFtk.ExtractAttachments(
await File.ReadAllBytesAsync("MyDocument.pdf"));
if(result.Success)
{
foreach (var (fileName, bytes) in result.Result)
{
// Do something with each attachment.
}
}
Compression/Decompression
These are only useful when you want to edit PDF code in a text editor like vim or emacs. Remove PDF page stream compression by applying the uncompress filter.
Not Implemented yet.
Samples
The samples folder containers examples of how you could use the Kevsoft.PDFtk Library.
WebApplicationFillForm
This is a small razor pages website that has a form where you can fill in a PDF and generate an output for the browser to download.
Contributing
- Issue
- Fork
- Hack!
- Pull Request
This source includes a VSCode Remote Containers to help you get setup fast for development, it comes preinstalled with the prerequisites.
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net5.0 was computed. net5.0-windows was computed. net6.0 is compatible. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 is compatible. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. |
.NET Core | netcoreapp2.0 was computed. netcoreapp2.1 was computed. netcoreapp2.2 was computed. netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
.NET Standard | netstandard2.0 is compatible. netstandard2.1 is compatible. |
.NET Framework | net461 was computed. net462 was computed. net463 was computed. net47 was computed. net471 was computed. net472 was computed. net48 was computed. net481 was computed. |
MonoAndroid | monoandroid was computed. |
MonoMac | monomac was computed. |
MonoTouch | monotouch was computed. |
Tizen | tizen40 was computed. tizen60 was computed. |
Xamarin.iOS | xamarinios was computed. |
Xamarin.Mac | xamarinmac was computed. |
Xamarin.TVOS | xamarintvos was computed. |
Xamarin.WatchOS | xamarinwatchos was computed. |
-
.NETStandard 2.0
- No dependencies.
-
.NETStandard 2.1
- No dependencies.
-
net6.0
- No dependencies.
-
net8.0
- No dependencies.
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
Version | Downloads | Last updated |
---|---|---|
0.0.57 | 43,388 | 3/28/2024 |
0.0.56 | 52,935 | 4/29/2022 |
0.0.54 | 423 | 4/29/2022 |
0.0.51 | 2,421 | 12/27/2021 |
0.0.50 | 274 | 12/17/2021 |
0.0.48 | 448 | 10/24/2021 |
0.0.46 | 362 | 10/24/2021 |
0.0.44 | 427 | 10/24/2021 |
0.0.42 | 353 | 10/22/2021 |
0.0.39 | 362 | 10/17/2021 |
0.0.36 | 325 | 10/17/2021 |
0.0.31 | 5,542 | 6/4/2021 |
0.0.30 | 385 | 5/21/2021 |
0.0.29 | 387 | 5/9/2021 |
0.0.16-preview | 218 | 5/3/2021 |
0.0.15-preview | 210 | 5/3/2021 |
0.0.14-preview | 209 | 5/3/2021 |
0.0.13-preview | 181 | 5/3/2021 |
0.0.12-preview | 188 | 5/3/2021 |
0.0.11-preview | 205 | 5/3/2021 |
0.0.10-preview | 175 | 5/3/2021 |
0.0.9-preview | 190 | 5/3/2021 |
0.0.8-preview | 206 | 5/3/2021 |
0.0.7-preview | 209 | 5/3/2021 |
0.0.6-preview | 195 | 5/3/2021 |
0.0.5-preview | 223 | 5/3/2021 |
0.0.3-preview | 218 | 5/3/2021 |