Giter VIP home page Giter VIP logo

kevsoft.pdftk's Introduction

Kevsoft.PDFtk Continuous Integration Workflow install from nuget downloads

.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 pdfPage in result.Result)
   {
       // Do something with each pdfPage (byte[]).
   }
}

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.

Not Implemented yet.

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

  1. Issue
  2. Fork
  3. Hack!
  4. Pull Request

This source includes a VSCode Remote Containers to help you get setup fast for development, it comes preinstalled with the prerequisites.

kevsoft.pdftk's People

Contributors

kevbite avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.