Revision 6419

View differences:

org.gvsig.pdf/tags/org.gvsig.pdf-1.0.87/pom.xml
1
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
2

  
3
    <modelVersion>4.0.0</modelVersion>
4
    <parent>
5
        <groupId>org.gvsig</groupId>
6
        <artifactId>org.gvsig.desktop</artifactId>
7
        <version>2.0.372</version>
8
    </parent>
9
    <artifactId>org.gvsig.pdf</artifactId>
10
    <version>1.0.87</version>
11
    <packaging>pom</packaging>
12
    <name>${project.artifactId}</name>
13

  
14
    <url>https://devel.gvsig.org/svn/gvsig-projects-pool/${project.artifactId}/trunk/${project.artifactId}</url>
15
  
16
    <distributionManagement>
17
        <site>
18
            <id>gvsig-repository</id>
19
            <url>dav:https://devel.gvsig.org/sites/${project.artifactId}/${project.version}</url>
20
        </site>
21
    </distributionManagement>
22
  
23
    <scm>
24
        <connection>scm:svn:https://devel.gvsig.org/svn/gvsig-projects-pool/org.gvsig.pdf/tags/org.gvsig.pdf-1.0.87</connection>
25
        <developerConnection>scm:svn:https://devel.gvsig.org/svn/gvsig-projects-pool/org.gvsig.pdf/tags/org.gvsig.pdf-1.0.87</developerConnection>
26
        <url>https://devel.gvsig.org/svn/gvsig-projects-pool/org.gvsig.pdf/tags/org.gvsig.pdf-1.0.87</url>
27
    </scm>
28

  
29
    <developers>
30
        <developer>
31
            <id>jjdelcerro</id>
32
            <name>Joaquin Jose del Cerro</name>
33
            <email>jjdelcerro@gvsig.com</email>
34
            <roles>
35
                <role>Architect</role>
36
                <role>Developer</role>
37
            </roles>
38
        </developer>
39
    </developers>
40

  
41
    <repositories>
42
        <repository>
43
            <id>gvsig-public-http-repository</id>
44
            <name>gvSIG maven public HTTP repository</name>
45
            <url>http://devel.gvsig.org/m2repo/j2se</url>
46
            <releases>
47
                <enabled>true</enabled>
48
                <updatePolicy>daily</updatePolicy>
49
                <checksumPolicy>warn</checksumPolicy>
50
            </releases>
51
            <snapshots>
52
                <enabled>true</enabled>
53
                <updatePolicy>daily</updatePolicy>
54
                <checksumPolicy>warn</checksumPolicy>
55
            </snapshots>
56
        </repository>
57
<!--        <repository>
58
            
59
            https://stackoverflow.com/questions/26993105/i-get-an-error-downloading-javax-media-jai-core1-1-3-from-maven-central
60
            
61
            <id>geotoolkit-org</id>
62
            <name>geotoolkit.org repository</name>
63
            <url>http://maven.geotoolkit.org/</url>
64
        </repository>-->
65
    </repositories>
66

  
67
    <build>
68
        <plugins>
69
            <plugin>
70
                <groupId>org.apache.maven.plugins</groupId>
71
                <artifactId>maven-release-plugin</artifactId>
72
                <configuration>
73
                    <tagBase>https://devel.gvsig.org/svn/gvsig-projects-pool/${project.artifactId}/tags</tagBase>
74
                    <goal>deploy</goal>
75
                </configuration>
76
            </plugin>
77
        </plugins>
78
    </build>
79

  
80

  
81
    <dependencyManagement>
82
        <dependencies>
83
            <dependency>
84
                <groupId>org.gvsig</groupId>
85
                <artifactId>org.gvsig.pdf.app.mainplugin</artifactId>
86
                <version>1.0.87</version>
87
            </dependency>
88
            <dependency>
89
                <groupId>org.gvsig</groupId>
90
                <artifactId>org.gvsig.pdf.lib.api</artifactId>
91
                <version>1.0.87</version>
92
            </dependency>
93
            <dependency>
94
                <groupId>org.gvsig</groupId>
95
                <artifactId>org.gvsig.pdf.lib.impl</artifactId>
96
                <version>1.0.87</version>
97
            </dependency>
98
            <dependency>
99
                <groupId>org.gvsig</groupId>
100
                <artifactId>org.gvsig.pdf.swing.api</artifactId>
101
                <version>1.0.87</version>
102
            </dependency>
103
            <dependency>
104
                <groupId>org.gvsig</groupId>
105
                <artifactId>org.gvsig.pdf.swing.impl</artifactId>
106
                <version>1.0.87</version>
107
            </dependency>
108
            <dependency>
109
                <groupId>org.icepdf.os</groupId>
110
                <artifactId>icepdf-core</artifactId>
111
                <version>6.2.2</version>
112
                <exclusions>
113
                    <exclusion>
114
                        <groupId>batik</groupId>
115
                        <artifactId>batik-awt-util</artifactId>
116
                    </exclusion>        
117
                    <exclusion>
118
                        <groupId>batik</groupId>
119
                        <artifactId>batik-dom</artifactId>
120
                    </exclusion>        
121
                    <exclusion>
122
                        <groupId>batik</groupId>
123
                        <artifactId>batik-svg-dom</artifactId>
124
                    </exclusion>        
125
                    <exclusion>
126
                        <groupId>batik</groupId>
127
                        <artifactId>batik-svggen</artifactId>
128
                    </exclusion>        
129
                    <exclusion>
130
                        <groupId>batik</groupId>
131
                        <artifactId>batik-util</artifactId>
132
                    </exclusion>        
133
                    <exclusion>
134
                        <groupId>batik</groupId>
135
                        <artifactId>batik-xml</artifactId>
136
                    </exclusion>        
137
                    <!--
138
                    <exclusion>
139
                        <groupId>javax.media</groupId>
140
                        <artifactId>jai_core</artifactId>
141
                    </exclusion>        
142
                    -->
143
                </exclusions>
144
            </dependency>
145
	    <dependency>
146
                <groupId>org.icepdf.os</groupId>
147
                <artifactId>icepdf-viewer</artifactId>
148
                <version>6.2.2</version>
149
                <exclusions>
150
                    <exclusion>
151
                        <groupId>batik</groupId>
152
                        <artifactId>batik-awt-util</artifactId>
153
                    </exclusion>        
154
                    <exclusion>
155
                        <groupId>batik</groupId>
156
                        <artifactId>batik-dom</artifactId>
157
                    </exclusion>        
158
                    <exclusion>
159
                        <groupId>batik</groupId>
160
                        <artifactId>batik-svg-dom</artifactId>
161
                    </exclusion>        
162
                    <exclusion>
163
                        <groupId>batik</groupId>
164
                        <artifactId>batik-svggen</artifactId>
165
                    </exclusion>        
166
                    <exclusion>
167
                        <groupId>batik</groupId>
168
                        <artifactId>batik-util</artifactId>
169
                    </exclusion>        
170
                    <exclusion>
171
                        <groupId>batik</groupId>
172
                        <artifactId>batik-xml</artifactId>
173
                    </exclusion>  
174
                    <!--      
175
                    <exclusion>
176
                        <groupId>javax.media</groupId>
177
                        <artifactId>jai_core</artifactId>
178
                    </exclusion>        
179
                    -->
180
                </exclusions>
181
            </dependency>
182
            <!--
183
            <dependency>
184
              <groupId>com.cosium.jai-imageio</groupId>
185
              <artifactId>jai-imageio-core</artifactId>
186
              <version>1.3.0.1</version>
187
            </dependency>
188
            -->
189
            <dependency>
190
              <groupId>org.bouncycastle</groupId>
191
              <artifactId>bcpkix-jdk15on</artifactId>
192
              <version>1.54</version>
193
            </dependency>
194
            <dependency>
195
              <groupId>org.bouncycastle</groupId>
196
              <artifactId>bcprov-jdk15on</artifactId>
197
              <version>1.54</version>
198
            </dependency>
199
            <dependency>
200
              <groupId>org.bouncycastle</groupId>
201
              <artifactId>bcprov-ext-jdk15on</artifactId>
202
              <version>1.54</version>
203
            </dependency>
204
            <dependency>
205
                <groupId>com.itextpdf</groupId>
206
                <artifactId>itextpdf</artifactId>
207
                <version>5.5.8</version>
208
            </dependency>
209
            <dependency>
210
                <groupId>org.apache.pdfbox</groupId>
211
                <artifactId>pdfbox</artifactId>
212
                <version>2.0.16</version>
213
            </dependency>
214
            <dependency>
215
                <groupId>de.rototor.pdfbox</groupId>
216
                <artifactId>graphics2d</artifactId>
217
                <version>0.24</version>
218
            </dependency>
219
        </dependencies>
220
    </dependencyManagement>
221

  
222
    <modules>
223
        <module>org.gvsig.pdf.lib</module>
224
        <module>org.gvsig.pdf.swing</module>
225
        <module>org.gvsig.pdf.app</module>
226
    </modules>
227

  
228
</project>
org.gvsig.pdf/tags/org.gvsig.pdf-1.0.87/org.gvsig.pdf.app/pom.xml
1
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
2
  <modelVersion>4.0.0</modelVersion>
3
  <parent>
4
    <groupId>org.gvsig</groupId>
5
    <artifactId>org.gvsig.pdf</artifactId>
6
    <version>1.0.87</version>
7
  </parent>
8
  <artifactId>org.gvsig.pdf.app</artifactId>
9
  <packaging>pom</packaging>
10
  <name>${project.artifactId}</name>
11
  <modules>
12
  	<module>org.gvsig.pdf.app.mainplugin</module>
13
  </modules>
14
</project>
org.gvsig.pdf/tags/org.gvsig.pdf-1.0.87/org.gvsig.pdf.app/org.gvsig.pdf.app.mainplugin/buildNumber.properties
1
#Mon Apr 25 01:29:20 CEST 2022
2
buildNumber=89
org.gvsig.pdf/tags/org.gvsig.pdf-1.0.87/org.gvsig.pdf.app/org.gvsig.pdf.app.mainplugin/src/main/resources-plugin/i18n/text.properties
1
#Translations for language [es]
2
#Thu Nov 20 10:10:09 CET 2014
3
_Open=Abrir
org.gvsig.pdf/tags/org.gvsig.pdf-1.0.87/org.gvsig.pdf.app/org.gvsig.pdf.app.mainplugin/src/main/resources-plugin/i18n/text_en.properties
1
#Translations for language [en]
2
#Thu Nov 20 10:10:15 CET 2014
3
_Open=Open
4

  
5

  
org.gvsig.pdf/tags/org.gvsig.pdf-1.0.87/org.gvsig.pdf.app/org.gvsig.pdf.app.mainplugin/src/main/resources-plugin/config.xml
1
<?xml version="1.0" encoding="ISO-8859-1"?>
2
<!-- gvSIG. Desktop Geographic Information System. Copyright (C) 2007-2014 gvSIG
3
  Association. This program is free software; you can redistribute it and/or modify
4
  it under the terms of the GNU General Public License as published by the Free Software
5
  Foundation; either version 3 of the License, or (at your option) any later version.
6
  This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
7
  without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
8
  PURPOSE. See the GNU General Public License for more details. You should have received
9
  a copy of the GNU General Public License along with this program; if not, write to
10
  the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
11
  USA. For any additional information, do not hesitate to contact us at info AT gvsig.com,
12
  or visit our website www.gvsig.com. -->
13
<plugin-config>
14
  <depends plugin-name="org.gvsig.app.mainplugin" />
15
  <resourceBundle name="text" />
16
  <libraries library-dir="lib" />
17
  <extensions>
18

  
19

  
20
    <extension class-name="org.gvsig.pdf.app.mainplugin.PDFExtension"
21
      description="" active="true" priority="1">
22
    </extension>
23

  
24

  
25
  </extensions>
26
</plugin-config>
org.gvsig.pdf/tags/org.gvsig.pdf-1.0.87/org.gvsig.pdf.app/org.gvsig.pdf.app.mainplugin/src/main/assembly/gvsig-plugin-package.xml
1
<!--
2

  
3
    gvSIG. Desktop Geographic Information System.
4

  
5
    Copyright (C) 2007-2013 gvSIG Association.
6

  
7
    This program is free software; you can redistribute it and/or
8
    modify it under the terms of the GNU General Public License
9
    as published by the Free Software Foundation; either version 3
10
    of the License, or (at your option) any later version.
11

  
12
    This program is distributed in the hope that it will be useful,
13
    but WITHOUT ANY WARRANTY; without even the implied warranty of
14
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15
    GNU General Public License for more details.
16

  
17
    You should have received a copy of the GNU General Public License
18
    along with this program; if not, write to the Free Software
19
    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
20
    MA  02110-1301, USA.
21

  
22
    For any additional information, do not hesitate to contact us
23
    at info AT gvsig.com, or visit our website www.gvsig.com.
24

  
25
-->
26
<assembly>
27
    <id>gvsig-plugin-package</id>
28
    <formats>
29
        <format>zip</format>
30
    </formats>
31
    <baseDirectory>${project.artifactId}</baseDirectory>
32
    <includeBaseDirectory>true</includeBaseDirectory>
33
    <files>
34
        <file>
35
            <source>target/${project.artifactId}-${project.version}.jar</source>
36
            <outputDirectory>lib</outputDirectory>
37
        </file>
38
        <file>
39
            <source>target/package.info</source>
40
        </file>
41
    </files>
42

  
43
    <fileSets>
44
        <fileSet>
45
            <directory>src/main/resources-plugin</directory>
46
            <outputDirectory>.</outputDirectory>
47
        </fileSet>
48
    </fileSets>
49

  
50

  
51
    <dependencySets>
52
        <dependencySet>
53
            <useProjectArtifact>false</useProjectArtifact>
54
            <useTransitiveDependencies>false</useTransitiveDependencies>
55
            <outputDirectory>lib</outputDirectory>
56
            <includes>
57
                <include>org.gvsig:org.gvsig.pdf.lib.api</include>
58
                <include>org.gvsig:org.gvsig.pdf.lib.impl</include>
59
                <include>org.gvsig:org.gvsig.pdf.swing.api</include>
60
                <include>org.gvsig:org.gvsig.pdf.swing.impl</include>
61
                <include>org.icepdf.os:icepdf-viewer</include>
62
                <include>org.icepdf.os:icepdf-core</include>
63

  
64
                <include>javax.media:jai_core</include>
65
                <include>org.bouncycastle:bcpkix-jdk15on</include>
66
                
67
                <include>org.apache.pdfbox:pdfbox</include>
68
                <include>de.rototor.pdfbox:graphics2d</include>
69
                
70
                <!--
71
                Estos dos jars ya se los esta llevando andami
72
                <include>org.bouncycastle:bcprov-jdk15on</include>
73
                <include>org.bouncycastle:bcprov-ext-jdk15on</include>
74
                -->
75
            </includes>
76
        </dependencySet>
77
    </dependencySets>
78

  
79
</assembly>
80

  
org.gvsig.pdf/tags/org.gvsig.pdf-1.0.87/org.gvsig.pdf.app/org.gvsig.pdf.app.mainplugin/src/main/java/org/gvsig/pdf/app/mainplugin/PDFExtension.java
1
/**
2
 * gvSIG. Desktop Geographic Information System.
3
 *
4
 * Copyright (C) 2007-2013 gvSIG Association.
5
 *
6
 * This program is free software; you can redistribute it and/or
7
 * modify it under the terms of the GNU General Public License
8
 * as published by the Free Software Foundation; either version 3
9
 * of the License, or (at your option) any later version.
10
 *
11
 * This program is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 * GNU General Public License for more details.
15
 *
16
 * You should have received a copy of the GNU General Public License
17
 * along with this program; if not, write to the Free Software
18
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
19
 * MA  02110-1301, USA.
20
 *
21
 * For any additional information, do not hesitate to contact us
22
 * at info AT gvsig.com, or visit our website www.gvsig.com.
23
 */
24
package org.gvsig.pdf.app.mainplugin;
25

  
26
import org.gvsig.andami.plugins.Extension;
27

  
28
/**
29
 *
30
 * @author jjdelcerro
31
 */
32
public class PDFExtension extends Extension {
33

  
34
    @Override
35
    public void initialize() {
36

  
37
    }
38

  
39
    @Override
40
    public void postInitialize() {
41

  
42
    }
43

  
44
    @Override
45
    public void execute(String action) {
46

  
47
    }
48

  
49
    @Override
50
    public boolean isEnabled() {
51

  
52
        return true;
53
    }
54

  
55
    @Override
56
    public boolean isVisible() {
57
        return true;
58
    }
59

  
60
}
org.gvsig.pdf/tags/org.gvsig.pdf-1.0.87/org.gvsig.pdf.app/org.gvsig.pdf.app.mainplugin/pom.xml
1
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
2
    <modelVersion>4.0.0</modelVersion>
3
    <parent>
4
        <groupId>org.gvsig</groupId>
5
        <artifactId>org.gvsig.pdf.app</artifactId>
6
        <version>1.0.87</version>
7
    </parent>
8
    <artifactId>org.gvsig.pdf.app.mainplugin</artifactId>
9
    <name>${project.artifactId}</name>
10
    <dependencies>
11
        <dependency>
12
            <groupId>org.gvsig</groupId>
13
            <artifactId>org.gvsig.app.mainplugin</artifactId>
14
            <scope>compile</scope>
15
        </dependency>
16
        <dependency>
17
            <groupId>org.gvsig</groupId>
18
            <artifactId>org.gvsig.pdf.lib.api</artifactId>
19
            <scope>compile</scope>
20
        </dependency>
21
        <dependency>
22
            <groupId>org.gvsig</groupId>
23
            <artifactId>org.gvsig.pdf.lib.impl</artifactId>
24
            <scope>runtime</scope>
25
        </dependency>
26
        <dependency>
27
            <groupId>org.gvsig</groupId>
28
            <artifactId>org.gvsig.pdf.swing.api</artifactId>
29
            <scope>compile</scope>
30
        </dependency>
31
        <dependency>
32
            <groupId>org.gvsig</groupId>
33
            <artifactId>org.gvsig.pdf.swing.impl</artifactId>
34
            <scope>runtime</scope>
35
        </dependency>
36
        <dependency>
37
            <groupId>org.icepdf.os</groupId>
38
            <artifactId>icepdf-core</artifactId>
39
            <scope>runtime</scope>
40
        </dependency>
41
        <dependency>
42
            <groupId>org.icepdf.os</groupId>
43
            <artifactId>icepdf-viewer</artifactId>
44
            <scope>runtime</scope>
45
        </dependency>
46
        <dependency>
47
            <groupId>javax.media</groupId>
48
            <artifactId>jai_core</artifactId>
49
            <scope>runtime</scope>
50
        </dependency>
51
        
52
        <dependency>
53
            <groupId>org.bouncycastle</groupId>
54
            <artifactId>bcpkix-jdk15on</artifactId>
55
            <scope>runtime</scope>
56
        </dependency>
57
        <dependency>
58
            <groupId>org.bouncycastle</groupId>
59
            <artifactId>bcprov-jdk15on</artifactId>
60
            <scope>runtime</scope>
61
        </dependency>
62
        <dependency>
63
            <groupId>org.bouncycastle</groupId>
64
            <artifactId>bcprov-ext-jdk15on</artifactId>
65
            <scope>runtime</scope>
66
        </dependency>
67
        <dependency>
68
            <groupId>org.apache.pdfbox</groupId>
69
            <artifactId>pdfbox</artifactId>
70
        </dependency>
71
        <dependency>
72
            <groupId>de.rototor.pdfbox</groupId>
73
            <artifactId>graphics2d</artifactId>
74
        </dependency>
75
    </dependencies>
76

  
77
    <properties>
78
        <gvsig.package.info.state>testing</gvsig.package.info.state>
79
        <gvsig.package.info.official>true</gvsig.package.info.official>
80
        <gvsig.package.info.dependencies>required: org.gvsig.app -ge 2.2.0</gvsig.package.info.dependencies>
81
        <gvsig.package.info.categories />
82
        <gvsig.package.info.name>PDF framework</gvsig.package.info.name>
83
        <gvsig.package.info.description>PDF framework and basic rules</gvsig.package.info.description>
84
        <gvsig.package.info.owner>gvSIG Association</gvsig.package.info.owner>
85
        <gvsig.package.info.javaVM>j1_8</gvsig.package.info.javaVM>
86
        <gvsig.package.info.sourcesURL>${project.scm.url}</gvsig.package.info.sourcesURL>
87
        <gvsig.package.info.poolURL>https://devel.gvsig.org/download/projects/gvsig-pdf/pool</gvsig.package.info.poolURL>
88
    </properties>
89

  
90
</project>
0 91

  
org.gvsig.pdf/tags/org.gvsig.pdf-1.0.87/org.gvsig.pdf.lib/org.gvsig.pdf.lib.api/src/main/resources/META-INF/services/org.gvsig.tools.library.Library
1
org.gvsig.pdf.lib.api.PDFLibrary
org.gvsig.pdf/tags/org.gvsig.pdf-1.0.87/org.gvsig.pdf.lib/org.gvsig.pdf.lib.api/src/main/java/org/gvsig/pdf/lib/api/PDFManager.java
1
/**
2
 * gvSIG. Desktop Geographic Information System.
3
 *
4
 * Copyright (C) 2007-2013 gvSIG Association.
5
 *
6
 * This program is free software; you can redistribute it and/or
7
 * modify it under the terms of the GNU General Public License
8
 * as published by the Free Software Foundation; either version 3
9
 * of the License, or (at your option) any later version.
10
 *
11
 * This program is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 * GNU General Public License for more details.
15
 *
16
 * You should have received a copy of the GNU General Public License
17
 * along with this program; if not, write to the Free Software
18
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
19
 * MA  02110-1301, USA.
20
 *
21
 * For any additional information, do not hesitate to contact us
22
 * at info AT gvsig.com, or visit our website www.gvsig.com.
23
 */
24
package org.gvsig.pdf.lib.api;
25

  
26
import java.io.File;
27
import java.io.OutputStream;
28
import java.util.List;
29

  
30
/**
31
 *
32
 * @author jjdelcerro
33
 */
34
public interface PDFManager {
35
    
36
    public PDFDocument createPDFDocument(byte[] document);
37
    public PDFDocument createPDFDocument(String document);
38
    public PDFDocument createPDFDocument(File document);
39
    public PDFDocument createPDFDocument(); 
40
    public PDFWriter createPDFWriter();
41
    public void merge(List<PDFDocument> inputs, 
42
            OutputStream output, 
43
            long maxMemoryToUse, 
44
            String title, 
45
            String creator, 
46
            String subject
47
    );
48
    
49
    
50
}
org.gvsig.pdf/tags/org.gvsig.pdf-1.0.87/org.gvsig.pdf.lib/org.gvsig.pdf.lib.api/src/main/java/org/gvsig/pdf/lib/api/PDFWriter.java
1
package org.gvsig.pdf.lib.api;
2

  
3
import java.awt.Graphics2D;
4

  
5
/**
6
 *
7
 * @author osc
8
 */
9
public interface PDFWriter {
10

  
11
    public static final int PAGE_LETTER = 1;
12
    public static final int PAGE_LEGAL = 2;
13
    public static final int PAGE_A4 = 4;
14
    public static final int PAGE_A5 = 5;
15

  
16
    public void open(int pageSize);
17

  
18
    public void close();
19

  
20
    public float getWidth();
21

  
22
    public float getHeight();
23

  
24
    public Graphics2D getGraphics2D();
25
    
26
    public byte[] toByteArray();
27
    
28
    public PDFDocument toDocument();
29
}
org.gvsig.pdf/tags/org.gvsig.pdf-1.0.87/org.gvsig.pdf.lib/org.gvsig.pdf.lib.api/src/main/java/org/gvsig/pdf/lib/api/PDFDocument.java
1
/*
2
 * To change this license header, choose License Headers in Project Properties.
3
 * To change this template file, choose Tools | Templates
4
 * and open the template in the editor.
5
 */
6
package org.gvsig.pdf.lib.api;
7

  
8
import java.io.IOException;
9
import java.io.InputStream;
10
import org.gvsig.tools.swing.api.SimpleImage;
11

  
12
/**
13
 *
14
 * @author osc
15
 */
16
public interface PDFDocument {
17
    public InputStream getInputStream() throws IOException ;
18
    
19
    public void setSource(Object source);
20

  
21
    public byte[] toByteArray();
22
    
23
    public String toHexString();
24
    
25
    public int getNumberOfPages();
26
    
27
    public SimpleImage toImage();
28
    
29
    public SimpleImage toImage(int page);
30
    
31
    public SimpleImage toImage(int page, int dpis);
32
}
org.gvsig.pdf/tags/org.gvsig.pdf-1.0.87/org.gvsig.pdf.lib/org.gvsig.pdf.lib.api/src/main/java/org/gvsig/pdf/lib/api/PDFLocator.java
1
/**
2
 * gvSIG. Desktop Geographic Information System.
3
 *
4
 * Copyright (C) 2007-2013 gvSIG Association.
5
 *
6
 * This program is free software; you can redistribute it and/or
7
 * modify it under the terms of the GNU General Public License
8
 * as published by the Free Software Foundation; either version 3
9
 * of the License, or (at your option) any later version.
10
 *
11
 * This program is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 * GNU General Public License for more details.
15
 *
16
 * You should have received a copy of the GNU General Public License
17
 * along with this program; if not, write to the Free Software
18
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
19
 * MA  02110-1301, USA.
20
 *
21
 * For any additional information, do not hesitate to contact us
22
 * at info AT gvsig.com, or visit our website www.gvsig.com.
23
 */
24
package org.gvsig.pdf.lib.api;
25

  
26
import org.gvsig.tools.locator.AbstractLocator;
27
import org.gvsig.tools.locator.Locator;
28
import org.gvsig.tools.locator.LocatorException;
29

  
30
@SuppressWarnings("rawtypes")
31
public class PDFLocator extends AbstractLocator {
32

  
33
	private static final String LOCATOR_NAME = "PDFLocator";
34
	
35
	public static final String PDF_MANAGER_NAME =
36
			"PDFManager";
37

  
38
	private static final String PDF_MANAGER_DESCRIPTION =
39
			"PDF Manager of gvSIG";
40
	
41
	private static final PDFLocator instance = new PDFLocator();
42

  
43
	private PDFLocator() {
44

  
45
	}
46

  
47
	/**
48
	 * Return the singleton instance.
49
	 * 
50
	 * @return the singleton instance
51
	 */
52
	public static PDFLocator getInstance() {
53
		return instance;
54
	}
55

  
56
        @Override
57
	public String getLocatorName() {
58
		return LOCATOR_NAME;
59
	}
60

  
61
	/**
62
	 * Return a reference to PDFManager.
63
	 * 
64
	 * @return a reference to PDFManager
65
	 * @throws LocatorException
66
	 *             if there is no access to the class or the class cannot be
67
	 *             instantiated
68
	 * @see Locator#get(String)
69
	 */
70
	public static PDFManager getPDFManager()
71
			throws LocatorException {
72
		return (PDFManager) getInstance().get(PDF_MANAGER_NAME);
73
	}
74

  
75
	/**
76
	 * Registers the Class implementing the PDFManager interface.
77
	 * 
78
	 * @param clazz
79
	 *            implementing the PDFManager interface
80
	 */
81
//	public static void registerPDFManager(Class clazz) {
82
//		getInstance().register(PDF_MANAGER_NAME,
83
//				PDF_MANAGER_DESCRIPTION, clazz);
84
//	}
85

  
86
	public static void registerDefaultPDFManager(Class clazz) {
87
		getInstance().registerDefault(PDF_MANAGER_NAME,
88
				PDF_MANAGER_DESCRIPTION, clazz);
89
	}
90

  
91

  
92
}
org.gvsig.pdf/tags/org.gvsig.pdf-1.0.87/org.gvsig.pdf.lib/org.gvsig.pdf.lib.api/src/main/java/org/gvsig/pdf/lib/api/PDFLibrary.java
1
/**
2
 * gvSIG. Desktop Geographic Information System.
3
 *
4
 * Copyright (C) 2007-2013 gvSIG Association.
5
 *
6
 * This program is free software; you can redistribute it and/or
7
 * modify it under the terms of the GNU General Public License
8
 * as published by the Free Software Foundation; either version 3
9
 * of the License, or (at your option) any later version.
10
 *
11
 * This program is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 * GNU General Public License for more details.
15
 *
16
 * You should have received a copy of the GNU General Public License
17
 * along with this program; if not, write to the Free Software
18
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
19
 * MA  02110-1301, USA.
20
 *
21
 * For any additional information, do not hesitate to contact us
22
 * at info AT gvsig.com, or visit our website www.gvsig.com.
23
 */
24
package org.gvsig.pdf.lib.api;
25

  
26
import org.gvsig.fmap.dal.DALLibrary;
27
import org.gvsig.tools.ToolsLibrary;
28
import org.gvsig.tools.library.AbstractLibrary;
29
import org.gvsig.tools.library.LibraryException;
30

  
31
/**
32
 *
33
 * @author jjdelcerro
34
 */
35
public class PDFLibrary extends AbstractLibrary {
36

  
37
    @Override
38
    public void doRegistration() {
39
        super.doRegistration();
40
        registerAsAPI(PDFLibrary.class);
41
        this.require(ToolsLibrary.class);
42
        this.require(DALLibrary.class);
43
    }
44

  
45
    @Override
46
    protected void doInitialize() throws LibraryException {
47
    }
48

  
49
    @Override
50
    protected void doPostInitialize() throws LibraryException {
51
    }
52

  
53
}
org.gvsig.pdf/tags/org.gvsig.pdf-1.0.87/org.gvsig.pdf.lib/org.gvsig.pdf.lib.api/pom.xml
1
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
2
  <modelVersion>4.0.0</modelVersion>
3
  <parent>
4
    <groupId>org.gvsig</groupId>
5
    <artifactId>org.gvsig.pdf.lib</artifactId>
6
    <version>1.0.87</version>
7
  </parent>
8
  <artifactId>org.gvsig.pdf.lib.api</artifactId>
9
  <name>${project.artifactId}</name>
10
  <dependencies>
11
    <dependency>
12
      <groupId>org.gvsig</groupId>
13
      <artifactId>org.gvsig.tools.lib</artifactId>
14
      <scope>compile</scope>
15
    </dependency>
16
    <dependency>
17
      <groupId>org.gvsig</groupId>
18
      <artifactId>org.gvsig.fmap.dal.api</artifactId>
19
      <scope>compile</scope>
20
    </dependency>
21
  </dependencies>
22

  
23
</project>
0 24

  
org.gvsig.pdf/tags/org.gvsig.pdf-1.0.87/org.gvsig.pdf.lib/pom.xml
1
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
2
  <modelVersion>4.0.0</modelVersion>
3
  <parent>
4
    <groupId>org.gvsig</groupId>
5
    <artifactId>org.gvsig.pdf</artifactId>
6
    <version>1.0.87</version>
7
  </parent>
8
  <artifactId>org.gvsig.pdf.lib</artifactId>
9
  <packaging>pom</packaging>
10
  <name>${project.artifactId}</name>
11
  <modules>
12
  	<module>org.gvsig.pdf.lib.api</module>
13
  	<module>org.gvsig.pdf.lib.impl</module>
14
  </modules>
15
</project>
org.gvsig.pdf/tags/org.gvsig.pdf-1.0.87/org.gvsig.pdf.lib/org.gvsig.pdf.lib.impl/src/main/java/org/gvsig/pdf/lib/impl/PDFImplLibrary.java
1
/**
2
 * gvSIG. Desktop Geographic Information System.
3
 *
4
 * Copyright (C) 2007-2013 gvSIG Association.
5
 *
6
 * This program is free software; you can redistribute it and/or
7
 * modify it under the terms of the GNU General Public License
8
 * as published by the Free Software Foundation; either version 3
9
 * of the License, or (at your option) any later version.
10
 *
11
 * This program is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 * GNU General Public License for more details.
15
 *
16
 * You should have received a copy of the GNU General Public License
17
 * along with this program; if not, write to the Free Software
18
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
19
 * MA  02110-1301, USA.
20
 *
21
 * For any additional information, do not hesitate to contact us
22
 * at info AT gvsig.com, or visit our website www.gvsig.com.
23
 */
24
package org.gvsig.pdf.lib.impl;
25

  
26
import org.gvsig.fmap.dal.DALLocator;
27
import org.gvsig.fmap.dal.DataManager;
28
import org.gvsig.pdf.lib.api.PDFLibrary;
29
import org.gvsig.pdf.lib.api.PDFLocator;
30
import org.gvsig.tools.ToolsLibrary;
31
import org.gvsig.tools.library.AbstractLibrary;
32
import org.gvsig.tools.library.LibraryException;
33

  
34
public class PDFImplLibrary extends AbstractLibrary {
35

  
36
    @Override
37
    public void doRegistration() {
38
        super.doRegistration();
39
        registerAsImplementationOf(PDFLibrary.class);
40
        this.require(ToolsLibrary.class);
41
//        this.require(DALLibrary.class);
42
//        this.require(GeometryLibrary.class);
43
    }
44

  
45
    @Override
46
    protected void doInitialize() throws LibraryException {
47
        PDFLocator.registerDefaultPDFManager(DefaultPDFManager.class);
48
    }
49

  
50
    @Override
51
    protected void doPostInitialize() throws LibraryException {
52
        DataManager dataManager = DALLocator.getDataManager();
53
        dataManager.registerDataProfile(new PDFProfile());
54
    }
55

  
56
}
org.gvsig.pdf/tags/org.gvsig.pdf-1.0.87/org.gvsig.pdf.lib/org.gvsig.pdf.lib.impl/src/main/java/org/gvsig/pdf/lib/impl/DefaultPDFManager.java
1
/**
2
 * gvSIG. Desktop Geographic Information System.
3
 *
4
 * Copyright (C) 2007-2013 gvSIG Association.
5
 *
6
 * This program is free software; you can redistribute it and/or
7
 * modify it under the terms of the GNU General Public License
8
 * as published by the Free Software Foundation; either version 3
9
 * of the License, or (at your option) any later version.
10
 *
11
 * This program is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 * GNU General Public License for more details.
15
 *
16
 * You should have received a copy of the GNU General Public License
17
 * along with this program; if not, write to the Free Software
18
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
19
 * MA  02110-1301, USA.
20
 *
21
 * For any additional information, do not hesitate to contact us
22
 * at info AT gvsig.com, or visit our website www.gvsig.com.
23
 */
24
package org.gvsig.pdf.lib.impl;
25

  
26
import java.io.File;
27
import java.io.IOException;
28
import java.io.OutputStream;
29
import java.util.List;
30
import java.util.logging.Level;
31
import java.util.logging.Logger;
32
import org.apache.pdfbox.io.MemoryUsageSetting;
33
import org.apache.pdfbox.multipdf.PDFMergerUtility;
34
import org.apache.pdfbox.pdmodel.PDDocumentInformation;
35
import org.gvsig.pdf.lib.api.PDFDocument;
36
import org.gvsig.pdf.lib.api.PDFManager;
37
import org.gvsig.pdf.lib.api.PDFWriter;
38
import org.gvsig.tools.ToolsLocator;
39
import org.gvsig.tools.folders.FoldersManager;
40

  
41
public class DefaultPDFManager implements PDFManager {
42

  
43
    @Override
44
    public PDFDocument createPDFDocument(byte[] document) {
45
        DefaultPDFDocument doc = new DefaultPDFDocument();
46
        doc.setSource(document);
47
        return doc;
48
    }
49

  
50
    @Override
51
    public PDFDocument createPDFDocument(String document) {
52
        DefaultPDFDocument doc = new DefaultPDFDocument();
53
        doc.setSource(document);
54
        return doc;
55
    }
56

  
57
    @Override
58
    public PDFDocument createPDFDocument(File document) {
59
        DefaultPDFDocument doc = new DefaultPDFDocument();
60
        doc.setSource(document);
61
        return doc;
62
    }
63
   
64
    @Override
65
    public PDFDocument createPDFDocument() {
66
        DefaultPDFDocument doc = new DefaultPDFDocument();
67
        return doc;
68
    }
69

  
70
    @Override
71
    public PDFWriter createPDFWriter() {
72
        return new DefaultPDFWriter();
73
    }
74
    
75
    public void merge(List<PDFDocument> inputs, OutputStream output, long maxMemoryToUse, String title, String creator, String subject) {
76
        try {
77
            PDFMergerUtility pdfMerger = new PDFMergerUtility();
78
            pdfMerger.setDestinationStream(output);
79

  
80
            PDDocumentInformation documentInformation = new PDDocumentInformation();
81
            documentInformation.setTitle(title);
82
            documentInformation.setCreator(creator);
83
            documentInformation.setSubject(subject);
84

  
85
            for (PDFDocument input : inputs) {
86
                pdfMerger.addSource(input.getInputStream());
87
            }
88
            FoldersManager folderManager = ToolsLocator.getFoldersManager();
89
            pdfMerger.mergeDocuments(
90
                    MemoryUsageSetting.setupMixed(maxMemoryToUse)
91
                            .setTempDir(folderManager.getTemporaryFolder())
92
            );        
93
        } catch (IOException ex) {
94
            throw new RuntimeException("Can't merge pdf documents", ex);
95
        }
96
    }
97
}
org.gvsig.pdf/tags/org.gvsig.pdf-1.0.87/org.gvsig.pdf.lib/org.gvsig.pdf.lib.impl/src/main/java/org/gvsig/pdf/lib/impl/PDFProfile.java
1
/*
2
 * To change this license header, choose License Headers in Project Properties.
3
 * To change this template file, choose Tools | Templates
4
 * and open the template in the editor.
5
 */
6
package org.gvsig.pdf.lib.impl;
7

  
8
import java.io.File;
9
import org.gvsig.fmap.dal.feature.AbstractDataProfile;
10
import org.gvsig.pdf.lib.api.PDFDocument;
11
import org.gvsig.pdf.lib.api.PDFLocator;
12
import org.gvsig.pdf.lib.api.PDFManager;
13
import org.gvsig.tools.dataTypes.CoercionException;
14
import org.gvsig.tools.dataTypes.DataType;
15
import org.gvsig.tools.dataTypes.DataTypes;
16
import org.gvsig.tools.dynobject.Tags;
17

  
18
public class PDFProfile extends AbstractDataProfile {
19

  
20
    public PDFProfile() {
21
        super("PDF", File.class);
22
    }
23

  
24
    @Override
25
    public Object createData(Object pdf, Tags tags) {
26
        PDFManager manager = PDFLocator.getPDFManager();
27
        PDFDocument pdfdoc = manager.createPDFDocument();
28
        pdfdoc.setSource(pdf);
29
        return pdfdoc;
30
    }
31

  
32
    @Override
33
    public Object coerce(DataType dataType, Object data, Tags tags) throws CoercionException {
34
        PDFDocument document;
35
        try {
36
            switch (dataType.getType()) {
37
                case DataTypes.BYTEARRAY:
38
                    document = PDFLocator.getPDFManager().createPDFDocument();
39
                    document.setSource(data);
40
                    return document.toByteArray();
41
                case DataTypes.FILE:
42
                    if (data instanceof File) {
43
                        return data;
44
                    }
45
                case DataTypes.STRING:
46
                    document = PDFLocator.getPDFManager().createPDFDocument();
47
                    document.setSource(data);
48
                    return document.toHexString();
49
                default:
50
                    break;
51
            }
52
        } catch (Exception ex) {
53
            throw new CoercionException("Can't convert pdf to " + dataType.getName(), ex);
54
        }
55
        throw new CoercionException("Can't convert pdf to " + dataType.getName());
56
    }
57

  
58
}
org.gvsig.pdf/tags/org.gvsig.pdf-1.0.87/org.gvsig.pdf.lib/org.gvsig.pdf.lib.impl/src/main/java/org/gvsig/pdf/lib/impl/DefaultPDFWriter.java
1
package org.gvsig.pdf.lib.impl;
2

  
3
import de.rototor.pdfbox.graphics2d.PdfBoxGraphics2D;
4
import java.awt.Graphics2D;
5
import java.io.IOException;
6
import org.apache.commons.io.output.ByteArrayOutputStream;
7
import org.apache.pdfbox.pdmodel.PDDocument;
8
import org.apache.pdfbox.pdmodel.PDPage;
9
import org.apache.pdfbox.pdmodel.common.PDRectangle;
10
import org.gvsig.pdf.lib.api.PDFDocument;
11
import org.gvsig.pdf.lib.api.PDFWriter;
12

  
13
/**
14
 *
15
 * @author gvSIG Team
16
 */
17

  
18
@SuppressWarnings("UseSpecificCatch")
19
public class DefaultPDFWriter implements PDFWriter {
20

  
21
    private PDRectangle pageSize;
22
    private PdfBoxGraphics2D graphics;
23
    private PDDocument document;
24
    private byte[] data;
25

  
26
    public DefaultPDFWriter() {
27

  
28
    }
29

  
30
    @Override
31
    public void open(int pageSize) {
32
        switch (pageSize) {
33
            case PDFWriter.PAGE_A4:
34
                this.pageSize = PDRectangle.A4;
35
                break;
36
            case PDFWriter.PAGE_A5:
37
                this.pageSize = PDRectangle.A5;
38
                break;
39
            case PDFWriter.PAGE_LEGAL:
40
                this.pageSize = PDRectangle.LEGAL;
41
                break;
42
            case PDFWriter.PAGE_LETTER:
43
                this.pageSize = PDRectangle.LETTER;
44
                break;
45
            default:
46
                throw new IllegalArgumentException("Invalid value of page format");
47
        }
48
        this.close();
49
        this.data = null;
50
    }
51

  
52
    @Override
53
    public void close() {
54
        if( this.graphics!=null ) {
55
            this.graphics.dispose();
56
            this.graphics = null;
57
        }
58
        if( this.document!=null ) {
59
            try {
60
                ByteArrayOutputStream os = new ByteArrayOutputStream();
61
                this.document.save(os);
62
                this.data = os.toByteArray();
63
            } catch (IOException ex) {
64
                this.data = null;
65
            }
66
            this.document = null;
67
        }
68
    }
69

  
70
    @Override
71
    public Graphics2D getGraphics2D() {
72
        try {
73
            if (this.graphics != null) {
74
                return this.graphics;
75
            }
76

  
77
            if (this.document == null) {
78
                this.document = new PDDocument();
79
                PDPage page = new PDPage(this.pageSize);
80
                this.document.addPage(page);
81
            }
82
            this.graphics = new PdfBoxGraphics2D(
83
                    this.document,
84
                    this.pageSize
85
            );
86
            return this.graphics;
87
        } catch (Exception ex) {
88
            throw new RuntimeException("Can't create graphics.", ex);
89
        }
90
    }
91

  
92
    @Override
93
    public float getWidth() {
94
        return this.pageSize.getWidth();
95
    }
96

  
97
    @Override
98
    public float getHeight() {
99
        return this.pageSize.getHeight();
100
    }
101

  
102
    @Override
103
    public byte[] toByteArray() {
104
        if( this.document!=null ) {
105
            this.close();
106
        }
107
        return this.data;
108
    }
109

  
110
    @Override
111
    public PDFDocument toDocument() {
112
        if( this.document!=null ) {
113
            this.close();
114
        }
115
        PDFDocument theDocument = new DefaultPDFDocument();
116
        theDocument.setSource(this.data);
117
        return theDocument;
118
    }
119

  
120
}
org.gvsig.pdf/tags/org.gvsig.pdf-1.0.87/org.gvsig.pdf.lib/org.gvsig.pdf.lib.impl/src/main/java/org/gvsig/pdf/lib/impl/DefaultPDFDocument.java
1
package org.gvsig.pdf.lib.impl;
2

  
3
import java.awt.image.BufferedImage;
4
import java.io.ByteArrayInputStream;
5
import java.io.File;
6
import java.io.FileInputStream;
7
import java.io.FileNotFoundException;
8
import java.io.IOException;
9
import java.io.InputStream;
10
import java.net.URL;
11
import org.gvsig.pdf.lib.api.PDFDocument;
12
import org.slf4j.LoggerFactory;
13
import org.apache.commons.codec.binary.Hex;
14
import org.apache.commons.codec.DecoderException;
15
import org.apache.commons.codec.binary.Base64;
16
import org.apache.pdfbox.pdmodel.PDDocument;
17
import org.apache.pdfbox.rendering.ImageType;
18
import org.apache.pdfbox.rendering.PDFRenderer;
19
import org.gvsig.tools.swing.api.SimpleImage;
20
import org.gvsig.tools.swing.api.ToolsSwingLocator;
21

  
22
/**
23
 *
24
 * @author gvSIG Team
25
 */
26
@SuppressWarnings("UseSpecificCatch")
27
public class DefaultPDFDocument implements PDFDocument {
28

  
29
    private static final org.slf4j.Logger LOGGER = LoggerFactory.getLogger(DefaultPDFDocument.class);
30
    private Object source;
31
    private int nummberOfPages;
32
    private PDDocument document;
33

  
34
    public DefaultPDFDocument() {
35
        this.nummberOfPages = -1;
36
        this.document = null;
37
    }
38

  
39
    @Override
40
    public void setSource(Object source) {
41
        this.source = source;
42
        this.nummberOfPages = -1;
43
        this.document = null;
44
    }
45

  
46
    @Override
47
    public InputStream getInputStream() throws IOException {
48
        InputStream is = null;
49
        if (source == null) {
50
            return null;
51
        } else if (source instanceof File) {
52
            File fileSource = (File) source;
53
            try {
54
                is = new FileInputStream(fileSource);
55
            } catch (IOException ex) {
56
                LOGGER.warn("Not been able to convert file to input stream", ex);
57
                throw new IOException(ex);
58
            }
59
        } else if (source instanceof URL) {
60
            URL urlSource = (URL) source;
61
            try {
62
                is = urlSource.openStream();
63
            } catch (IOException ex) {
64
                LOGGER.warn("Not been able to open URL stream", ex);
65
                throw new IOException(ex);
66
            }
67
        } else if (source instanceof String) {
68
            String strSource = (String) source;
69
            File f = new File(strSource);
70
            if (f.exists()) {
71
                try {
72
                    is = new FileInputStream(f);
73
                } catch (FileNotFoundException ex) {
74
                    LOGGER.warn("Not been able to load existing file", ex);
75
                    throw new IOException(ex);
76
                }
77
            } else {
78
                try {
79
                    URL url = new URL(strSource);
80
                    is = url.openStream();
81
                    is.available(); // Force exception if is null
82
                } catch (Exception ex) {
83
                    try {
84
                        byte[] data = Hex.decodeHex(strSource.toCharArray());
85
                        is = new ByteArrayInputStream(data);
86
                    } catch (DecoderException ex2) {
87
                        try {
88
                            byte[] data = Base64.decodeBase64(strSource);
89
                            is = new ByteArrayInputStream(data);
90
                        } catch (Exception ex3) {
91
                            throw new IOException(ex3);
92
                        }
93
                    }
94
                }
95
            }
96
        } else if (source instanceof byte[]) {
97
            byte[] byteSource = (byte[]) source;
98
            is = new ByteArrayInputStream(byteSource);
99
        }
100

  
101
        return is;
102
    }
103

  
104
    @Override
105
    public byte[] toByteArray() {
106
        if (this.source != null) {
107
            try {
108
                InputStream is = this.getInputStream();
109
                byte[] bytes = new byte[is.available()];
110
                is.read(bytes);
111
                return bytes;
112
            } catch (IOException ex) {
113
                LOGGER.warn("Not been able to convert pdf to byte array", ex);
114
            }
115
        }
116
        return null;
117

  
118
    }
119

  
120
    private String bytearray_hex(byte[] data) {
121
        StringBuilder builder = new StringBuilder();
122
        for (byte abyte : data) {
123
            int v = abyte & 0xff;
124
            builder.append(String.format("%02x", v));
125
        }
126
        return builder.toString();
127
    }
128

  
129
    @Override
130
    public String toHexString() {
131
        byte[] data = this.toByteArray();
132
        return bytearray_hex(data);
133
    }    
134
    
135
    @Override
136
    public int getNumberOfPages() {
137
        if( this.source == null ) {
138
            return -1;
139
        }
140
        if( this.nummberOfPages>=0 ) {
141
            return this.nummberOfPages;
142
        }
143
        try {
144
            InputStream is = this.getInputStream();
145
            this.document = PDDocument.load(is);
146
            this.nummberOfPages = document.getNumberOfPages();
147
            return this.nummberOfPages;
148
        } catch (IOException ex) {
149
            return -1;
150
        }
151
    }
152
    
153
    @Override
154
    public SimpleImage toImage() {
155
        return this.toImage(0, 300);
156
    }
157
    
158
    @Override
159
    public SimpleImage toImage(int page) {
160
        return this.toImage(page, 300);
161
    }
162
    
163
    @Override
164
    public SimpleImage toImage(int page, int dpis) {
165
        if( this.source == null ) {
166
            return null;
167
        }
168
        if( page<0 ) {
169
            return null;
170
        }
171
        try {
172
            if (this.document == null) {
173
                InputStream is = this.getInputStream();
174
                this.document = PDDocument.load(is);
175
                this.nummberOfPages = document.getNumberOfPages();
176
            }
177
            if( page>=this.nummberOfPages ) {
178
                return null;
179
            }
180
            PDFRenderer pdfRenderer = new PDFRenderer(document);
181
            BufferedImage img = pdfRenderer.renderImageWithDPI(page, dpis, ImageType.RGB);
182
            return ToolsSwingLocator.getToolsSwingManager().createSimpleImage(img);
183
        } catch (IOException ex) {
184
            return null;
185
        }
186
    }
187
}
org.gvsig.pdf/tags/org.gvsig.pdf-1.0.87/org.gvsig.pdf.lib/org.gvsig.pdf.lib.impl/src/main/resources/META-INF/services/org.gvsig.tools.library.Library
1
org.gvsig.pdf.lib.impl.PDFImplLibrary
org.gvsig.pdf/tags/org.gvsig.pdf-1.0.87/org.gvsig.pdf.lib/org.gvsig.pdf.lib.impl/pom.xml
1
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
2
    <modelVersion>4.0.0</modelVersion>
3
    <parent>
4
        <groupId>org.gvsig</groupId>
5
        <artifactId>org.gvsig.pdf.lib</artifactId>
6
        <version>1.0.87</version>
7
    </parent>
8
    <artifactId>org.gvsig.pdf.lib.impl</artifactId>
9
    <name>${project.artifactId}</name>
10
    <dependencies>
11
        <dependency>
12
            <groupId>org.gvsig</groupId>
13
            <artifactId>org.gvsig.pdf.lib.api</artifactId>
14
            <scope>compile</scope>
15
        </dependency>
16
        <dependency>
17
            <groupId>org.gvsig</groupId>
18
            <artifactId>org.gvsig.tools.lib</artifactId>
19
            <scope>compile</scope>
20
        </dependency>
21
        <dependency>
22
            <groupId>org.gvsig</groupId>
23
            <artifactId>org.gvsig.fmap.dal.api</artifactId>
24
            <scope>compile</scope>
25
        </dependency>
26
        <dependency>
27
            <groupId>org.gvsig</groupId>
28
            <artifactId>org.gvsig.fmap.dal.swing.api</artifactId>
29
            <scope>compile</scope>
30
        </dependency>
31
        <dependency>
32
            <groupId>commons-codec</groupId>
33
            <artifactId>commons-codec</artifactId>
34
            <scope>compile</scope>
35
        </dependency>
... This diff was truncated because it exceeds the maximum size that can be displayed.

Also available in: Unified diff