Skip to content
Permalink
Browse files

Update README.md

  • Loading branch information...
hhrutter committed Mar 17, 2019
1 parent f5087de commit b112077a350f920d21423d55ea26f8ab15a3d1ae
@@ -8,16 +8,62 @@

![logo](resources/pdfchip3.png)

Package `pdfcpu` is a simple PDF processing library written in [Go](http://golang.org) supporting encryption.
It provides both an API and a CLI. Supported are all versions up to PDF 1.7 (ISO-32000). The current command set includes *validate*, *optimize*, *split*, *merge*, *extract*, *trim*, *stamp*, *watermark*, *import*, *nup*, *grid*, *rotate*, *attach*, *perm*, *encrypt*, *decrypt*, *changeupw*, *changeopw* and the list keeps growing.

Documentation is live at [pdfcpu.io](https://pdfcpu.io). If you go there you will also find examples for every command.
pdfcpu is a simple PDF processing library written in [Go](http://golang.org) supporting encryption.
It provides both an API and a CLI. Supported are all versions up to PDF 1.7 (ISO-32000).

## Motivation

Document interchange is essential in the world we live in. PDF is everywhere and it is not going away anytime soon.<br>
This is an effort to build a PDF processing library from the ground up written in Go with strong support for batch processing via a rich command line. Over time `pdfcpu` aims to support the standard range of PDF processing features and also any interesting use cases that may present themselves along the way.
This is an effort to build a comprehensive PDF processing library from the ground up written in Go. Over time pdfcpu aims to support the standard range of PDF processing features and also any interesting use cases that may present themselves along the way.

<p align="center">
<kbd><img src="resources/gridpdf.png" height="150"></kbd>&nbsp;
<kbd><img src="resources/wmi1abs.png" height="150"></kbd>&nbsp;
<kbd><img src="resources/nup9pdf.png" height="150"></kbd>&nbsp;
<kbd><img src="resources/wmText2Sample.png" height="150"></kbd><br><br>
<kbd><img src="resources/stt31.png" height="150"></kbd>&nbsp;
<kbd><img src="resources/nup4pdf.png" height="150"></kbd>&nbsp;
<kbd><img src="resources/wmi4.png" height="150"></kbd>&nbsp;
<kbd><img src="resources/sti.png" height="150"></kbd><br><br>
<kbd><img src="resources/stp.png" height="150"></kbd>&nbsp;
<kbd><img src="resources/gridimg.png" height="150"></kbd>
</p>

## Focus

The main focus lies on strong support for batch processing and scripting via a rich command line. At the same time pdfcpu wants to make it easy to integrate PDF processing into your Go based backend system by providing a robust command set.

## Command Set

* [validate](https://pdfcpu.io/core/validate)
* [optimize](https://pdfcpu.io/core/optimize)
* [split](https://pdfcpu.io/core/split)
* [merge](https://pdfcpu.io/core/merge)
* [extract](https://pdfcpu.io/extract/extract)
* [trim](https://pdfcpu.io/core/trim)
* [stamp](https://pdfcpu.io/core/stamp)
* [watermark](https://pdfcpu.io/core/watermark)
* [import](https://pdfcpu.io/generate/import)
* [nup](https://pdfcpu.io/core/nup)
* [grid](https://pdfcpu.io/core/grid)
* [rotate](https://pdfcpu.io/core/rotate)
* [attachments](https://pdfcpu.io/attach/attach)
* [permissions](https://pdfcpu.io/encrypt/perm_add)
* [encrypt](https://pdfcpu.io/encrypt/encryptPDF)
* [decrypt](https://pdfcpu.io/encrypt/decryptPDF)
* [change user password](https://pdfcpu.io/encrypt/change_upw)
* [change owner password](https://pdfcpu.io/encrypt/change_opw)

## Documentation

The main entry point is [pdfcpu.io](https://pdfcpu.io).

There you will find explanations of all the commands, their parameters and examples which use the CLI because this makes it easier to understand how the commands work.
Even if you want to dive right into pdfcpu backend integration it is highly recommended to [read the docs](https://pdfcpu.io) first.

### GoDoc

* [pdfcpu package](https://godoc.org/github.com/hhrutter/pdfcpu)
* [pdfcpu api](https://godoc.org/github.com/hhrutter/pdfcpu/pkg/api)

## Status

@@ -43,7 +89,7 @@ Required build version: go1.9 and up
* Feature requests - always welcome!
* Bug fixes - always welcome!
* PRs - also welcome, although I can't promise a merge-in right now.
* `pdfcpu` is stable but still _alpha_ and occasionally undergoing heavy changes.
* pdfcpu is stable but still alpha and occasionally undergoing heavy changes.

### How

@@ -66,7 +112,7 @@ Please note that this project is released with a Contributor [Code of Conduct](C

## Disclaimer

Usage of `pdfcpu` assumes you know about and respect all copyrights of any PDF content you may be processing. This applies to the PDF files as such, their content and in particular all embedded resources like font files or images. Credit goes to [Renee French](https://instagram.com/reneefrench) for creating our beloved Gopher.
Usage of pdfcpu assumes you know about and respect all copyrights of any PDF content you may be processing. This applies to the PDF files as such, their content and in particular all embedded resources like font files or images. Credit goes to [Renee French](https://instagram.com/reneefrench) for creating our beloved Gopher.

## License

@@ -188,6 +188,73 @@ func TestReadSeekerAndWriter(t *testing.T) {

}

func TestTrimUsingReadSeekerCloser(t *testing.T) {

config := pdf.NewDefaultConfiguration()
fileIn := filepath.Join(inDir, "pike-stanford.pdf")
fileOut := filepath.Join(outDir, "test.pdf")
pageSelection := []string{"-2"}

f, err := os.Open(fileIn)
if err != nil {
t.Fatalf("TestTrimUsingReadSeekerCloser Open: %v\n", err)
}

defer func() {
f.Close()
}()

ctx, err := ReadContext(f, "", 0, config)
if err != nil {
t.Fatalf("TestTrimUsingReadSeekerCloser Read: %v\n", err)
}

err = ValidateContext(ctx)
if err != nil {
t.Fatalf("TestTrimUsingReadSeekerCloser Validate: %v\n", err)
}

err = OptimizeContext(ctx)
if err != nil {
t.Fatalf("TestTrimUsingReadSeekerCloser Optimize: %v\n", err)
}

w, err := os.Create(fileOut)
if err != nil {
t.Fatalf("TestTrimUsingReadSeekerCloser Create: %v\n", err)

}

defer func() {

// The underlying bufio.Writer has already been flushed.

// Processing error takes precedence.
if err != nil {
w.Close()
return
}

// Do not miss out on closing errors.
err = w.Close()

}()

ctx.Write.Command = "Trim"

pages, err := pagesForPageSelection(ctx.PageCount, pageSelection)
if err != nil {
t.Fatalf("TestTrimUsingReadSeekerCloser pageSelection: %v\n", err)
}
ctx.Write.SelectedPages = pages

err = WriteContext(ctx, w)
if err != nil {
t.Fatalf("TestTrimUsingReadSeekerCloser Write: %v\n", err)
}

}

func TestMergeUsingReadSeekerCloser(t *testing.T) {

rr := []pdf.ReadSeekerCloser{}
@@ -14,8 +14,8 @@ The available commands are:
stamp add text or image stamp to selected pages
watermark add text or image watermark for selected pages
import import/convert images
nup rearrange pages/images into grid page layout for reduced number of pages
grid rearrange pages/images into grid page layout for enhanced browsing experience
nup rearrange pages/images for reduced number of pages
grid rearrange pages/images for enhanced browsing experience
rotate rotate pages
attach list, add, remove, extract embedded file attachments
perm list, add user access permissions
BIN -23.2 KB (95%) resources/gridimg.png
Binary file not shown.
BIN +360 KB resources/sti.png
Binary file not shown.
BIN +197 KB resources/stp.png
Binary file not shown.
BIN +202 KB resources/stt31.png
Binary file not shown.
BIN +1.26 MB resources/wmi1abs.png
Binary file not shown.
BIN +1 MB resources/wmi4.png
Binary file not shown.

0 comments on commit b112077

Please sign in to comment.
You can’t perform that action at this time.