• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

PDFTextStripper returning null for all the japanese text in the PDF

 
Ranch Hand
Posts: 48
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi,
Below is an example that i picked up to try but when ever i parse a PDF with japanese text in it, i get all null for japanese text but get the english text and numbers correctly. below is the code.

public class PDF {
public PDF(String fname) {
try {
InputStream in = new FileInputStream(fname);
StringWriter out = new StringWriter();
PDFTextStripper stripper = new PDFTextStripper();
PDFParser parser = new PDFParser( in );
parser.parse();
PDDocument document = parser.getPDDocument();
stripper.writeText(document,out);
rawText = out.toString();
document.close();
} catch (Exception exception) {
System.out.println("PDF error: " + exception);
exception.printStackTrace();
}
}
public String getText() { return rawText; }
private String rawText = "";

}

please suggest
 
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
How are you dealing with character encoding? The code you posted does not set any encoding, so your standard system encoding would be used. That might not work for Japanese text.

I suggest having a look at the documentation of the PDFTextStripper, PDFParser, etc. classes, and look for something that explains how to parse documents using other encodings.
 
mohit bahl
Ranch Hand
Posts: 48
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi Ulf
thanks foir your reply, can you please guide as to where ihave to set this encoding as i have been looking around for the same but i have not found it even in the pdfbox documentation.

thanks in advance.
 
mohit bahl
Ranch Hand
Posts: 48
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
i have done some testing and have seen that it is happening in case where the document contains both english and asian language text.

Anyone has some suggestion on this
 
reply
    Bookmark Topic Watch Topic
  • New Topic