github.com/pdfcpu/pdfcpu@v0.11.1/pkg/api/test/optimize_test.go (about)

     1  /*
     2  Copyright 2020 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/api"
    24  )
    25  
    26  func TestOptimize(t *testing.T) {
    27  	msg := "TestOptimize"
    28  	fileName := "Acroforms2.pdf"
    29  	inFile := filepath.Join(inDir, fileName)
    30  	outFile := filepath.Join(outDir, fileName)
    31  
    32  	// Create an optimized version of inFile.
    33  	if err := api.OptimizeFile(inFile, outFile, nil); err != nil {
    34  		t.Fatalf("%s: %v\n", msg, err)
    35  	}
    36  
    37  	// Create an optimized version of inFile.
    38  	// If you want to modify the original file, pass an empty string for outFile.
    39  	inFile = outFile
    40  	if err := api.OptimizeFile(inFile, "", nil); err != nil {
    41  		t.Fatalf("%s: %v\n", msg, err)
    42  	}
    43  }