-
-
Save olliephillips/05d1b4da7a55423485827066eb793ba2 to your computer and use it in GitHub Desktop.
PDF split and recombine script
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"fmt" | |
"github.com/pdfcpu/pdfcpu/pkg/api" | |
_ "github.com/pdfcpu/pdfcpu/pkg/api" | |
"log" | |
"os" | |
"path/filepath" | |
"strings" | |
) | |
func main() { | |
inputTitle := "gofaster-master.pdf" | |
choppedTitle := "./tmp/chop.pdf" | |
blankPage := "page2.pdf" | |
// remove the cover sheet and second page from the master | |
err := api.TrimFile(inputTitle, choppedTitle, []string{"3-216"}, nil) | |
if err != nil { | |
log.Fatalln("err") | |
} | |
// get all nft pdf covers | |
files, err := os.ReadDir("./nft") | |
if err != nil { | |
log.Fatalln(err) | |
} | |
nfts := []string{} | |
for _, file := range files { | |
ext := filepath.Ext(file.Name()) | |
if ext == ".pdf" { | |
nfts = append(nfts, fmt.Sprintf("%s/%s", "./nft", file.Name())) | |
} | |
} | |
fmt.Println(nfts) | |
for _, n := range nfts { | |
number := strings.TrimLeft(n, "./nft/goatspeed-") | |
number = strings.TrimRight(number, ".pdf") | |
err := api.MergeCreateFile([]string{n, blankPage, choppedTitle}, fmt.Sprintf("./out/gofaster-nft-edition-%s.pdf", number), nil) | |
if err != nil { | |
log.Fatalln(err) | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment