Skip to content
Permalink
Browse files

Fix #27, #61, #63

  • Loading branch information...
hhrutter committed Mar 30, 2019
1 parent fc05bdc commit e8cee97675f4453323b27079517e1c16746e1445
Showing with 25 additions and 24 deletions.
  1. +3 −6 README.md
  2. +5 −6 pkg/pdfcpu/utf16.go
  3. +1 −1 pkg/pdfcpu/version.go
  4. +2 −7 pkg/pdfcpu/writePages.go
  5. +2 −1 tiff/README.md
  6. +12 −3 tiff/writer.go
@@ -68,13 +68,10 @@ Even if you want to dive right into pdfcpu backend integration it is highly reco

## Status

[Version: 0.1.22](https://github.com/hhrutter/pdfcpu/releases/tag/v0.1.22)
[Version: 0.1.23](https://github.com/hhrutter/pdfcpu/releases/tag/v0.1.23)

* Support for `go mod`
* Command completion
* `pages insert` inserts empty pages before all selected pages
* `pages remove` removes all selected pages
* Bug fixes #64, #65, #68, #69
* Support for multiline stamps/watermarks such as in `pdfcpu stamp 'This\nis a\nmultiline stamp' test.pdf`
* Fixes #27, #61, #63

## Reminder

@@ -24,7 +24,6 @@ import (

"strings"

"github.com/hhrutter/pdfcpu/pkg/log"
"github.com/pkg/errors"
)

@@ -60,7 +59,7 @@ func IsUTF16BE(b []byte) (ok bool, err error) {

func decodeUTF16String(b []byte) (s string, err error) {

log.Debug.Printf("decodeUTF16String: begin %v\n", b)
//log.Debug.Printf("decodeUTF16String: begin %v\n", b)

// Check for Big Endian UTF-16.
isUTF16BE, err := IsUTF16BE(b)
@@ -83,13 +82,13 @@ func decodeUTF16String(b []byte) (s string, err error) {
// Collect code points.
for i := 0; i < len(b); {

log.Debug.Printf("i=%d\n", i)
//log.Debug.Printf("i=%d\n", i)

val := (uint16(b[i]) << 8) + uint16(b[i+1])

if val <= 0xD7FF || val > 0xE000 && val <= 0xFFFF {
// Basic Multilingual Plane
log.Debug.Println("decodeUTF16String: Basic Multilingual Plane detected")
//log.Debug.Println("decodeUTF16String: Basic Multilingual Plane detected")
u16 = append(u16, val)
i += 2
continue
@@ -108,7 +107,7 @@ func decodeUTF16String(b []byte) (s string, err error) {
}

// Supplementary Planes
log.Debug.Println("decodeUTF16String: Supplementary Planes detected")
//log.Debug.Println("decodeUTF16String: Supplementary Planes detected")
u16 = append(u16, val)
val = (uint16(b[i+2]) << 8) + uint16(b[i+3])
if val < 0xDC00 || val > 0xDFFF {
@@ -131,7 +130,7 @@ func decodeUTF16String(b []byte) (s string, err error) {

s = string(decb)

log.Debug.Printf("decodeUTF16String: end %s %s %s\n", s, hex.Dump(decb), hex.Dump([]byte(s)))
//log.Debug.Printf("decodeUTF16String: end %s %s %s\n", s, hex.Dump(decb), hex.Dump([]byte(s)))

return
}
@@ -24,7 +24,7 @@ import (

const (
// PDFCPUVersion returns the current pdfcpu version.
PDFCPUVersion = "0.1.22"
PDFCPUVersion = "0.1.23"

// PDFCPULongVersion returns pdfcpu's signature.
PDFCPULongVersion = "pdfcpu v" + PDFCPUVersion
@@ -45,11 +45,6 @@ func writePageDict(ctx *Context, ir *IndirectRef, pageDict Dict, pageNr int) err

dictName := "pageDict"

// For extracted pages we do not generate Annotations.
if ctx.ReducedFeatureSet() {
pageDict.Delete("Annots")
}

err := writeDictObject(ctx, objNr, genNr, pageDict)
if err != nil {
return err
@@ -238,11 +233,11 @@ func writePagesDict(ctx *Context, ir *IndirectRef, pageNr *int) (skip bool, writ
kidsOrig := d.ArrayEntry("Kids")

if len(ctx.Write.SelectedPages) > 0 {
// TRIM, REMOVEPAGES
// EXTRACTPAGES, SPLIT, TRIM, REMOVEPAGES
c := int(countOrig.(Integer))
log.Write.Printf("writePagesDict: checking page range %d - %d \n", *pageNr+1, *pageNr+c)
if ctx.Cmd == REMOVEPAGES ||
ctx.Cmd == TRIM && containsSelectedPages(ctx, *pageNr+1, *pageNr+c) {
((ctx.Cmd == EXTRACTPAGES || ctx.Cmd == TRIM || ctx.Cmd == SPLIT) && containsSelectedPages(ctx, *pageNr+1, *pageNr+c)) {
log.Write.Println("writePagesDict: process this subtree")
} else {
log.Write.Println("writePagesDict: skip this subtree")
@@ -1,6 +1,7 @@
# Note
# Note

This package is an improved version of golang.org/x/image/tiff. It uses a consolidated version of `compress/lzw` (hosted at: [github.com/hhrutter/pdfcpu/lzw](https://github.com/hhrutter/pdfcpu/tree/master/lzw)) for compression and also adds support for CMYK.
CCITT Group3/4 compression is supported for reading only.

## Background

@@ -8,6 +8,7 @@ import (
"bytes"
"compress/zlib"
"encoding/binary"
"fmt"
"image"
"io"
"sort"
@@ -348,6 +349,7 @@ func Encode(w io.Writer, m image.Image, opt *Options) error {
var imageLen int

switch compression {

case cNone:
dst = w
// Write IFD offset before outputting pixel data.
@@ -369,13 +371,20 @@ func Encode(w io.Writer, m image.Image, opt *Options) error {
imageLen = d.X * d.Y * 4
}
err = binary.Write(w, enc, uint32(imageLen+8))
if err != nil {
return err
}

case cLZW:
dst = lzw.NewWriter(&buf, true)

case cDeflate:
dst = zlib.NewWriter(&buf)

default:
err = UnsupportedError(fmt.Sprintf("compression value %d", compression))

}

if err != nil {
return err
}

pr := uint32(prNone)

0 comments on commit e8cee97

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