0
當我嘗試從pdf和doc等驅動器文件中讀取文本時,文本格式如下所示。從谷歌驅動器pdf和doc文件中讀取文本android
%PDF-1.3
%âãÏÓ
7 0 obj
<</Linearized 1/L 7945/O 9/E 3524/N 1/T 7656/H [ 451 137]>>
endobj
13 0 obj
<</DecodeParms<</Columns 4/Predictor 12>>/Filter/FlateDecode/ID[<4DC91A1875A6D707AEC203BB021C93A0><F6C92B368A8A13408457A1D395A37EB9>]/Index[7 21]/Info 6 0 R/Length 52/Prev 7657/Root 8 0 R/Size 28/Type/XRef/W[1 2 1]>>stream
hÞbbd``b`² ±H0§ 6G ñå#Ã4,#¹ÄÆ_L¤ð
endstream
endobj
startxref
0
%%EOF
27 0 obj
<</Filter/FlateDecode/I 69/Length 58/S 38>>stream
hÞb```a``üÏÜ6¨¬$ËѬ,ÆÅ
ÜÜÓt&¬8ÌZ-R,¿â
endstream
endobj
8 0 obj
<</Metadata 1 0 R/Pages 5 0 R/Type/Catalog>>
endobj
9 0 obj
<</Contents 11 0 R/CropBox[0 0 595 842]/MediaBox[0 0 595 842]/Parent 5 0 R/Resources 14 0 R/Rotate 0/Type/Page>>
endobj
請找到下面的代碼:
DriveContents contents = result.getDriveContents();
BufferedReader reader = new BufferedReader(new InputStreamReader(contents.getInputStream()));
StringBuilder builder = new StringBuilder();
String line;
while ((line = reader.readLine()) != null) {
builder.append(line);
}
String contentsAsString = builder.toString();
但實際上,我需要在原始格式文本here
請幫我在這。
PDF文件不是純文本文件,並且您的代碼僅適用於純文本文件。查找理解PDF文件格式的PDF庫(例如iText)。 – CommonsWare