Skip to content

Instantly share code, notes, and snippets.

@abhilashsajeev
Created January 20, 2023 12:21
Show Gist options
  • Save abhilashsajeev/094cb7797ba9d25b0ededc79384d8662 to your computer and use it in GitHub Desktop.
Save abhilashsajeev/094cb7797ba9d25b0ededc79384d8662 to your computer and use it in GitHub Desktop.
pdf_compresson
package main
import (
"fmt"
pdfcpu "github.com/pdfcpu/pdfcpu"
api "github.com/pdfcpu/pdfcpu/pkg/api"
)
func main() {
inputPath := "input.pdf"
outputPath := "output.pdf"
// Encrypt the PDF
opt := pdfcpu.EncryptOptions{
Owners: pdfcpu.NewUserAccess(pdfcpu.PermPrint | pdfcpu.PermModify),
Users: pdfcpu.NewUserAccess(pdfcpu.PermPrint),
}
pages := []int{1, 3}
err := api.EncryptFilePages(inputPath, outputPath, pages, &opt)
if err != nil {
fmt.Printf("Error encrypting PDF: %v\n", err)
} else {
fmt.Println("PDF encrypted successfully!")
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment