0
pdfやdocなどのドライブファイルからテキストを読み込もうとすると、次のようなテキスト形式になります。Googleドライブのテキストを読む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