File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -2,6 +2,7 @@ package docreader
22
33import (
44 "fmt"
5+ "strings"
56
67 "github.com/ledongthuc/pdf"
78)
@@ -21,7 +22,7 @@ func (r *PdfReader) ReadText(filePath string) (string, error) {
2122 // 获取总页数
2223 totalPages := reader .NumPage ()
2324
24- var content string
25+ var content strings. Builder
2526
2627 // 逐页读取文本
2728 for pageNum := 1 ; pageNum <= totalPages ; pageNum ++ {
@@ -36,11 +37,11 @@ func (r *PdfReader) ReadText(filePath string) (string, error) {
3637 continue
3738 }
3839
39- content += text
40- content += "\n \n --- 第 " + fmt .Sprintf ("%d" , pageNum ) + " 页 ---\n \n "
40+ content . WriteString ( text )
41+ content . WriteString ( "\n \n --- 第 " + fmt .Sprintf ("%d" , pageNum ) + " 页 ---\n \n " )
4142 }
4243
43- return content , nil
44+ return content . String () , nil
4445}
4546
4647// GetMetadata 获取 PDF 文件的元数据
You can’t perform that action at this time.
0 commit comments