unidoc/unipdf-examples

forms/pdf_form_fill_json.go debug logs sometimes pollute JSON output

dhoelle opened this issue · 2 comments

One of the example steps in forms/pdf_form_fill_json.go is to run:

go run pdf_form_fill_json.go input.pdf > formdata.json

Because the example enables debug logging to io.Stdout, any debug messages will wind up in the output JSON file, and will break it.

For example, one of my PDFs produces this output:

$ go run pdf_form_fill_json.go in.pdf > data.json
$ head -6 data.json
[DEBUG]  parser.go:754 Pdf version 1.3
[
    {
        "name": "MyField",
        "value": "foo123"
    },

Perhaps logging should be disabled? Or, alternatively, you could alter the loggers in "github.com/unidoc/unipdf/v3/common" to output to io.Stderr (instead of io.Stdout), and a caller could pipe only the stdout stream to the JSON file.

@dhoelle The examples here are mostly intended for getting started. There are many ways to adapt it to avoid the issue with the extra debug line. One would be to turn off debug mode, or write the JSON to a file.

Note that you can provide your own custom logger where you can write to stderr or handle in any way that it suitable. Just needs to implement our common.Logger interface

Understood - just noting that, as a new user evaluating the library, I originally assumed that the library itself was broken. Others may be similarly confused. Perhaps a comment there would help?

Besides that hiccup, these examples and the library have been fantastic. Thanks!