Add protection make imported PDF page content become blank
Opened this issue · 0 comments
sonnht1409 commented
Hi
I do follow import the pdf page in the example and it works like a charm
package main
import (
"bytes"
"github.com/phpdave11/gofpdf"
"github.com/phpdave11/gofpdf/contrib/gofpdi"
"io"
"io/ioutil"
"net/http"
)
func main() {
var err error
pdf := gofpdf.New("P", "mm", "A4", "")
// Download a PDF into memory
res, err := http.Get("https://tcpdf.org/files/examples/example_038.pdf")
if err != nil {
panic(err)
}
pdfBytes, err := ioutil.ReadAll(res.Body)
res.Body.Close()
if err != nil {
panic(err)
}
// convert []byte to io.ReadSeeker
rs := io.ReadSeeker(bytes.NewReader(pdfBytes))
// Import in-memory PDF stream with gofpdi free pdf document importer
tpl1 := gofpdi.ImportPageFromStream(pdf, &rs, 1, "/TrimBox")
pdf.AddPage()
pdf.SetFillColor(200, 700, 220)
pdf.Rect(20, 50, 150, 215, "F")
// Draw imported template onto page
gofpdi.UseImportedTemplate(pdf, tpl1, 20, 50, 150, 0)
pdf.SetFont("Helvetica", "", 20)
pdf.Cell(0, 0, "Import PDF stream into gofpdf document with gofpdi")
err = pdf.OutputFileAndClose("example.pdf")
if err != nil {
panic(err)
}
}
But when I use SetProtection function, then all content of the imported page was gone
pdf.SetProtection(gofpdf.CnProtectAnnotForms, "1", "a")
As my demand is import a pdf page and set password for the pdf file, please help me walkthrough this