Skip to content

Commit 6a33d81

Browse files
author
jenkins
committed
Added updates for latest PDFTronGo lib update.
1 parent f189db0 commit 6a33d81

File tree

21 files changed

+98278
-97488
lines changed

21 files changed

+98278
-97488
lines changed

pdftron_darwin_arm64.go

Lines changed: 174 additions & 0 deletions
Large diffs are not rendered by default.

pdftron_darwin_x86_64.go

Lines changed: 174 additions & 0 deletions
Large diffs are not rendered by default.

pdftron_linux.go

Lines changed: 174 additions & 0 deletions
Large diffs are not rendered by default.

pdftron_windows.go

Lines changed: 89555 additions & 89381 deletions
Large diffs are not rendered by default.
Lines changed: 139 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,139 @@
1+
//---------------------------------------------------------------------------------------
2+
// Copyright (c) 2001-2023 by Apryse Software Inc. All Rights Reserved.
3+
// Consult LICENSE.txt regarding license information.
4+
//---------------------------------------------------------------------------------------
5+
6+
package main
7+
import (
8+
"testing"
9+
"fmt"
10+
"flag"
11+
"runtime"
12+
. "github.com/pdftron/pdftron-go/v2"
13+
)
14+
15+
var licenseKey string
16+
var modulePath string
17+
18+
func init() {
19+
flag.StringVar(&licenseKey, "license", "", "License key for Apryse SDK")
20+
flag.StringVar(&modulePath, "modulePath", "", "Module path for Apryse SDK")
21+
}
22+
23+
//---------------------------------------------------------------------------------------
24+
// The following sample illustrates how to convert to PDF with virtual printer on Windows.
25+
// It supports several input formats like docx, xlsx, rtf, txt, html, pub, emf, etc. For more details, visit
26+
// https://docs.apryse.com/documentation/windows/guides/features/conversion/convert-other/
27+
//
28+
// To check if ToPDF (or ToXPS) require that PDFNet printer is installed use Convert::RequiresPrinter(filename).
29+
// The installing application must be run as administrator. The manifest for this sample
30+
// specifies appropriate the UAC elevation.
31+
//
32+
// Note: the PDFNet printer is a virtual XPS printer supported on Vista SP1 and Windows 7.
33+
// For Windows XP SP2 or higher, or Vista SP0 you need to install the XPS Essentials Pack (or
34+
// equivalent redistributables). You can download the XPS Essentials Pack from:
35+
// http://www.microsoft.com/downloads/details.aspx?FamilyId=B8DCFFDD-E3A5-44CC-8021-7649FD37FFEE&displaylang=en
36+
// Windows XP Sp2 will also need the Microsoft Core XML Services (MSXML) 6.0:
37+
// http://www.microsoft.com/downloads/details.aspx?familyid=993C0BCF-3BCF-4009-BE21-27E85E1857B1&displaylang=en
38+
//
39+
// Note: Convert.fromEmf and Convert.toEmf will only work on Windows and require GDI+.
40+
//
41+
// Please contact us if you have any questions.
42+
//---------------------------------------------------------------------------------------
43+
44+
// Relative path to the folder containing the test files.
45+
var inputPath = "../../TestFiles/"
46+
var outputPath = "../../TestFiles/Output/"
47+
48+
49+
func ConvertSpecificFormats() bool{
50+
ret := false
51+
52+
53+
// Convert MSWord document to XPS
54+
fmt.Println("Converting DOCX to XPS")
55+
outputFile := "simple-word_2007.xps"
56+
ConvertToXps(inputPath + "simple-word_2007.docx", outputPath + outputFile)
57+
fmt.Println("Saved " + outputFile)
58+
59+
// Start with a PDFDoc to collect the converted documents
60+
pdfdoc := NewPDFDoc()
61+
// Convert the EMF document to PDF
62+
s1 := inputPath + "simple-emf.emf"
63+
64+
fmt.Println("Converting from EMF")
65+
ConvertFromEmf(pdfdoc, s1)
66+
outputFile = "emf2pdf v2.pdf"
67+
pdfdoc.Save(outputPath + outputFile, uint(SDFDocE_remove_unused))
68+
fmt.Println("Saved " + outputFile)
69+
70+
return ret
71+
}
72+
func ConvertToPdfFromFile() bool{
73+
testFiles := [][]string{
74+
{"simple-word_2007.docx","docx2pdf.pdf"},
75+
{"simple-powerpoint_2007.pptx","pptx2pdf.pdf"},
76+
{"simple-excel_2007.xlsx","xlsx2pdf.pdf"},
77+
{"simple-publisher.pub","pub2pdf.pdf"},
78+
{"simple-text.txt","txt2pdf.pdf"},
79+
{ "simple-rtf.rtf","rtf2pdf.pdf"},
80+
{ "simple-emf.emf","emf2pdf.pdf"},
81+
{ "simple-webpage.mht","mht2pdf.pdf"},
82+
{ "simple-webpage.html","html2pdf.pdf"}}
83+
ret := false
84+
85+
if PrinterIsInstalled("PDFTron PDFNet"){
86+
PrinterSetPrinterName("PDFTron PDFNet")
87+
}else if ! PrinterIsInstalled(){
88+
fmt.Println("Installing printer (requires Windows platform and administrator)")
89+
PrinterInstall()
90+
fmt.Println("Installed printer " + PrinterGetPrinterName())
91+
}
92+
93+
for _, testfile := range testFiles {
94+
95+
pdfdoc := NewPDFDoc()
96+
inputFile := testfile[0]
97+
outputFile := testfile[1]
98+
if ConvertRequiresPrinter(inputPath + inputFile){
99+
fmt.Println("Using PDFNet printer to convert file " + inputFile)
100+
}
101+
ConvertToPdf(pdfdoc, inputPath + inputFile)
102+
pdfdoc.Save(outputPath + outputFile, uint(SDFDocE_linearized))
103+
pdfdoc.Close()
104+
fmt.Println("Converted file: " + inputFile + "\nto: " + outputFile)
105+
}
106+
return ret
107+
}
108+
109+
func TestConvertPrint(t *testing.T){
110+
if runtime.GOOS == "windows" {
111+
// The first step in every application using PDFNet is to initialize the
112+
// library. The library is usually initialized only once, but calling
113+
// Initialize() multiple times is also fine.
114+
PDFNetInitialize(licenseKey)
115+
116+
// Demonstrate Convert.ToPdf and Convert.Printer
117+
err := ConvertToPdfFromFile()
118+
if err{
119+
fmt.Println("ConvertFile failed")
120+
}else{
121+
fmt.Println("ConvertFile succeeded")
122+
}
123+
// Demonstrate Convert.[FromEmf, FromXps, ToEmf, ToSVG, ToXPS]
124+
err = ConvertSpecificFormats()
125+
if err{
126+
fmt.Println("ConvertSpecificFormats failed")
127+
}else{
128+
fmt.Println("ConvertSpecificFormats succeeded")
129+
}
130+
fmt.Println("Uninstalling printer (requires Windows platform and administrator)")
131+
PrinterUninstall()
132+
fmt.Println("Uninstalled printer " + PrinterGetPrinterName())
133+
134+
PDFNetTerminate()
135+
fmt.Println("Done.")
136+
}else{
137+
fmt.Println("ConvertPrintTest only available on Windows")
138+
}
139+
}

samples/ConvertTest/Convert_test.go

Lines changed: 30 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import (
88
"testing"
99
"fmt"
1010
"flag"
11-
"runtime"
1211
. "github.com/pdftron/pdftron-go/v2"
1312
)
1413

@@ -21,23 +20,12 @@ func init() {
2120
}
2221

2322
//---------------------------------------------------------------------------------------
24-
// The following sample illustrates how to use the PDF.Convert utility class to convert
25-
// documents and files to PDF, XPS, SVG, or EMF.
23+
// The following sample illustrates how to use the PDF::Convert utility class to convert
24+
// documents and files to PDF, XPS, or SVG, or EMF. The sample also shows how to convert MS Office files
25+
// using our built in conversion.
2626
//
2727
// Certain file formats such as XPS, EMF, PDF, and raster image formats can be directly
28-
// converted to PDF or XPS. Other formats are converted using a virtual driver. To check
29-
// if ToPDF (or ToXPS) require that PDFNet printer is installed use Convert.RequiresPrinter(filename).
30-
// The installing application must be run as administrator. The manifest for this sample
31-
// specifies appropriate the UAC elevation.
32-
//
33-
// Note: the PDFNet printer is a virtual XPS printer supported on Vista SP1 and Windows 7.
34-
// For Windows XP SP2 or higher, or Vista SP0 you need to install the XPS Essentials Pack (or
35-
// equivalent redistributables). You can download the XPS Essentials Pack from:
36-
// http://www.microsoft.com/downloads/details.aspx?FamilyId=B8DCFFDD-E3A5-44CC-8021-7649FD37FFEE&displaylang=en
37-
// Windows XP Sp2 will also need the Microsoft Core XML Services (MSXML) 6.0:
38-
// http://www.microsoft.com/downloads/details.aspx?familyid=993C0BCF-3BCF-4009-BE21-27E85E1857B1&displaylang=en
39-
//
40-
// Note: Convert.fromEmf and Convert.toEmf will only work on Windows and require GDI+.
28+
// converted to PDF or XPS.
4129
//
4230
// Please contact us if you have any questions.
4331
//---------------------------------------------------------------------------------------
@@ -46,51 +34,6 @@ func init() {
4634
var inputPath = "../TestFiles/"
4735
var outputPath = "../TestFiles/Output/"
4836

49-
func ConvertToPdfFromFile() bool{
50-
testFiles := [][]string{
51-
{"simple-word_2007.docx","docx2pdf.pdf", "false"},
52-
{"simple-powerpoint_2007.pptx","pptx2pdf.pdf", "false"},
53-
{"simple-excel_2007.xlsx","xlsx2pdf.pdf", "false"},
54-
{"simple-publisher.pub","pub2pdf.pdf", "true"},
55-
//{"simple-visio.vsd","vsd2pdf.pdf}, // requires Microsoft Office Visio
56-
{"simple-text.txt","txt2pdf.pdf", "false"},
57-
{"simple-rtf.rtf","rtf2pdf.pdf", "true"},
58-
{"butterfly.png","png2pdf.pdf", "false"},
59-
{"simple-emf.emf","emf2pdf.pdf", "true"},
60-
{"simple-xps.xps","xps2pdf.pdf", "false"},
61-
//{"simple-webpage.mht","mht2pdf.pdf", true},
62-
{"simple-webpage.html","html2pdf.pdf", "true"}}
63-
ret := false
64-
65-
if runtime.GOOS == "windows" {
66-
if PrinterIsInstalled("PDFTron PDFNet"){
67-
PrinterSetPrinterName("PDFTron PDFNet")
68-
}else if ! PrinterIsInstalled(){
69-
fmt.Println("Installing printer (requires Windows platform and administrator)")
70-
PrinterInstall()
71-
fmt.Println("Installed printer " + PrinterGetPrinterName())
72-
}
73-
}
74-
75-
for _, testfile := range testFiles {
76-
if runtime.GOOS != "windows" {
77-
if testfile[2] == "true" {
78-
continue
79-
}
80-
}
81-
pdfdoc := NewPDFDoc()
82-
inputFile := testfile[0]
83-
outputFile := testfile[1]
84-
if ConvertRequiresPrinter(inputPath + inputFile){
85-
fmt.Println("Using PDFNet printer to convert file " + inputFile)
86-
}
87-
ConvertToPdf(pdfdoc, inputPath + inputFile)
88-
pdfdoc.Save(outputPath + outputFile, uint(SDFDocE_compatibility))
89-
pdfdoc.Close()
90-
fmt.Println("Converted file: " + inputFile + "\nto: " + outputFile)
91-
}
92-
return ret
93-
}
9437

9538
func ConvertSpecificFormats() bool{
9639
ret := false
@@ -104,15 +47,6 @@ func ConvertSpecificFormats() bool{
10447
pdfdoc.Save(outputPath + outputFile, uint(SDFDocE_remove_unused))
10548
fmt.Println("Saved " + outputFile)
10649

107-
// Convert the EMF document to PDF
108-
if runtime.GOOS == "windows" {
109-
s1 = inputPath + "simple-emf.emf"
110-
fmt.Println("Converting from EMF")
111-
ConvertFromEmf(pdfdoc, s1)
112-
outputFile = "emf2pdf v2.pdf"
113-
pdfdoc.Save(outputPath + outputFile, uint(SDFDocE_remove_unused))
114-
fmt.Println("Saved " + outputFile)
115-
}
11650

11751
// Convert the TXT document to PDF
11852
set := NewObjSet()
@@ -177,6 +111,31 @@ func ConvertSpecificFormats() bool{
177111

178112
return ret
179113
}
114+
func ConvertToPdfFromFile() bool{
115+
testFiles := [][]string{
116+
{"simple-word_2007.docx","docx2pdf.pdf"},
117+
{"simple-powerpoint_2007.pptx","pptx2pdf.pdf"},
118+
{"simple-excel_2007.xlsx","xlsx2pdf.pdf"},
119+
120+
{"simple-text.txt","txt2pdf.pdf"},
121+
{"butterfly.png","png2pdf.pdf"},
122+
{"simple-xps.xps","xps2pdf.pdf"}}
123+
ret := false
124+
125+
126+
for _, testfile := range testFiles {
127+
128+
pdfdoc := NewPDFDoc()
129+
inputFile := testfile[0]
130+
outputFile := testfile[1]
131+
PrinterSetMode(PrinterE_prefer_builtin_converter)
132+
ConvertToPdf(pdfdoc, inputPath + inputFile)
133+
pdfdoc.Save(outputPath + outputFile, uint(SDFDocE_linearized))
134+
pdfdoc.Close()
135+
fmt.Println("Converted file: " + inputFile + "\nto: " + outputFile)
136+
}
137+
return ret
138+
}
180139

181140
func TestConvert(t *testing.T){
182141
// The first step in every application using PDFNet is to initialize the
@@ -198,11 +157,7 @@ func TestConvert(t *testing.T){
198157
}else{
199158
fmt.Println("ConvertSpecificFormats succeeded")
200159
}
201-
if runtime.GOOS == "windows" {
202-
fmt.Println("Uninstalling printer (requires Windows platform and administrator)")
203-
PrinterUninstall()
204-
fmt.Println("Uninstalled printer " + PrinterGetPrinterName())
205-
}
160+
206161
PDFNetTerminate()
207162
fmt.Println("Done.")
208163
}

samples/TestFiles/imagemask.dat

Lines changed: 32 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,32 @@
1-
FFFFFFFFFFFFFFFFFFFFFFFCFFFFFFFF
2-
FFFFFFF87FFFFFFFFFFFFFF83FFFFFFF
3-
FFFFFFF83FFFFFFFFFFFFFF83FFFFFFF
4-
FFFFFFF83FFFFFFFEFFFFFF83FFFFFFF
5-
F3FFFFF83FFFFFFFF8FFFFF83FFFFFFF
6-
FE3FFFF83FFFFC7FFF0FFFF83FFFF87F
7-
FF87FFF83FFFE01FFFE1FFF87FFFC00F
8-
FFF0FFF87FFF0003FFF87FF87FFE007F
9-
FFFC3FF87FFC03FFFFFE0FF87FF80FFF
10-
FFFF07FC7FF03FFFFFFF83FC7FE0FFFF
11-
FFFFC1FC7FC1FFFFFFFFE0FC7F87FFFF
12-
FFFFF07C7F0FFFFFFFFFF87C7E1FFFFF
13-
FFFFFC3C7C7FFFFFFFFFFC1C7CFFFFFF
14-
FFFFFE0C78FFFFFFFFFFFF0C73FFFFFF
15-
FFFFFF8473FFFFFFFFFFFF8067FFFFFF
16-
FFFFFFC06FFFFFFFFFFFFFE04FFFFFFF
17-
FFFFFFF05FFFFFFFE00000000000000F
18-
E00000000000000FFFFFFFFC7FFFF80F
19-
FFFFFFFC7FFFFC1FFF7FFFFC7FFFFC3F
20-
FFBFFFFC7FFFFEFFFFDFFFFC7FFFFFFF
21-
FFCFFFFC7FFFFFFFFFE7FFFC7FFFFFFF
22-
FFE3FFFC7FFFFFFFFFF3FFFC7FFFFFFF
23-
FFF1FFFC7FFFFFFFFFF1FFFC7FFFFFFF
24-
FFF80000000003FFFFF80000000003FF
25-
FFFC7FFC7FFC07FFFFFC7FFC7FFE0FFF
26-
FFFC3FFC7FFF1FFFFFFE3FFC7FFFFFFF
27-
FFFE1FFC7FFFFFFFFFFE1FFC7FFFFFFF
28-
FFFE0FFC7FFFFFFFFFFE03F87FFFFFFF
29-
FFFF03F87FFFFFFFFFFF0FF83FFFFFFF
30-
FFFF7FF81FFFFFFFFFFFFFF81FFFFFFF
31-
FFFFFFF81FFFFFFFFFFFFFF3FFFFFFFF
32-
FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF
1+
FFFFFFFFFFFFFFFFFFFFFFFCFFFFFFFF
2+
FFFFFFF87FFFFFFFFFFFFFF83FFFFFFF
3+
FFFFFFF83FFFFFFFFFFFFFF83FFFFFFF
4+
FFFFFFF83FFFFFFFEFFFFFF83FFFFFFF
5+
F3FFFFF83FFFFFFFF8FFFFF83FFFFFFF
6+
FE3FFFF83FFFFC7FFF0FFFF83FFFF87F
7+
FF87FFF83FFFE01FFFE1FFF87FFFC00F
8+
FFF0FFF87FFF0003FFF87FF87FFE007F
9+
FFFC3FF87FFC03FFFFFE0FF87FF80FFF
10+
FFFF07FC7FF03FFFFFFF83FC7FE0FFFF
11+
FFFFC1FC7FC1FFFFFFFFE0FC7F87FFFF
12+
FFFFF07C7F0FFFFFFFFFF87C7E1FFFFF
13+
FFFFFC3C7C7FFFFFFFFFFC1C7CFFFFFF
14+
FFFFFE0C78FFFFFFFFFFFF0C73FFFFFF
15+
FFFFFF8473FFFFFFFFFFFF8067FFFFFF
16+
FFFFFFC06FFFFFFFFFFFFFE04FFFFFFF
17+
FFFFFFF05FFFFFFFE00000000000000F
18+
E00000000000000FFFFFFFFC7FFFF80F
19+
FFFFFFFC7FFFFC1FFF7FFFFC7FFFFC3F
20+
FFBFFFFC7FFFFEFFFFDFFFFC7FFFFFFF
21+
FFCFFFFC7FFFFFFFFFE7FFFC7FFFFFFF
22+
FFE3FFFC7FFFFFFFFFF3FFFC7FFFFFFF
23+
FFF1FFFC7FFFFFFFFFF1FFFC7FFFFFFF
24+
FFF80000000003FFFFF80000000003FF
25+
FFFC7FFC7FFC07FFFFFC7FFC7FFE0FFF
26+
FFFC3FFC7FFF1FFFFFFE3FFC7FFFFFFF
27+
FFFE1FFC7FFFFFFFFFFE1FFC7FFFFFFF
28+
FFFE0FFC7FFFFFFFFFFE03F87FFFFFFF
29+
FFFF03F87FFFFFFFFFFF0FF83FFFFFFF
30+
FFFF7FF81FFFFFFFFFFFFFF81FFFFFFF
31+
FFFFFFF81FFFFFFFFFFFFFF3FFFFFFFF
32+
FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF

0 commit comments

Comments
 (0)