mirror of
https://github.com/unidoc/unipdf.git
synced 2025-05-01 22:17:29 +08:00
Address review feedback
This commit is contained in:
parent
24dbf33807
commit
b5714c231b
@ -56,7 +56,6 @@ func probeAllObjectsSinglePdf(inputPath string) error {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
defer f.Close()
|
||||
|
||||
pdfReader, err := model.NewPdfReader(f)
|
||||
|
@ -20,7 +20,7 @@ import (
|
||||
// Set environment variables:
|
||||
// UNIDOC_E2E_FORCE_TESTS to "1" to force the tests to execute.
|
||||
// UNIDOC_PASSTHROUGH_TESTDATA to the path of the corpus folder.
|
||||
// UNIDOC_GS_BIN_PATH to the path of the ghosccript binary (gs).
|
||||
// UNIDOC_GS_BIN_PATH to the path of the ghostscript binary (gs).
|
||||
var (
|
||||
forceTest = os.Getenv("UNIDOC_E2E_FORCE_TESTS") == "1"
|
||||
passthroughCorpusFolder = os.Getenv("UNIDOC_PASSTHROUGH_TESTDATA")
|
||||
@ -55,7 +55,7 @@ func TestPassthrough(t *testing.T) {
|
||||
params := passthroughParams{
|
||||
inputPath: fpath,
|
||||
outPath: filepath.Join(tempdir, "1.pdf"),
|
||||
gsValidation: false,
|
||||
gsValidation: len(ghostscriptBinPath) > 0,
|
||||
}
|
||||
err := passthroughSinglePdf(params)
|
||||
if err != nil {
|
||||
|
@ -18,7 +18,7 @@ import (
|
||||
|
||||
// To enable ghostscript validation, the path to the binary needs to be specified.
|
||||
// Set environment variable:
|
||||
// UNIDOC_GS_BIN_PATH to the path of the ghosccript binary (gs).
|
||||
// UNIDOC_GS_BIN_PATH to the path of the ghostscript binary (gs).
|
||||
var (
|
||||
ghostscriptBinPath = os.Getenv("UNIDOC_GS_BIN_PATH")
|
||||
)
|
||||
@ -32,16 +32,17 @@ func validatePdf(path string, password string) (int, error) {
|
||||
}
|
||||
common.Log.Debug("Validating: %s", path)
|
||||
|
||||
var cmd *exec.Cmd
|
||||
params := []string{"-dBATCH", "-dNODISPLAY", "-dNOPAUSE"}
|
||||
if len(password) > 0 {
|
||||
option := fmt.Sprintf("-sPDFPassword=%s", password)
|
||||
cmd = exec.Command(ghostscriptBinPath, "-dBATCH", "-dNODISPLAY", "-dNOPAUSE", option, path)
|
||||
} else {
|
||||
cmd = exec.Command(ghostscriptBinPath, "-dBATCH", "-dNODISPLAY", "-dNOPAUSE", path)
|
||||
params = append(params, fmt.Sprintf("-sPDFPassword=%s", password))
|
||||
}
|
||||
params = append(params, path)
|
||||
|
||||
var out bytes.Buffer
|
||||
var errOut bytes.Buffer
|
||||
var (
|
||||
out bytes.Buffer
|
||||
errOut bytes.Buffer
|
||||
)
|
||||
cmd := exec.Command(ghostscriptBinPath, params...)
|
||||
cmd.Stdout = &out
|
||||
cmd.Stderr = &errOut
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user