Skip to content

Commit fff3853

Browse files
committed
Fix #657
1 parent 337d257 commit fff3853

File tree

7 files changed

+67
-9
lines changed

7 files changed

+67
-9
lines changed

pkg/api/test/form_test.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,7 @@ func TestRemoveFormFields(t *testing.T) {
5555
}
5656
want := len(ss) - 2
5757

58-
// Remove "firstName1" by id'(=45) and "dob1" by name as per form list output.
59-
if err := api.RemoveFormFieldsFile(inFile, outFile, []string{"dob1", "45"}, conf); err != nil {
58+
if err := api.RemoveFormFieldsFile(inFile, outFile, []string{"dob1", "firstName1"}, conf); err != nil {
6059
t.Fatalf("%s: %v\n", msg, err)
6160
}
6261

pkg/cli/cli.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ func ChangeOwnerPassword(cmd *Command) ([]string, error) {
6060
// ListPermissions of inFile.
6161
func ListPermissions(cmd *Command) ([]string, error) {
6262
return api.ListPermissionsFile(*cmd.InFile, cmd.Conf)
63+
// TODO turn struct into []string
6364
}
6465

6566
// SetPermissions of inFile.
@@ -161,6 +162,7 @@ func ExtractMetadata(cmd *Command) ([]string, error) {
161162
// ListAttachments returns a list of embedded file attachments for inFile.
162163
func ListAttachments(cmd *Command) ([]string, error) {
163164
return api.ListAttachmentsFile(*cmd.InFile, cmd.Conf)
165+
// TODO turn struct into []string
164166
}
165167

166168
// AddAttachments embeds inFiles into a PDF context read from inFile and writes the result to outFile.
@@ -181,6 +183,7 @@ func ExtractAttachments(cmd *Command) ([]string, error) {
181183
// Info gathers information about inFile and returns the result as []string.
182184
func Info(cmd *Command) ([]string, error) {
183185
return api.InfoFiles(cmd.InFiles, cmd.PageSelection, cmd.Conf)
186+
// TODO turn struct into []string
184187
}
185188

186189
// CreateCheatSheetsFonts creates single page PDF cheat sheets for user fonts in current dir.
@@ -191,6 +194,7 @@ func CreateCheatSheetsFonts(cmd *Command) ([]string, error) {
191194
// ListFonts gathers information about supported fonts and returns the result as []string.
192195
func ListFonts(cmd *Command) ([]string, error) {
193196
return api.ListFonts()
197+
// TODO turn struct into []string
194198
}
195199

196200
// InstallFonts installs True Type fonts into the pdfcpu pconfig dir.
@@ -201,6 +205,7 @@ func InstallFonts(cmd *Command) ([]string, error) {
201205
// ListKeywords returns a list of keywords for inFile.
202206
func ListKeywords(cmd *Command) ([]string, error) {
203207
return api.ListKeywordsFile(*cmd.InFile, cmd.Conf)
208+
// TODO turn struct into []string
204209
}
205210

206211
// AddKeywords adds keywords to inFile's document info dict and writes the result to outFile.
@@ -216,6 +221,7 @@ func RemoveKeywords(cmd *Command) ([]string, error) {
216221
// ListProperties returns inFile's properties.
217222
func ListProperties(cmd *Command) ([]string, error) {
218223
return api.ListPropertiesFile(*cmd.InFile, cmd.Conf)
224+
// TODO turn struct into []string
219225
}
220226

221227
// AddProperties adds properties to inFile's document info dict and writes the result to outFile.
@@ -236,6 +242,7 @@ func Collect(cmd *Command) ([]string, error) {
236242
// ListBoxes returns inFile's page boundaries.
237243
func ListBoxes(cmd *Command) ([]string, error) {
238244
return api.ListBoxesFile(*cmd.InFile, cmd.PageSelection, cmd.PageBoundaries, cmd.Conf)
245+
// TODO turn struct into []string
239246
}
240247

241248
// AddBoxes adds page boundaries to inFile's page tree and writes the result to outFile.
@@ -256,6 +263,7 @@ func Crop(cmd *Command) ([]string, error) {
256263
// ListAnnotations returns inFile's page annotations.
257264
func ListAnnotations(cmd *Command) ([]string, error) {
258265
_, ss, err := api.ListAnnotationsFile(*cmd.InFile, cmd.PageSelection, cmd.Conf)
266+
// TODO turn struct into []string
259267
return ss, err
260268
}
261269

@@ -268,6 +276,7 @@ func RemoveAnnotations(cmd *Command) ([]string, error) {
268276
// ListImages returns inFiles embedded images.
269277
func ListImages(cmd *Command) ([]string, error) {
270278
return api.ListImagesFile(cmd.InFiles, cmd.PageSelection, cmd.Conf)
279+
// turn struct into []string
271280
}
272281

273282
// Dump known object to stdout.
@@ -286,6 +295,7 @@ func Create(cmd *Command) ([]string, error) {
286295
// ListFormFields returns inFile's form field ids.
287296
func ListFormFields(cmd *Command) ([]string, error) {
288297
return api.ListFormFieldsFile(cmd.InFiles, cmd.Conf)
298+
// TODO turn struct into []string
289299
}
290300

291301
// RemoveFormFields removes some form fields from inFile.

pkg/pdfcpu/form/fill.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -605,7 +605,12 @@ func fillBtn(
605605
fillDetails func(id, name string, fieldType FieldType, format DataFormat) ([]string, bool, bool),
606606
ok *bool) error {
607607

608-
if len(d.ArrayEntry("Kids")) > 0 {
608+
ff := d.IntEntry("Ff")
609+
if ff != nil && primitives.FieldFlags(*ff)&primitives.FieldPushbutton > 0 {
610+
return nil
611+
}
612+
613+
if len(d.ArrayEntry("Kids")) > 0 && primitives.FieldFlags(*ff)&primitives.FieldRadio > 0 {
609614
if err := fillRadioButtonGroup(ctx, d, id, name, locked, format, fillDetails, ok); err != nil {
610615
return err
611616
}

pkg/pdfcpu/form/form.go

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -332,6 +332,12 @@ func collectRadioButtonGroup(xRefTable *model.XRefTable, d types.Dict, f *Field,
332332
}
333333

334334
func collectBtn(xRefTable *model.XRefTable, d types.Dict, f *Field, fm *FieldMeta) error {
335+
336+
ff := d.IntEntry("Ff")
337+
if ff != nil && primitives.FieldFlags(*ff)&primitives.FieldPushbutton > 0 {
338+
return nil
339+
}
340+
335341
v := types.Name("Off")
336342
if s, found := d.Find("DV"); found {
337343
v = s.(types.Name)
@@ -350,7 +356,9 @@ func collectBtn(xRefTable *model.XRefTable, d types.Dict, f *Field, fm *FieldMet
350356
}
351357

352358
if len(d.ArrayEntry("Kids")) > 0 {
353-
return collectRadioButtonGroup(xRefTable, d, f, fm)
359+
if ff != nil && primitives.FieldFlags(*ff)&primitives.FieldRadio > 0 {
360+
return collectRadioButtonGroup(xRefTable, d, f, fm)
361+
}
354362
}
355363

356364
f.typ = FTCheckBox
@@ -1159,6 +1167,12 @@ func RemoveFormFields(ctx *model.Context, fieldIDsOrNames []string) (bool, error
11591167
}
11601168

11611169
func resetBtn(xRefTable *model.XRefTable, d types.Dict) error {
1170+
1171+
ff := d.IntEntry("Ff")
1172+
if ff != nil && primitives.FieldFlags(*ff)&primitives.FieldPushbutton > 0 {
1173+
return nil
1174+
}
1175+
11621176
v := types.Name("Off")
11631177
if s, found := d.Find("DV"); found {
11641178
v = s.(types.Name)

pkg/pdfcpu/primitives/font.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -314,7 +314,11 @@ func fontFromAcroDict(xRefTable *model.XRefTable, fName, fLang *string, fontID s
314314
return err
315315
}
316316

317-
*fName, *fLang = *fN, *fL
317+
*fName = *fN
318+
319+
if fL != nil {
320+
*fLang = *fL
321+
}
318322

319323
return err
320324
}

pkg/pdfcpu/validate/action.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -566,7 +566,7 @@ func validateNamedActionDict(xRefTable *model.XRefTable, d types.Dict, dictName
566566
}
567567

568568
// Some known non standard named actions
569-
if types.MemberOf(s, []string{"GoToPage", "GoBack", "GoForward", "Find", "Print", "Quit", "FullScreen"}) {
569+
if types.MemberOf(s, []string{"GoToPage", "GoBack", "GoForward", "Find", "Print", "SaveAs", "Quit", "FullScreen"}) {
570570
return true
571571
}
572572

pkg/pdfcpu/validate/annotation.go

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1357,8 +1357,31 @@ func validateAppearDictEntry(xRefTable *model.XRefTable, d types.Dict, dictName
13571357
return err
13581358
}
13591359

1360-
func validateBorderArrayLength(a types.Array) bool {
1361-
return len(a) == 0 || len(a) == 3 || len(a) == 4
1360+
func validateBorderArray(xRefTable *model.XRefTable, a types.Array) bool {
1361+
if len(a) == 0 {
1362+
return true
1363+
}
1364+
if len(a) == 1 || len(a) == 2 || len(a) > 4 {
1365+
return false
1366+
}
1367+
if len(a) == 3 {
1368+
_, err := validateNumberArray(xRefTable, a)
1369+
return err == nil
1370+
}
1371+
1372+
// len = 4
1373+
1374+
o := a[3]
1375+
a1, ok := o.(types.Array)
1376+
if !ok {
1377+
return false
1378+
}
1379+
if len(a1) != 2 {
1380+
return false
1381+
}
1382+
1383+
_, err := validateNumberArray(xRefTable, a1)
1384+
return err == nil
13621385
}
13631386

13641387
func validateAnnotationDictGeneral(xRefTable *model.XRefTable, d types.Dict, dictName string) (*types.Name, error) {
@@ -1424,10 +1447,13 @@ func validateAnnotationDictGeneral(xRefTable *model.XRefTable, d types.Dict, dic
14241447
}
14251448

14261449
// Border, optional, array of numbers
1427-
_, err = validateNumberArrayEntry(xRefTable, d, dictName, "Border", OPTIONAL, model.V10, validateBorderArrayLength)
1450+
a, err := validateArrayEntry(xRefTable, d, dictName, "Border", OPTIONAL, model.V10, nil)
14281451
if err != nil {
14291452
return nil, err
14301453
}
1454+
if !validateBorderArray(xRefTable, a) {
1455+
return nil, errors.Errorf("invalid border array: %s", a)
1456+
}
14311457

14321458
// C, optional array, of numbers, since V1.1
14331459
_, err = validateNumberArrayEntry(xRefTable, d, dictName, "C", OPTIONAL, model.V11, nil)

0 commit comments

Comments
 (0)