gofpdf icon indicating copy to clipboard operation
gofpdf copied to clipboard

gofpdf.SetProtection() and gofpdi.ImportPage() + gofpdi.UseImportedTemplate() bug

Open ayvan opened this issue 5 years ago • 6 comments

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.

ayvan avatar Jun 06 '19 10:06 ayvan

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.

jung-kurt avatar Jun 06 '19 12:06 jung-kurt

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.

phpdave11 avatar Jun 06 '19 15:06 phpdave11

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.

jung-kurt avatar Jun 06 '19 15:06 jung-kurt

请问,如何获取导入pdf文件的页面高度、宽度、页面数量等信息?

denept avatar Jul 05 '19 03:07 denept

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?

jung-kurt avatar Jul 06 '19 11:07 jung-kurt

@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

phpdave11 avatar Jul 12 '19 15:07 phpdave11