Skip to content
This repository has been archived by the owner on Nov 13, 2021. It is now read-only.

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

Open
ayvan opened this issue Jun 6, 2019 · 6 comments
Labels

Comments

@ayvan
Copy link

ayvan commented Jun 6, 2019

My imports (commit 8060f83):
"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.

@jung-kurt
Copy link
Owner

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.

@phpdave11
Copy link
Contributor

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.

@jung-kurt
Copy link
Owner

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 jung-kurt added the bug label Jun 6, 2019
@denept
Copy link

denept commented Jul 5, 2019

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

@jung-kurt
Copy link
Owner

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?

@phpdave11
Copy link
Contributor

@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

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

4 participants