@@ -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
749754func (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.
819829func (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