github.com/pdfcpu/pdfcpu@v0.11.1/pkg/cli/test/createFromJSON_test.go (about) 1 /* 2 Copyright 2023 The pdf Authors. 3 4 Licensed under the Apache License, Version 2.0 (the "License"); 5 you may not use this file except in compliance with the License. 6 You may obtain a copy of the License at 7 8 http://www.apache.org/licenses/LICENSE-2.0 9 10 Unless required by applicable law or agreed to in writing, software 11 distributed under the License is distributed on an "AS IS" BASIS, 12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 See the License for the specific language governing permissions and 14 limitations under the License. 15 */ 16 17 package test 18 19 import ( 20 "path/filepath" 21 "testing" 22 23 "github.com/pdfcpu/pdfcpu/pkg/cli" 24 "github.com/pdfcpu/pdfcpu/pkg/pdfcpu/model" 25 ) 26 27 /************************************************************** 28 * All form related processing is optimized for Adobe Reader! * 29 **************************************************************/ 30 31 func createPDF(t *testing.T, msg, inFile, inFileJSON, outFile string, conf *model.Configuration) { 32 33 t.Helper() 34 35 // inFile inFileJSON outFile action 36 // --------------------------------------------------------------- 37 // "" jsonFile outfile write outFile 38 // inFile jsonFile "" update (read and write inFile) 39 // inFile jsonFile outFile read inFile and write outFile 40 41 if outFile == "" { 42 outFile = inFile 43 } 44 45 cmd := cli.CreateCommand(inFile, inFileJSON, outFile, conf) 46 if _, err := cli.Process(cmd); err != nil { 47 t.Fatalf("%s %s: %v\n", msg, outFile, err) 48 } 49 50 if err := validateFile(t, outFile, conf); err != nil { 51 t.Fatalf("%s: %v\n", msg, err) 52 } 53 54 } 55 56 func TestCreateSinglePageDemoFormsViaJson(t *testing.T) { 57 58 // Render single page demo forms for export, reset, lock, unlock and fill tests. 59 60 inDirFormDemo := filepath.Join(inDir, "json", "form", "demoSinglePage") 61 outDirFormDemo := outDir 62 63 for _, tt := range []struct { 64 msg string 65 inFileJSON string 66 outFile string 67 }{ 68 69 {"TestFormDemoEN", "english.json", "english.pdf"}, // Core font (Helvetica) 70 {"TestFormDemoUK", "ukrainian.json", "ukrainian.pdf"}, // User font (Roboto-Regular) 71 {"TestFormDemoAR", "arabic.json", "arabic.pdf"}, // User font RTL (Roboto-Regular) 72 {"TestFormDemoSC", "chineseSimple.json", "chineseSimple.pdf"}, // User font CJK (UnifontMedium) 73 {"TestPersonFormDemo", "person.json", "person.pdf"}, // Person Form 74 } { 75 inFileJSON := filepath.Join(inDirFormDemo, tt.inFileJSON) 76 outFile := filepath.Join(outDirFormDemo, tt.outFile) 77 createPDF(t, tt.msg, "", inFileJSON, outFile, conf) 78 } 79 80 // For more comprehensive PDF creation tests please refer to api/test/createFromJSON_test.go 81 }