Open ayvan opened 5 years ago
This is an interesting problem. Protection involves encrypting the data stream as it is written to the internal buffer. @phpdave11, do you have any insights into what it would take to apply the encryption to embedded PDF templates? This problem may involve templates in general, not just those that contain embedded PDF pages. If a solution is too complex to handle at this point, we may want to document the limitation and set an error internally if an incompatible embedding method is called.
I don't have any experience with PDF encryption; however, I will do some research to see how difficult it would be to encrypt the objects when they are imported into gofpdf.
This is likely a problem with gofpdf. Don't spend too much time on this unless you have some immediate insights that have escaped me. I need to examine the error this produces to understand what is failing and where.
请问,如何获取导入pdf文件的页面高度、宽度、页面数量等信息?
Excuse me, how can I get the page height, width, page number and other information of the imported pdf file?
I don't see any way to do this in the underlying import package gofpdi. @phpdave11, does your library ever have access to this information?
@denept 我添加了一个gofpdi接口,允许您获取PDF中所有页面的页码,宽度和高度。 这是在gofpdi v1.0.5中添加的。
@jung-kurt I have added an interface to gofpdi that allows you to get the page number, width, and height for all pages in a PDF. This was added in gofpdi v1.0.5.
Example usage to get the width and height of all pages in a PDF:
package main
import (
"fmt"
fpdi "github.com/phpdave11/gofpdi"
)
func main() {
importer := fpdi.NewImporter()
importer.SetSourceFile("example.pdf")
pageSizes := importer.GetPageSizes()
for pageNo := 1; pageNo <= len(pageSizes); pageNo++ {
fmt.Printf("Page: %d\n", pageNo)
width := pageSizes[pageNo]["/MediaBox"]["w"]
height := pageSizes[pageNo]["/MediaBox"]["h"]
fmt.Printf("Width: %f, Height: %f\n", width, height)
}
}
Output:
Page: 1
Width: 595.280000, Height: 841.890000
My imports (commit 8060f8371088d63b5935a6eeb617328705387ace): "github.com/jung-kurt/gofpdf" "github.com/jung-kurt/gofpdf/contrib/gofpdi"
When use gofpdf.SetProtection() I can't use gofpdi.ImportPage() + gofpdi.UseImportedTemplate() - imported template pages not saved to result PDF.