Skip to content

Commit 5959a40

Browse files
committed
fix: #37
1 parent 7a06ec6 commit 5959a40

2 files changed

Lines changed: 16 additions & 2 deletions

File tree

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ func readPdf(path string) (string, error) {
118118

119119
for pageIndex := 1; pageIndex <= totalPage; pageIndex++ {
120120
p := r.Page(pageIndex)
121-
if p.V.IsNull() {
121+
if p.V.IsNull() || p.V.Key("Contents").Kind() == pdf.Null {
122122
continue
123123
}
124124

page.go

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,8 @@ func (r *Reader) GetStyledTexts() (sentences []Text, err error) {
8787
totalPage := r.NumPage()
8888
for pageIndex := 1; pageIndex <= totalPage; pageIndex++ {
8989
p := r.Page(pageIndex)
90-
if p.V.IsNull() {
90+
91+
if p.V.IsNull() || p.V.Key("Contents").Kind() == Null {
9192
continue
9293
}
9394
var lastTextStyle Text
@@ -525,6 +526,10 @@ func (p Page) GetPlainText(fonts map[string]*Font) (result string, err error) {
525526
}
526527
}()
527528

529+
// Handle in case the content page is empty
530+
if p.V.IsNull() || p.V.Key("Contents").Kind() == Null {
531+
return "", nil
532+
}
528533
strm := p.V.Key("Contents")
529534
var enc TextEncoding = &nopEncoder{}
530535

@@ -747,6 +752,11 @@ func (p Page) GetTextByRow() (Rows, error) {
747752
}
748753

749754
func (p Page) walkTextBlocks(walker func(enc TextEncoding, x, y float64, s string)) {
755+
// Handle in case the content page is empty
756+
if p.V.IsNull() || p.V.Key("Contents").Kind() == Null {
757+
return
758+
}
759+
750760
strm := p.V.Key("Contents")
751761

752762
fonts := make(map[string]*Font)
@@ -817,6 +827,10 @@ func (p Page) walkTextBlocks(walker func(enc TextEncoding, x, y float64, s strin
817827

818828
// Content returns the page's content.
819829
func (p Page) Content() Content {
830+
// Handle in case the content page is empty
831+
if p.V.IsNull() || p.V.Key("Contents").Kind() == Null {
832+
return Content{}
833+
}
820834
strm := p.V.Key("Contents")
821835
var enc TextEncoding = &nopEncoder{}
822836

0 commit comments

Comments
 (0)