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

     1  /*
     2  Copyright 2020 The pdfcpu 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 TestTrim(t *testing.T) {
    27  	msg := "TestTrim"
    28  	fileName := "adobe_errata.pdf"
    29  	inFile := filepath.Join(inDir, fileName)
    30  	outFile := filepath.Join(outDir, fileName)
    31  
    32  	// Create a trimmed version of inFile containing odd page numbers only.
    33  	if err := api.TrimFile(inFile, outFile, []string{"odd"}, nil); err != nil {
    34  		t.Fatalf("%s: %v\n", msg, err)
    35  	}
    36  
    37  	// Create a trimmed version of inFile containing the first two pages only.
    38  	// If you want to modify the original file, pass an empty string for outFile.
    39  	inFile = outFile
    40  	if err := api.TrimFile(inFile, "", []string{"1-2"}, nil); err != nil {
    41  		t.Fatalf("%s: %v\n", msg, err)
    42  	}
    43  }