benoitkugler / pdf

Golang high level PDF model
MIT License
22 stars 3 forks source link

"missing TrueType font file" #4

Closed tommynanny closed 1 year ago

tommynanny commented 1 year ago

How can I use a custom font type Courier?

func main() {

    doc, _, err := reader.ParsePDFFile("/Users/tommynanny/Desktop/PDFWorker/template3.pdf", reader.Options{})
    if err != nil {
        fmt.Println(err)
        os.Exit(1)
    }

    // if L := len(doc.Catalog.AcroForm.Flatten()); L != 65 {
    //  fmt.Println(fmt.Errorf("expected 65 fields, got %d", L))
    //  os.Exit(1)
    // }

    err = formfill.FillForm(&doc, formfill.FDFDict{
        Fields: []formfill.FDFField{
            {
                T: "z1",
                Values: formfill.Values{
                    V: formfill.Text("Nanlin Sun"),
                },
            },
        },
    }, true)

    if err != nil {
        fmt.Println(err)    // << --- "missing TrueType font file"
        os.Exit(1)
    }

    out, err := os.Create("/Users/tommynanny/Desktop/PDFWorker/output.pdf")
    if err != nil {
        fmt.Println(err)
        os.Exit(1)
    }

    if err = doc.Write(out, nil); err != nil {
        fmt.Println(err)
        os.Exit(1)
    }
}
tommynanny commented 1 year ago

Also, I realize my pdf full of Japanese characters doesn't seem to work with reader.ParsePDFFile which gives me the error of "unexpected type for Outline item: <nil>". I was wondering if there is a work around?

benoitkugler commented 1 year ago

Hi !

The missing TrueType font file is triggered because the embedded font file is not found on the PDF file. I will relax the code to gracefully accept this scenario, but I suspect there is another issue..

The unexpected type for Outline item: <nil> error is either a bug or comes from a non spec compliant PDF, but Japanese characters should be accepted.. Could you send me your PDF sample so that I give another look ?

benoitkugler commented 1 year ago

e9db32e should fix the missing TrueType font file error

tommynanny commented 1 year ago

Hi !

The missing TrueType font file is triggered because the embedded font file is not found on the PDF file. I will relax the code to gracefully accept this scenario, but I suspect there is another issue..

The unexpected type for Outline item: <nil> error is either a bug or comes from a non spec compliant PDF, but Japanese characters should be accepted.. Could you send me your PDF sample so that I give another look ?

Thanks for the info and for taking a look at this. Here is the pdf that I am working on at the moment: template.pdf

benoitkugler commented 1 year ago

The unexpected type for Outline item: error is either a bug or comes from a non spec compliant PDF, but Japanese characters should be accepted.. Could you send me your PDF sample so that I give another look ?

This is #5, and now fixed. Thanks for the report.