Skip to content

Commit e3358c4

Browse files
committed
PDF 2.0 safe guard, fix #740, bump version
1 parent dce5085 commit e3358c4

28 files changed

+417
-331
lines changed

README.md

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
pdfcpu is a PDF processing library written in [Go](http://golang.org) supporting encryption.
1515
It provides both an API and a CLI. Supported are all versions up to PDF 1.7 (ISO-32000).
1616

17+
Support for PDF 2.0 is basic and ongoing work.
18+
1719
## Motivation
1820

1921
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.
@@ -68,6 +70,8 @@ The main focus lies on strong support for batch processing and scripting via a r
6870
* [ndown](https://pdfcpu.io/generate/ndown)
6971
* [nup](https://pdfcpu.io/generate/nup)
7072
* [optimize](https://pdfcpu.io/core/optimize)
73+
* [pagelayout](https://pdfcpu.io/pagelayout/pagelayout)
74+
* [pagemode](https://pdfcpu.io/pagemode/pagemode)
7175
* [pages](https://pdfcpu.io/pages/pages)
7276
* [permissions](https://pdfcpu.io/encrypt/perm_add)
7377
* [portfolio](https://pdfcpu.io/portfolio/portfolio)
@@ -78,8 +82,9 @@ The main focus lies on strong support for batch processing and scripting via a r
7882
* [split](https://pdfcpu.io/core/split)
7983
* [stamp](https://pdfcpu.io/core/stamp)
8084
* [trim](https://pdfcpu.io/core/trim)
81-
* [validate](https://pdfcpu.io/core/validate)
82-
* [watermark](https://pdfcpu.io/core/watermark)
85+
* [validate](https://pdfcpu.io/core/validate) 👉 now including rudimentory support for PDF 2.0
86+
* [viewerpref](https://pdfcpu.io/viewerpref/viewerpref)
87+
* [watermark](https://pdfcpu.io/core/watermark)
8388

8489
## Documentation
8590

@@ -187,7 +192,7 @@ If processing your PDF with pdfcpu crashes during validation and can be opened b
187192

188193
## Contributors
189194

190-
Thanks goes to these wonderful people:
195+
Thanks 💚 goes to these wonderful people:
191196

192197
<!-- ALL-CONTRIBUTORS-LIST:START - Do not remove or modify this section -->
193198
||||||||

cmd/pdfcpu/process.go

Lines changed: 39 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,7 @@ func processOptimizeCommand(conf *model.Configuration) {
231231
process(cli.OptimizeCommand(inFile, outFile, conf))
232232
}
233233

234-
func processSplitVyPageNumberCommand(inFile, outDir string, conf *model.Configuration) {
234+
func processSplitByPageNumberCommand(inFile, outDir string, conf *model.Configuration) {
235235
if len(flag.Args()) == 2 {
236236
fmt.Fprintln(os.Stderr, "split: missing page numbers")
237237
os.Exit(1)
@@ -274,7 +274,7 @@ func processSplitCommand(conf *model.Configuration) {
274274
outDir := flag.Arg(1)
275275

276276
if mode == "page" {
277-
processSplitVyPageNumberCommand(inFile, outDir, conf)
277+
processSplitByPageNumberCommand(inFile, outDir, conf)
278278
return
279279
}
280280

@@ -666,24 +666,7 @@ func isHex(s string) bool {
666666
return err == nil
667667
}
668668

669-
func processSetPermissionsCommand(conf *model.Configuration) {
670-
if perm != "" {
671-
perm = permCompletion(perm)
672-
}
673-
if len(flag.Args()) != 1 || selectedPages != "" {
674-
fmt.Fprintf(os.Stderr, "usage: %s\n\n", usagePermSet)
675-
os.Exit(1)
676-
}
677-
if perm != "" && perm != "none" && perm != "print" && perm != "all" && !isBinary(perm) && !isHex(perm) {
678-
fmt.Fprintf(os.Stderr, "usage: %s\n\n", usagePermSet)
679-
os.Exit(1)
680-
}
681-
682-
inFile := flag.Arg(0)
683-
if conf.CheckFileNameExt {
684-
ensurePDFExtension(inFile)
685-
}
686-
669+
func configPerm(perm string, conf *model.Configuration) {
687670
if perm != "" {
688671
switch perm {
689672
case "none":
@@ -702,6 +685,27 @@ func processSetPermissionsCommand(conf *model.Configuration) {
702685
conf.Permissions = model.PermissionFlags(p)
703686
}
704687
}
688+
}
689+
690+
func processSetPermissionsCommand(conf *model.Configuration) {
691+
if perm != "" {
692+
perm = permCompletion(perm)
693+
}
694+
if len(flag.Args()) != 1 || selectedPages != "" {
695+
fmt.Fprintf(os.Stderr, "usage: %s\n\n", usagePermSet)
696+
os.Exit(1)
697+
}
698+
if perm != "" && perm != "none" && perm != "print" && perm != "all" && !isBinary(perm) && !isHex(perm) {
699+
fmt.Fprintf(os.Stderr, "usage: %s\n\n", usagePermSet)
700+
os.Exit(1)
701+
}
702+
703+
inFile := flag.Arg(0)
704+
if conf.CheckFileNameExt {
705+
ensurePDFExtension(inFile)
706+
}
707+
708+
configPerm(perm, conf)
705709

706710
process(cli.SetPermissionsCommand(inFile, "", conf))
707711
}
@@ -871,7 +875,7 @@ func addWatermarks(conf *model.Configuration, onTop bool) {
871875
}
872876

873877
if len(flag.Args()) < 3 || len(flag.Args()) > 4 {
874-
fmt.Fprintf(os.Stderr, "%s\n\n", u)
878+
fmt.Fprintf(os.Stderr, "usage: %s\n\n", u)
875879
os.Exit(1)
876880
}
877881

@@ -934,9 +938,9 @@ func processAddWatermarksCommand(conf *model.Configuration) {
934938
}
935939

936940
func updateWatermarks(conf *model.Configuration, onTop bool) {
937-
u := usageWatermarkAdd
941+
u := usageWatermarkUpdate
938942
if onTop {
939-
u = usageStampAdd
943+
u = usageStampUpdate
940944
}
941945

942946
if len(flag.Args()) < 3 || len(flag.Args()) > 4 {
@@ -1107,7 +1111,7 @@ func processImportImagesCommand(conf *model.Configuration) {
11071111

11081112
func processInsertPagesCommand(conf *model.Configuration) {
11091113
if len(flag.Args()) == 0 || len(flag.Args()) > 2 {
1110-
fmt.Fprintf(os.Stderr, "%s\n\n", usagePagesInsert)
1114+
fmt.Fprintf(os.Stderr, "usage: %s\n\n", usagePagesInsert)
11111115
os.Exit(1)
11121116
}
11131117

@@ -1138,7 +1142,7 @@ func processInsertPagesCommand(conf *model.Configuration) {
11381142

11391143
func processRemovePagesCommand(conf *model.Configuration) {
11401144
if len(flag.Args()) == 0 || len(flag.Args()) > 2 || selectedPages == "" {
1141-
fmt.Fprintf(os.Stderr, "%s\n\n", usagePagesRemove)
1145+
fmt.Fprintf(os.Stderr, "usage: %s\n\n", usagePagesRemove)
11421146
os.Exit(1)
11431147
}
11441148

@@ -1529,7 +1533,7 @@ func processRemoveKeywordsCommand(conf *model.Configuration) {
15291533

15301534
func processListPropertiesCommand(conf *model.Configuration) {
15311535
if len(flag.Args()) != 1 || selectedPages != "" {
1532-
fmt.Fprintf(os.Stderr, "usage: %s\n", usageKeywordsList)
1536+
fmt.Fprintf(os.Stderr, "usage: %s\n", usagePropertiesList)
15331537
os.Exit(1)
15341538
}
15351539

@@ -1903,7 +1907,7 @@ func processDumpCommand(conf *model.Configuration) {
19031907

19041908
func processCreateCommand(conf *model.Configuration) {
19051909
if len(flag.Args()) <= 1 || len(flag.Args()) > 3 || selectedPages != "" {
1906-
fmt.Fprintf(os.Stderr, "usage: %s\n\n", usageCreate)
1910+
fmt.Fprintf(os.Stderr, "%s\n\n", usageCreate)
19071911
os.Exit(1)
19081912
}
19091913

@@ -2166,7 +2170,7 @@ func processMultiFillFormCommand(conf *model.Configuration) {
21662170

21672171
func processResizeCommand(conf *model.Configuration) {
21682172
if len(flag.Args()) < 2 || len(flag.Args()) > 3 {
2169-
fmt.Fprintf(os.Stderr, "usage: %s\n", usageResize)
2173+
fmt.Fprintf(os.Stderr, "%s\n", usageResize)
21702174
os.Exit(1)
21712175
}
21722176

@@ -2200,7 +2204,7 @@ func processResizeCommand(conf *model.Configuration) {
22002204

22012205
func processPosterCommand(conf *model.Configuration) {
22022206
if len(flag.Args()) < 3 || len(flag.Args()) > 4 {
2203-
fmt.Fprintf(os.Stderr, "usage: %s\n", usagePoster)
2207+
fmt.Fprintf(os.Stderr, "%s\n", usagePoster)
22042208
os.Exit(1)
22052209
}
22062210

@@ -2236,7 +2240,7 @@ func processPosterCommand(conf *model.Configuration) {
22362240

22372241
func processNDownCommand(conf *model.Configuration) {
22382242
if len(flag.Args()) < 3 || len(flag.Args()) > 5 {
2239-
fmt.Fprintf(os.Stderr, "usage: %s\n", usageNDown)
2243+
fmt.Fprintf(os.Stderr, "%s\n", usageNDown)
22402244
os.Exit(1)
22412245
}
22422246

@@ -2305,7 +2309,7 @@ func processNDownCommand(conf *model.Configuration) {
23052309

23062310
func processCutCommand(conf *model.Configuration) {
23072311
if len(flag.Args()) < 3 || len(flag.Args()) > 4 {
2308-
fmt.Fprintf(os.Stderr, "usage: %s\n", usageCut)
2312+
fmt.Fprintf(os.Stderr, "%s\n", usageCut)
23092313
os.Exit(1)
23102314
}
23112315

@@ -2491,7 +2495,7 @@ func processSetPageModeCommand(conf *model.Configuration) {
24912495
v := flag.Arg(1)
24922496

24932497
if !validate.DocumentPageMode(v) {
2494-
fmt.Fprintln(os.Stderr, "invalid page mode, use one of: UseNone, UseThumb, FullScreen, UseOC, UseAttachments")
2498+
fmt.Fprintln(os.Stderr, "invalid page mode, use one of: UseNone, UseOutlines, UseThumbs, FullScreen, UseOC, UseAttachments")
24952499
os.Exit(1)
24962500
}
24972501

@@ -2513,7 +2517,7 @@ func processResetPageModeCommand(conf *model.Configuration) {
25132517

25142518
func processListViewerPreferencesCommand(conf *model.Configuration) {
25152519
if len(flag.Args()) != 1 || selectedPages != "" {
2516-
fmt.Fprintf(os.Stderr, "usage: %s\n", usageViewerPreferences)
2520+
fmt.Fprintf(os.Stderr, "usage: %s\n", usageViewerPreferencesList)
25172521
os.Exit(1)
25182522
}
25192523

@@ -2526,7 +2530,7 @@ func processListViewerPreferencesCommand(conf *model.Configuration) {
25262530

25272531
func processSetViewerPreferencesCommand(conf *model.Configuration) {
25282532
if len(flag.Args()) != 2 || selectedPages != "" {
2529-
fmt.Fprintf(os.Stderr, "usage: %s\n", usageViewerPreferences)
2533+
fmt.Fprintf(os.Stderr, "usage: %s\n", usageViewerPreferencesSet)
25302534
os.Exit(1)
25312535
}
25322536

@@ -2549,7 +2553,7 @@ func processSetViewerPreferencesCommand(conf *model.Configuration) {
25492553

25502554
func processResetViewerPreferencesCommand(conf *model.Configuration) {
25512555
if len(flag.Args()) != 1 || selectedPages != "" {
2552-
fmt.Fprintf(os.Stderr, "usage: %s\n", usageViewerPreferences)
2556+
fmt.Fprintf(os.Stderr, "usage: %s\n", usageViewerPreferencesReset)
25532557
os.Exit(1)
25542558
}
25552559

0 commit comments

Comments
 (0)