-
Notifications
You must be signed in to change notification settings - Fork 101
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
136 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
/* | ||
* PDF/A-3 optimization (compression) example. | ||
* | ||
* Run as: go run pdfa3_apply_standard.go <input.pdf> <output.pdf> | ||
*/ | ||
|
||
package main | ||
|
||
import ( | ||
"fmt" | ||
"log" | ||
"os" | ||
"time" | ||
|
||
"github.com/unidoc/unipdf/v3/common/license" | ||
"github.com/unidoc/unipdf/v3/model" | ||
"github.com/unidoc/unipdf/v3/model/pdfa" | ||
) | ||
|
||
func init() { | ||
// Make sure to load your metered License API key prior to using the library. | ||
// If you need a key, you can sign up and create a free one at https://cloud.unidoc.io | ||
err := license.SetMeteredKey(os.Getenv(`UNIDOC_LICENSE_API_KEY`)) | ||
if err != nil { | ||
panic(err) | ||
} | ||
} | ||
|
||
func main() { | ||
args := os.Args | ||
if len(args) < 3 { | ||
fmt.Printf("Usage: %s INPUT_PDF_PATH OUTPUT_PDF_PATH", os.Args[0]) | ||
return | ||
} | ||
inputPath := args[1] | ||
outputPath := args[2] | ||
|
||
// Initialize starting time. | ||
start := time.Now() | ||
|
||
// Create reader. | ||
reader, file, err := model.NewPdfReaderFromFile(inputPath, nil) | ||
if err != nil { | ||
log.Fatalf("Fail: %v\n", err) | ||
} | ||
defer file.Close() | ||
|
||
// Generate a PDFWriter from PDFReader. | ||
pdfWriter, err := reader.ToWriter(nil) | ||
if err != nil { | ||
log.Fatalf("Fail: %v\n", err) | ||
} | ||
|
||
// Apply standard PDF/A-3B. | ||
pdfWriter.ApplyStandard(pdfa.NewProfile3B(nil)) | ||
|
||
// Create output file. | ||
err = pdfWriter.WriteToFile(outputPath) | ||
if err != nil { | ||
log.Fatalf("Fail: %v\n", err) | ||
} | ||
|
||
duration := float64(time.Since(start)) / float64(time.Millisecond) | ||
fmt.Printf("Processing time: %.2f ms\n", duration) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
/* | ||
* PDF/A-3 optimization (compression) example. | ||
* | ||
* Run as: go run pdfa3_validate_standard.go <input.pdf> | ||
*/ | ||
|
||
package main | ||
|
||
import ( | ||
"fmt" | ||
"log" | ||
"os" | ||
"time" | ||
|
||
"github.com/unidoc/unipdf/v3/common/license" | ||
"github.com/unidoc/unipdf/v3/model" | ||
"github.com/unidoc/unipdf/v3/model/pdfa" | ||
) | ||
|
||
func init() { | ||
// Make sure to load your metered License API key prior to using the library. | ||
// If you need a key, you can sign up and create a free one at https://cloud.unidoc.io | ||
err := license.SetMeteredKey(os.Getenv(`UNIDOC_LICENSE_API_KEY`)) | ||
if err != nil { | ||
panic(err) | ||
} | ||
} | ||
|
||
func main() { | ||
args := os.Args | ||
if len(args) < 2 { | ||
fmt.Printf("Usage: %s INPUT_PDF_PATH", os.Args[0]) | ||
return | ||
} | ||
inputPath := args[1] | ||
|
||
// Initialize starting time. | ||
start := time.Now() | ||
|
||
// Create reader. | ||
inputFile, err := os.Open(inputPath) | ||
if err != nil { | ||
log.Fatalf("Fail: %v\n", err) | ||
} | ||
defer inputFile.Close() | ||
|
||
detailedReader, err := model.NewCompliancePdfReader(inputFile) | ||
if err != nil { | ||
log.Fatalf("Fail: %v\n", err) | ||
} | ||
|
||
// Apply standard PDF/A-3. | ||
standards := []model.StandardImplementer{ | ||
pdfa.NewProfile3A(nil), | ||
pdfa.NewProfile3B(nil), | ||
pdfa.NewProfile3U(nil), | ||
} | ||
|
||
// Iterate over input standards and check if the document passes its requirements. | ||
for _, standard := range standards { | ||
if err = standard.ValidateStandard(detailedReader); err != nil { | ||
fmt.Printf("Input document didn't pass the standard: %s - %v\n", standard.StandardName(), err) | ||
} | ||
} | ||
|
||
duration := float64(time.Since(start)) / float64(time.Millisecond) | ||
fmt.Printf("Processing time: %.2f ms\n", duration) | ||
} |