Source Code Cross Referenced for MergeSample.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) 


01:        package it.stefanochizzolini.clown.samples;
02:
03:        import it.stefanochizzolini.clown.documents.Document;
04:        import it.stefanochizzolini.clown.documents.Page;
05:        import it.stefanochizzolini.clown.documents.Pages;
06:        import it.stefanochizzolini.clown.files.File;
07:        import it.stefanochizzolini.clown.tokens.FileFormatException;
08:
09:        import java.util.Collection;
10:
11:        /**
12:         This sample demonstrates how to concatenate a document to another.
13:         <h3>Remarks</h3>
14:         <p>This implementation is based on the <b>contextual cloning</b> functionality
15:         of PDF Clown which allows to transparently and intuitively import contents from
16:         one document to another.</p>
17:         */
18:        public class MergeSample implements  ISample {
19:            public void run(PDFClownSampleLoader loader) {
20:                // (boilerplate user choice -- ignore it)
21:                String sourceFilePath = loader
22:                        .getPdfFileChoice("Please select source PDF file");
23:                String targetFilePath = loader
24:                        .getPdfFileChoice("Please select target PDF file");
25:
26:                // 1. Opening the PDF files...
27:                // Source file.
28:                File sourceFile;
29:                try {
30:                    sourceFile = new File(sourceFilePath);
31:                } catch (FileFormatException e) {
32:                    throw new RuntimeException(sourceFilePath
33:                            + " file has a bad file format.", e);
34:                } catch (Exception e) {
35:                    throw new RuntimeException(sourceFilePath
36:                            + " file access error.", e);
37:                }
38:                // Target file.
39:                File targetFile;
40:                try {
41:                    targetFile = new File(targetFilePath);
42:                } catch (FileFormatException e) {
43:                    throw new RuntimeException(targetFilePath
44:                            + " file has a bad file format.", e);
45:                } catch (Exception e) {
46:                    throw new RuntimeException(targetFilePath
47:                            + " file access error.", e);
48:                }
49:
50:                // Get the PDF documents!
51:                Document sourceDocument = sourceFile.getDocument();
52:                Document targetDocument = targetFile.getDocument();
53:                Pages targetPages = targetDocument.getPages();
54:
55:                // 2. Append the source document's pages to the target document!
56:                /*
57:                  NOTE: To be added to an alien document,
58:                  pages MUST be firstly contextualized into it,
59:                  then added to the target pages collection.
60:                 */
61:                targetPages.addAll((Collection<Page>) targetDocument
62:                        .contextualize((Collection<Page>) sourceDocument
63:                                .getPages()));
64:                targetPages.update(); // NOTE: Update is fundamental to override original page collection.
65:
66:                // (boilerplate metadata insertion -- ignore it)
67:                loader.buildAccessories(targetDocument, this .getClass(),
68:                        "Merge",
69:                        "concatenating two (or possibly more) documents");
70:
71:                // 3. Serialize the PDF file (again, boilerplate code -- see the PDFClownSampleLoader class source code)!
72:                loader.serialize(targetFile, this.getClass().getSimpleName());
73:            }
74:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.