Source Code Cross Referenced for TextExtractionSample.java in  » PDF » PDFClown-0.0.5 » it » stefanochizzolini » clown » samples » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » PDF » PDFClown 0.0.5 » it.stefanochizzolini.clown.samples 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        package it.stefanochizzolini.clown.samples;
002:
003:        import it.stefanochizzolini.clown.documents.Document;
004:        import it.stefanochizzolini.clown.documents.Page;
005:        import it.stefanochizzolini.clown.documents.Pages;
006:        import it.stefanochizzolini.clown.documents.contents.objects.ContainerObject;
007:        import it.stefanochizzolini.clown.documents.contents.objects.ContentObject;
008:        import it.stefanochizzolini.clown.documents.contents.objects.Operation;
009:        import it.stefanochizzolini.clown.documents.contents.objects.Text;
010:        import it.stefanochizzolini.clown.files.File;
011:        import it.stefanochizzolini.clown.objects.IPdfString;
012:        import it.stefanochizzolini.clown.objects.PdfArray;
013:        import it.stefanochizzolini.clown.objects.PdfDirectObject;
014:        import it.stefanochizzolini.clown.objects.PdfName;
015:        import it.stefanochizzolini.clown.tokens.FileFormatException;
016:
017:        import java.util.List;
018:        import java.util.Scanner;
019:
020:        /**
021:         This sample is a rough stub that demonstrates a basic way to extract text from
022:         a document.
023:         <h3>Remarks</h3>
024:         <p>This implementation is definitely simplistic: its purpose is NOT to provide
025:         a real-life solution for PDF text mining; it lacks advanced features such as
026:         character encoding management, glyph position detection, dehyphenation,
027:         page-breaks handling and so on. Its purpose is to test the new content-stream parsing
028:         functionality.</p>
029:         <p>So, read my lips: this-is-just-a-toy (for now!).</p>
030:         */
031:        public class TextExtractionSample implements  ISample {
032:            public void run(PDFClownSampleLoader loader) {
033:                // (boilerplate user choice -- ignore it)
034:                String filePath = loader
035:                        .getPdfFileChoice("Please select a PDF file");
036:
037:                // Open the PDF file!
038:                File file;
039:                try {
040:                    file = new File(filePath);
041:                } catch (FileFormatException e) {
042:                    throw new RuntimeException(filePath
043:                            + " file has a bad file format.", e);
044:                } catch (Exception e) {
045:                    throw new RuntimeException(
046:                            filePath + " file access error.", e);
047:                }
048:
049:                // Get the PDF document!
050:                Document document = file.getDocument();
051:                // Get the page collection!
052:                Pages pages = document.getPages();
053:                //TODO:IMPL see PDF:1.6:5.9
054:                for (Page page : pages) {
055:                    System.out.println("\nScanning page "
056:                            + (page.getIndex() + 1) + "...\n");
057:
058:                    extract(page.getContents());
059:
060:                    System.out.println("\nENTER (Scan next page)");
061:                    System.out.println("[Q] (End scanning)");
062:                    System.out.print("Please select: ");
063:
064:                    Scanner in = new Scanner(System.in);
065:                    try {
066:                        String choice = in.nextLine();
067:                        if (choice.toUpperCase().equals("Q")) // Quit.
068:                            break;
069:                    } catch (Exception e) {
070:                    }
071:                }
072:            }
073:
074:            private void extract(List<? extends ContentObject> objects) {
075:                for (ContentObject object : objects) {
076:                    if (object instanceof  Text) {
077:                        for (Operation operation : ((Text) object).getObjects()) {
078:                            boolean hit = false;
079:                            String operator = operation.getOperator();
080:                            if (operator.equals("TJ") || operator.equals("Tj")
081:                                    || operator.equals("'")
082:                                    || operator.equals("''")) {
083:                                for (PdfDirectObject operand : operation
084:                                        .getOperands()) {
085:                                    if (operand instanceof  IPdfString) {
086:                                        hit = true;
087:                                        System.out.print(((IPdfString) operand)
088:                                                .getStringValue()
089:                                                + " ");
090:                                    } else if (operand instanceof  PdfArray) {
091:                                        for (PdfDirectObject item : ((PdfArray) operand)) {
092:                                            if (item instanceof  IPdfString) {
093:                                                hit = true;
094:                                                System.out
095:                                                        .print(((IPdfString) item)
096:                                                                .getStringValue()
097:                                                                + " ");
098:                                            }
099:                                        }
100:                                    }
101:                                }
102:                                if (hit) {
103:                                    System.out.println();
104:                                }
105:                            }
106:                        }
107:                    } else if (object instanceof  ContainerObject) {
108:                        extract(((ContainerObject) object).getObjects());
109:                    }
110:                }
111:            }
112:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.