Skip to content
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
22,274 changes: 11,274 additions & 11,000 deletions pdftron_darwin_arm64_0.go

Large diffs are not rendered by default.

23,073 changes: 11,905 additions & 11,168 deletions pdftron_darwin_arm64_1.go

Large diffs are not rendered by default.

20,663 changes: 10,383 additions & 10,280 deletions pdftron_darwin_arm64_2.go

Large diffs are not rendered by default.

23,690 changes: 11,911 additions & 11,779 deletions pdftron_darwin_arm64_3.go

Large diffs are not rendered by default.

22,278 changes: 11,276 additions & 11,002 deletions pdftron_darwin_x86_64_0.go

Large diffs are not rendered by default.

23,075 changes: 11,906 additions & 11,169 deletions pdftron_darwin_x86_64_1.go

Large diffs are not rendered by default.

20,665 changes: 10,384 additions & 10,281 deletions pdftron_darwin_x86_64_2.go

Large diffs are not rendered by default.

23,692 changes: 11,912 additions & 11,780 deletions pdftron_darwin_x86_64_3.go

Large diffs are not rendered by default.

22,270 changes: 11,272 additions & 10,998 deletions pdftron_linux_0.go

Large diffs are not rendered by default.

23,073 changes: 11,905 additions & 11,168 deletions pdftron_linux_1.go

Large diffs are not rendered by default.

20,663 changes: 10,383 additions & 10,280 deletions pdftron_linux_2.go

Large diffs are not rendered by default.

23,702 changes: 11,917 additions & 11,785 deletions pdftron_linux_3.go

Large diffs are not rendered by default.

22,270 changes: 11,272 additions & 10,998 deletions pdftron_linux_arm64_0.go

Large diffs are not rendered by default.

23,073 changes: 11,905 additions & 11,168 deletions pdftron_linux_arm64_1.go

Large diffs are not rendered by default.

20,663 changes: 10,383 additions & 10,280 deletions pdftron_linux_arm64_2.go

Large diffs are not rendered by default.

23,702 changes: 11,917 additions & 11,785 deletions pdftron_linux_arm64_3.go

Large diffs are not rendered by default.

22,270 changes: 11,272 additions & 10,998 deletions pdftron_windows_0.go

Large diffs are not rendered by default.

23,073 changes: 11,905 additions & 11,168 deletions pdftron_windows_1.go

Large diffs are not rendered by default.

20,663 changes: 10,383 additions & 10,280 deletions pdftron_windows_2.go

Large diffs are not rendered by default.

23,702 changes: 11,917 additions & 11,785 deletions pdftron_windows_3.go

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions samples/DataExtractionTest/DataExtraction_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -282,14 +282,14 @@ func GenericKeyValueTest() (err error) {
// Exclude the ad on page 2
// These coordinates are in PDF user space, with the origin at the bottom left corner of the page
// Coordinates rotate with the page, if it has rotation applied.
p2ExclusionZones.AddRect(NewRect(166, 47, 562, 222))
p2ExclusionZones.AddRect(NewRect(166.0, 47.0, 562.0, 222.0))
options.AddExclusionZonesForPage(p2ExclusionZones, 2)

p4InclusionZones := NewRectCollection()
p4ExclusionZones := NewRectCollection()
// Only include the article text for page 4, exclude ads and headings
p4InclusionZones.AddRect(NewRect(30, 432, 562, 684))
p4ExclusionZones.AddRect(NewRect(30, 657, 295, 684))
p4InclusionZones.AddRect(NewRect(30.0, 432.0, 562.0, 684.0))
p4ExclusionZones.AddRect(NewRect(30.0, 657.0, 295.0, 684.0))
options.AddInclusionZonesForPage(p4InclusionZones, 4)
options.AddExclusionZonesForPage(p4ExclusionZones, 4)

Expand Down
3 changes: 1 addition & 2 deletions samples/EncTest/Enc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,7 @@ func TestEnc(t *testing.T){
for count < 3{
fmt.Println("A password required to open the document.")
var password string
fmt.Print("Please enter the password: \n")
fmt.Scanf("%s", &password)
password = userPassword
fmt.Println(password)

if doc.InitStdSecurityHandler(password, len(password)){
Expand Down
2 changes: 0 additions & 2 deletions samples/FindReplaceTest/FindReplace_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@

package main
import (
"fmt"
"testing"
"flag"
. "github.com/pdftron/pdftron-go/v2"
Expand Down Expand Up @@ -56,5 +55,4 @@ func TestFindReplace(t *testing.T) {
doc.Close()

PDFNetTerminate()
fmt.Println("Done.")
}
117 changes: 117 additions & 0 deletions samples/HighlightsTest/Highlights_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
//---------------------------------------------------------------------------------------
// Copyright (c) 2001-2026 by Apryse Software Inc. All Rights Reserved.
// Consult LICENSE.txt regarding license information.
//---------------------------------------------------------------------------------------

package main

import (
"flag"
"fmt"
"math"
"strings"
"testing"

. "github.com/pdftron/pdftron-go/v2"
)

var licenseKey string
var modulePath string

func init() {
flag.StringVar(&licenseKey, "license", "", "License key for Apryse SDK")
flag.StringVar(&modulePath, "modulePath", "", "Module path for Apryse SDK")
}

// ---------------------------------------------------------------------------------------
// This sample illustrates the basic text highlight capabilities of PDFNet.
// It simulates a full-text search engine that finds all occurrences of the word 'Federal'.
// It then highlights those words on the page.
//
// Note: The TextSearch class is the preferred solution for searching text within a single
// PDF file. TextExtractor provides search highlighting capabilities where a large number
// of documents are indexed using a 3rd party search engine.
// --------------------------------------------------------------------------------------

func TestHighlights(t *testing.T) {
// The first step in every application using PDFNet is to initialize the
// library and set the path to common PDF resources. The library is usually
// initialized only once, but calling Initialize() multiple times is also fine.
PDFNetInitialize(licenseKey)

// Relative path to the folder containing the test files.
inputPath := "../TestFiles/paragraphs_and_tables.pdf"
outputPath := "../TestFiles/Output/"

// Sample code showing how to use high-level text highlight APIs.
doc := NewPDFDoc(inputPath)
doc.InitSecurityHandler()

page := doc.GetPage(1)
if !page.IsValid() {
PDFNetTerminate()
t.Fatal("Page not found.")
}

txt := NewTextExtractor()
txt.Begin(page) // read the page

// Do not dehyphenate; that would interfere with character offsets
dehyphen := false

// Retrieve the page text
pageText := txt.GetAsText(dehyphen)

// Simulating a full-text search engine that finds all occurrences of the word 'Federal'.
// In a real application, plug in your own search engine here.
searchText := "Federal"

charRanges := NewVectorCharRange()
ofs := strings.Index(pageText, searchText)
for ofs != -1 {
cr := NewCharRange()
cr.SetIndex(ofs)
cr.SetLength(len(searchText))
charRanges.Add(cr)
next := strings.Index(pageText[ofs+1:], searchText)
if next == -1 {
break
}
ofs = ofs + 1 + next
}

// Retrieve Highlights object and apply annotations to the page
hlts := txt.GetHighlights(charRanges)
hlts.Begin(doc)

for hlts.HasNext() {
quads := hlts.GetCurrentQuads()
count := int(quads.Size())
for i := 0; i < count; i++ {
q := quads.Get(i)

// Each quad has 4 points: q.P1, q.P2, q.P3, q.P4
x1 := math.Min(math.Min(q.GetP1().GetX(), q.GetP2().GetX()), math.Min(q.GetP3().GetX(), q.GetP4().GetX()))
x2 := math.Max(math.Max(q.GetP1().GetX(), q.GetP2().GetX()), math.Max(q.GetP3().GetX(), q.GetP4().GetX()))
y1 := math.Min(math.Min(q.GetP1().GetY(), q.GetP2().GetY()), math.Min(q.GetP3().GetY(), q.GetP4().GetY()))
y2 := math.Max(math.Max(q.GetP1().GetY(), q.GetP2().GetY()), math.Max(q.GetP3().GetY(), q.GetP4().GetY()))

highlight := HighlightAnnotCreate(
doc.GetSDFDoc(),
NewRect(x1, y1, x2, y2),
)
highlight.RefreshAppearance()
page.AnnotPushBack(highlight)

fmt.Printf("[%.2f, %.2f, %.2f, %.2f]\n", x1, y1, x2, y2)
}

hlts.Next()
}
doc.Save(outputPath+"search_highlights.pdf", uint(SDFDocE_linearized))

doc.Close()

PDFNetTerminate()
fmt.Println("Done.")
}
Loading