Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

XFA/v8 support #159

Open
wants to merge 22 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
71 changes: 66 additions & 5 deletions .github/workflows/go.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ on:
- main
- development

env:
PDFIUM_EXPERIMENTAL_VERSION: "6392"
PDFIUM_EXPERIMENTAL_GO_VERSION: "1.22"

jobs:
test-cgo:
strategy:
Expand All @@ -18,9 +22,6 @@ jobs:
os: [ ubuntu-latest, macos-latest, windows-latest ]
go: [ "1.20", "1.21", "1.22" ]
pdfium: [ "4849", "6392" ]
env:
PDFIUM_EXPERIMENTAL_VERSION: "6392"
PDFIUM_EXPERIMENTAL_GO_VERSION: "1.22"
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v4
Expand Down Expand Up @@ -92,14 +93,74 @@ jobs:
with:
files: coverage.out
token: ${{ secrets.CODECOV_TOKEN }}

test-cgo-v8:
strategy:
fail-fast: false
matrix:
os: [ ubuntu-latest, macos-latest, windows-latest ]
go: [ "1.20", "1.21", "1.22" ]
pdfium: [ "5692", "6392" ]
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v4

- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: ${{ matrix.go }}
- name: Set up PDFium library with V8 (Linux)
if: matrix.os == 'ubuntu-latest'
run: |
sudo curl -L https://github.com/bblanchon/pdfium-binaries/releases/download/chromium%2F${{ matrix.pdfium }}/pdfium-v8-linux-x64.tgz -o pdfium-v8-linux-x64.tgz && sudo mkdir /opt/pdfium && sudo tar -C /opt/pdfium -xvf pdfium-v8-linux-x64.tgz
sudo rm pdfium-v8-linux-x64.tgz
sudo cp ./.github/workflows/pdfium.pc /usr/lib/pkgconfig/pdfium.pc
- name: Set up PDFium library with V8 (MacOS)
if: matrix.os == 'macos-latest'
run: |
sudo curl -L https://github.com/bblanchon/pdfium-binaries/releases/download/chromium%2F${{ matrix.pdfium }}/pdfium-v8-mac-x64.tgz -o pdfium-v8-mac-x64.tgz && sudo mkdir /opt/pdfium && sudo tar -C /opt/pdfium -xvf pdfium-v8-mac-x64.tgz
sudo rm pdfium-v8-mac-x64.tgz
sudo cp ./.github/workflows/pdfium.pc /usr/local/lib/pkgconfig/pdfium.pc
- name: Set up PDFium library with V8 (Windows)
if: matrix.os == 'windows-latest'
run: |
curl -L https://github.com/bblanchon/pdfium-binaries/releases/download/chromium%2F${{ matrix.pdfium }}/pdfium-v8-win-x64.tgz -o pdfium-v8-win-x64.tgz
mkdir -p D:\opt\pdfium
tar -C D:\opt\pdfium -xvf pdfium-v8-win-x64.tgz
rm pdfium-v8-win-x64.tgz
mkdir D:\opt\pkgconfig
cp ./.github/workflows/pdfium-windows.pc D:\opt\pkgconfig\pdfium.pc
- name: Test all packages with XFA support (Linux & MacOS)
if: matrix.os == 'ubuntu-latest' || matrix.os == 'macos-latest'
run: |
export LD_LIBRARY_PATH="/opt/pdfium/lib"
go test -timeout 30m `go list ./... | grep -v webassembly` -tags pdfium_xfa -exec "env DYLD_LIBRARY_PATH=/opt/pdfium/lib" -v
- name: Test all packages (Linux & MacOS) - Experimental
if: (matrix.os == 'ubuntu-latest' || matrix.os == 'macos-latest') && matrix.pdfium == env.PDFIUM_EXPERIMENTAL_VERSION
run: |
export LD_LIBRARY_PATH="/opt/pdfium/lib"
export IS_EXPERIMENTAL="1"
go test -timeout 30m `go list ./... | grep -v webassembly` -tags pdfium_experimental,pdfium_xfa -exec "env DYLD_LIBRARY_PATH=/opt/pdfium/lib" -v
- name: Test all packages (Windows)
if: matrix.os == 'windows-latest'
run: |
$env:PKG_CONFIG_PATH = 'D:\opt\pkgconfig'
$env:Path += ";D:\opt\pdfium\bin"
go test -timeout 30m $(go list ./... | grep -v webassembly) -tags pdfium_xfa -v
- name: Test all packages (Windows) - Experimental
if: matrix.os == 'windows-latest' && matrix.pdfium == env.PDFIUM_EXPERIMENTAL_VERSION
run: |
$env:PKG_CONFIG_PATH = 'D:\opt\pkgconfig'
$env:Path += ";D:\opt\pdfium\bin"
$env:IS_EXPERIMENTAL = '1'
go test -timeout 30m $(go list ./... | grep -v webassembly) -tags pdfium_experimental,pdfium_xfa -v

test-webassembly:
strategy:
fail-fast: false
matrix:
os: [ ubuntu-latest, macos-latest, windows-latest ]
go: [ "1.20", "1.21", "1.22" ]
env:
PDFIUM_EXPERIMENTAL_GO_VERSION: "1.22"
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v4
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
* Thumbnails
* Attachments
* XFA packet handling
* XFA/v8 form handling
* ViewerRef (print settings)
* Windows features (`FPDF_SetPrintMode`, `FPDF_RenderPage`)
* Transformations (page boxes, clip paths)
Expand All @@ -48,8 +49,7 @@
* Methods that won't be implemented for now:
* fpdf_sysfontinfo.h (probably too complicated)
* Skia methods ([not in pre-built binaries](https://github.com/bblanchon/pdfium-binaries/issues/29))
* XFA/v8 JS
methods ([not in pre-built binaries due to build issues](https://github.com/bblanchon/pdfium-binaries/issues/62))
* v8 methods (`FPDF_GetRecommendedV8Flags`/`FPDF_GetArrayBufferAllocatorSharedInstance`, can't be used in `pdfium-binaries`)
* Useful helpers to make your life easier:
* Get all document metadata
* Get all document bookmarks
Expand Down
7 changes: 2 additions & 5 deletions check_implementation/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,8 @@ var skipMethods = map[string]bool{
"FPDF_FFLRecord": true, // Skia render engine method
"FPDF_RenderPageSkia": true, // Skia render engine method
"FPDF_FFLDrawSkia": true, // Skia render engine method
"FPDF_GetRecommendedV8Flags": true, // V8 method
"FPDF_GetArrayBufferAllocatorSharedInstance": true, // V8 method
"FPDF_BStr_Init": true, // XFA method
"FPDF_BStr_Set": true, // XFA method
"FPDF_BStr_Clear": true, // XFA method
"FPDF_GetRecommendedV8Flags": true, // V8 method, we could implement it, but you can't use it in pdfium-binaries.
"FPDF_GetArrayBufferAllocatorSharedInstance": true, // V8 method, we could implement it, but you can't use it in pdfium-binaries.
}

func main() {
Expand Down
68 changes: 68 additions & 0 deletions enums/enums.go
Original file line number Diff line number Diff line change
Expand Up @@ -475,6 +475,46 @@ const (
FPDF_FORMTYPE_XFA_FOREGROUND FPDF_FORMTYPE = 3
)

type JSPLATFORM_ALERT_BUTTON int

const (
JSPLATFORM_ALERT_BUTTON_OK JSPLATFORM_ALERT_BUTTON = 0 // OK button
JSPLATFORM_ALERT_BUTTON_OKCANCEL JSPLATFORM_ALERT_BUTTON = 1 // OK & Cancel buttons
JSPLATFORM_ALERT_BUTTON_YESNO JSPLATFORM_ALERT_BUTTON = 2 // Yes & No buttons
JSPLATFORM_ALERT_BUTTON_YESNOCANCEL JSPLATFORM_ALERT_BUTTON = 3 // Yes, No & Cancel buttons
JSPLATFORM_ALERT_BUTTON_DEFAULT JSPLATFORM_ALERT_BUTTON = JSPLATFORM_ALERT_BUTTON_OK
)

type JSPLATFORM_ALERT_ICON int

const (
JSPLATFORM_ALERT_ICON_ERROR JSPLATFORM_ALERT_ICON = 0 // Error
JSPLATFORM_ALERT_ICON_WARNING JSPLATFORM_ALERT_ICON = 1 // Warning
JSPLATFORM_ALERT_ICON_QUESTION JSPLATFORM_ALERT_ICON = 2 // Question
JSPLATFORM_ALERT_ICON_STATUS JSPLATFORM_ALERT_ICON = 3 // Status
JSPLATFORM_ALERT_ICON_ASTERISK JSPLATFORM_ALERT_ICON = 4 // Asterisk
JSPLATFORM_ALERT_ICON_DEFAULT JSPLATFORM_ALERT_ICON = JSPLATFORM_ALERT_ICON_ERROR
)

type JSPLATFORM_ALERT_RETURN int

const (
JSPLATFORM_ALERT_RETURN_OK JSPLATFORM_ALERT_RETURN = 1 // OK
JSPLATFORM_ALERT_RETURN_CANCEL JSPLATFORM_ALERT_RETURN = 2 // Cancel
JSPLATFORM_ALERT_RETURN_NO JSPLATFORM_ALERT_RETURN = 3 // No
JSPLATFORM_ALERT_RETURN_YES JSPLATFORM_ALERT_RETURN = 4 // Yes
)

type JSPLATFORM_BEEP int

const (
JSPLATFORM_BEEP_ERROR JSPLATFORM_BEEP = 0 // Error
JSPLATFORM_BEEP_WARNING JSPLATFORM_BEEP = 1 // Warning
JSPLATFORM_BEEP_QUESTION JSPLATFORM_BEEP = 2 // Question
JSPLATFORM_BEEP_STATUS JSPLATFORM_BEEP = 3 // Status
JSPLATFORM_BEEP_DEFAULT JSPLATFORM_BEEP = 4 // Default
)

type FWL_EVENTFLAG int

const (
Expand Down Expand Up @@ -671,3 +711,31 @@ const (
FPDF_ANNOT_AACTION_VALIDATE FPDF_ANNOT_AACTION = 14
FPDF_ANNOT_AACTION_CALCULATE FPDF_ANNOT_AACTION = 15
)

// Pageview event flags
type FXFA_PAGEVIEWEVENT int

const (
FXFA_PAGEVIEWEVENT_POSTADDED FXFA_PAGEVIEWEVENT = 1
FXFA_PAGEVIEWEVENT_POSTREMOVED FXFA_PAGEVIEWEVENT = 3
)

// Definitions for Right Context Menu Features Of XFA Fields
type FXFA_MENU int

const (
FXFA_MENU_COPY FXFA_MENU = 1
FXFA_MENU_CUT FXFA_MENU = 2
FXFA_MENU_SELECTALL FXFA_MENU = 4
FXFA_MENU_UNDO FXFA_MENU = 8
FXFA_MENU_REDO FXFA_MENU = 16
FXFA_MENU_PASTE FXFA_MENU = 16
)

// Definitions for File Type.
type FXFA_SAVEAS int

const (
FXFA_SAVEAS_XML FXFA_SAVEAS = 1
FXFA_SAVEAS_XDP FXFA_SAVEAS = 2
)
3 changes: 3 additions & 0 deletions errors/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,11 @@ var (
ErrPassword = errors.New("4: invalid password")
ErrSecurity = errors.New("5: invalid encryption")
ErrPage = errors.New("6: incorrect page")
ErrXFALoad = errors.New("7: load XFA error")
ErrXFALayout = errors.New("8: layout XFA error")
ErrUnexpected = errors.New("unexpected error")
ErrExperimentalUnsupported = errors.New("this functionality is only supported when using the pdfium_experimental build flag, see https://github.com/klippa-app/go-pdfium#experimental for more information")
ErrWindowsUnsupported = errors.New("this functionality is Windows only")
ErrUnsupportedOnWebassembly = errors.New("this functionality is not supported on Webassembly")
ErrXFAUnsupported = errors.New("this functionality is only supported when using the pdfium_xfa build flag, see https://github.com/klippa-app/go-pdfium#xfa for more information")
)
87 changes: 87 additions & 0 deletions internal/commons/generated.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

21 changes: 21 additions & 0 deletions internal/implementation_cgo/bstr.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package implementation_cgo

// #cgo pkg-config: pdfium
// #include "fpdfview.h"
import "C"
import (
"github.com/google/uuid"
"github.com/klippa-app/go-pdfium/references"
)

func (p *PdfiumImplementation) registerBStr(bstr C.FPDF_BSTR) *BStrHandle {
ref := uuid.New()
handle := &BStrHandle{
handle: bstr,
nativeRef: references.FPDF_BSTR(ref.String()),

Check warning on line 15 in internal/implementation_cgo/bstr.go

View check run for this annotation

Codecov / codecov/patch

internal/implementation_cgo/bstr.go#L11-L15

Added lines #L11 - L15 were not covered by tests
}

p.bStrRefs[handle.nativeRef] = handle

Check warning on line 18 in internal/implementation_cgo/bstr.go

View check run for this annotation

Codecov / codecov/patch

internal/implementation_cgo/bstr.go#L18

Added line #L18 was not covered by tests

return handle

Check warning on line 20 in internal/implementation_cgo/bstr.go

View check run for this annotation

Codecov / codecov/patch

internal/implementation_cgo/bstr.go#L20

Added line #L20 was not covered by tests
}
Loading
Loading