benoitkugler / pdf Goto Github PK
View Code? Open in Web Editor NEWGolang high level PDF model
License: MIT License
Golang high level PDF model
License: MIT License
This repository doesn't specify a license. Among other issues, this makes it invisible on pkg.go.dev.
EDIT: I am attempting this on wsl2 - in case that makes a difference
I am trying to wrap my head around how a simple form can be filled but I can't seem to make it work.
I tried the examples - ie. cargo test
in formfill but the filled.pdf
has no information entered in the fields?
I have put together a small example using the same template - attempting to fill just one field - but I have the same result, no data entered.
Am I doing something wrong here?
PS: not really a go person but I really need to get some PDF forms filled in automatically
package main
import (
"fmt"
"github.com/benoitkugler/pdf/formfill"
"github.com/benoitkugler/pdf/reader"
"os" // Import the os package
)
var data = []formfill.FDFField{
{T: "z2",
Values: formfill.Values{
V: formfill.FDFText("testing_here"),
},
},
}
func main() {
const path = "original_sample.pdf"
doc, _, err := reader.ParsePDFFile(path, reader.Options{})
if err != nil {
fmt.Fprintf(os.Stderr, "Error: %s\n", err)
os.Exit(1) // Exit the program if there is an error
}
err = formfill.FillForm(&doc, formfill.FDFDict{Fields: data}, true)
if err != nil {
fmt.Fprintf(os.Stderr, "Error: %s\n", err)
os.Exit(1) // Exit the program if there is an error
}
out, err := os.Create("filled.pdf")
if err != nil {
fmt.Fprintf(os.Stderr, "Error: %s\n", err)
os.Exit(1) // Exit the program if there is an error
}
if err = doc.Write(out, nil); err != nil {
fmt.Fprintf(os.Stderr, "Error: %s\n", err)
os.Exit(1) // Exit the program if there is an error
}
}
Is it possible to add examples on how to use the library?
i wanted to have a play with the formfilling.
I have 2 files missing that stop tests in the form filling.
open test/open_action.pdf: no such file or directory
can't open file: open test/ModeleRecuFiscalEditable.pdf: no such file or directory
Is is because the files are too big for git practically ?
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)
}
}
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?
Originally posted by @tommynanny in #4 (comment)
Hi Benoit,
I'm actually trying to fill a CERFA PDF file (https://www.assurance-maladie.ameli.fr/sites/default/files/formulaires/S3116i.pdf) but I'm struggling with this error : missing Form XObject
I've tried to "repair" my file but I load the file only when form is removed. I also check, it works with another PDF file with form.
Do you have any idea about I can solve this issue, please ?
When attempting to fill in the attached file, everything works fine until it attempts to fill the 3.2 Companies' House Reg No
field.
I assume this is due to the '
in the field name but I can't figure out how to escape it. Is this something that is caused by the library or go?
Any advice would be welcome...
Error: unexpected value type for text field: formfill.FDFName
exit status 1
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.