Revision 7705
org.gvsig.pdf/trunk/org.gvsig.pdf/org.gvsig.pdf.swing/org.gvsig.pdf.swing.impl/pom.xml | ||
---|---|---|
48 | 48 |
<artifactId>org.gvsig.tools.dynform.services</artifactId> |
49 | 49 |
<scope>compile</scope> |
50 | 50 |
</dependency> |
51 |
<dependency> |
|
52 |
<groupId>org.gvsig</groupId> |
|
53 |
<artifactId>org.gvsig.fmap.dal.swing.api</artifactId> |
|
54 |
<scope>compile</scope> |
|
55 |
</dependency> |
|
51 | 56 |
</dependencies> |
52 | 57 |
</project> |
org.gvsig.pdf/trunk/org.gvsig.pdf/pom.xml | ||
---|---|---|
201 | 201 |
<artifactId>bcprov-ext-jdk15on</artifactId> |
202 | 202 |
<version>1.54</version> |
203 | 203 |
</dependency> |
204 |
<dependency> |
|
204 |
<!-- <dependency>
|
|
205 | 205 |
<groupId>com.itextpdf</groupId> |
206 | 206 |
<artifactId>itextpdf</artifactId> |
207 | 207 |
<version>5.5.8</version> |
208 |
</dependency> |
|
208 |
</dependency>-->
|
|
209 | 209 |
<dependency> |
210 | 210 |
<groupId>org.apache.pdfbox</groupId> |
211 | 211 |
<artifactId>pdfbox</artifactId> |
... | ... | |
226 | 226 |
<artifactId>tika-core</artifactId> |
227 | 227 |
<version>1.12</version> |
228 | 228 |
</dependency> |
229 |
<dependency> |
|
230 |
<groupId>org.apache.pdfbox</groupId> |
|
231 |
<artifactId>xmpbox</artifactId> |
|
232 |
<version>2.0.16</version> |
|
233 |
<type>bundle</type> |
|
234 |
</dependency> |
|
235 |
|
|
236 |
<dependency> |
|
237 |
<groupId>com.openhtmltopdf</groupId> |
|
238 |
<artifactId>openhtmltopdf-pdfbox</artifactId> |
|
239 |
<version>1.0.10</version> |
|
240 |
</dependency> |
|
241 |
<dependency> |
|
242 |
<groupId>com.openhtmltopdf</groupId> |
|
243 |
<artifactId>openhtmltopdf-objects</artifactId> |
|
244 |
<version>1.0.10</version> |
|
245 |
</dependency> |
|
246 |
<dependency> |
|
247 |
<groupId>com.openhtmltopdf</groupId> |
|
248 |
<artifactId>openhtmltopdf-core</artifactId> |
|
249 |
<version>1.0.10</version> |
|
250 |
</dependency> |
|
251 |
<dependency> |
|
252 |
<groupId>com.openhtmltopdf</groupId> |
|
253 |
<artifactId>openhtmltopdf-java2d</artifactId> |
|
254 |
<version>1.0.10</version> |
|
255 |
</dependency> |
|
256 |
<dependency> |
|
257 |
<groupId>com.openhtmltopdf</groupId> |
|
258 |
<artifactId>openhtmltopdf-slf4j</artifactId> |
|
259 |
<version>1.0.10</version> |
|
260 |
</dependency> |
|
261 |
<dependency> |
|
262 |
<groupId>com.openhtmltopdf</groupId> |
|
263 |
<artifactId>openhtmltopdf-rtl-support</artifactId> |
|
264 |
<version>1.0.10</version> |
|
265 |
</dependency> |
|
266 |
<dependency> |
|
267 |
<groupId>com.openhtmltopdf</groupId> |
|
268 |
<artifactId>openhtmltopdf-svg-support</artifactId> |
|
269 |
<version>1.0.10</version> |
|
270 |
</dependency> |
|
271 |
|
|
229 | 272 |
</dependencies> |
230 | 273 |
</dependencyManagement> |
231 | 274 |
|
org.gvsig.pdf/trunk/org.gvsig.pdf/org.gvsig.pdf.app/org.gvsig.pdf.app.mainplugin/src/main/assembly/gvsig-plugin-package.xml | ||
---|---|---|
66 | 66 |
|
67 | 67 |
<include>org.apache.pdfbox:pdfbox</include> |
68 | 68 |
<include>de.rototor.pdfbox:graphics2d</include> |
69 |
<include>org.apache.pdfbox:xmpbox</include> |
|
69 | 70 |
<include>org.apache.pdfbox:fontbox</include> |
70 | 71 |
<include>org.apache.tika:tika-core</include> |
71 | 72 |
|
73 |
<include>com.openhtmltopdf:openhtmltopdf-objects</include> |
|
74 |
<include>com.openhtmltopdf:openhtmltopdf-core</include> |
|
75 |
<include>com.openhtmltopdf:openhtmltopdf-java2d</include> |
|
76 |
<include>com.openhtmltopdf:openhtmltopdf-slf4j</include> |
|
77 |
<include>com.openhtmltopdf:openhtmltopdf-rtl-support</include> |
|
78 |
<include>com.openhtmltopdf:openhtmltopdf-svg-support</include> |
|
79 |
<include>com.openhtmltopdf:openhtmltopdf-pdfbox</include> |
|
80 |
|
|
72 | 81 |
<!-- |
82 |
<include>com.ibm.icu:icu4j</include> |
|
83 |
<include>org.apache.xmlgraphics:batik-transcoder</include> |
|
84 |
<include>org.apache.xmlgraphics:batik-shared-resources</include> |
|
85 |
<include>org.apache.xmlgraphics:batik-svggen</include> |
|
86 |
<include>org.apache.xmlgraphics:batik-codec</include> |
|
87 |
<include>org.apache.xmlgraphics:xmlgraphics-commons</include> |
|
88 |
--> |
|
89 |
|
|
90 |
|
|
91 |
|
|
92 |
<!-- |
|
73 | 93 |
Estos dos jars ya se los esta llevando andami |
74 | 94 |
<include>org.bouncycastle:bcprov-jdk15on</include> |
75 | 95 |
<include>org.bouncycastle:bcprov-ext-jdk15on</include> |
org.gvsig.pdf/trunk/org.gvsig.pdf/org.gvsig.pdf.app/org.gvsig.pdf.app.mainplugin/pom.xml | ||
---|---|---|
83 | 83 |
<groupId>org.apache.tika</groupId> |
84 | 84 |
<artifactId>tika-core</artifactId> |
85 | 85 |
</dependency> |
86 |
|
|
87 |
<dependency> |
|
88 |
<groupId>com.openhtmltopdf</groupId> |
|
89 |
<artifactId>openhtmltopdf-objects</artifactId> |
|
90 |
<scope>runtime</scope> |
|
91 |
</dependency> |
|
92 |
<dependency> |
|
93 |
<groupId>com.openhtmltopdf</groupId> |
|
94 |
<artifactId>openhtmltopdf-core</artifactId> |
|
95 |
<scope>runtime</scope> |
|
96 |
</dependency> |
|
97 |
<dependency> |
|
98 |
<groupId>com.openhtmltopdf</groupId> |
|
99 |
<artifactId>openhtmltopdf-java2d</artifactId> |
|
100 |
<scope>runtime</scope> |
|
101 |
</dependency> |
|
102 |
<dependency> |
|
103 |
<groupId>com.openhtmltopdf</groupId> |
|
104 |
<artifactId>openhtmltopdf-slf4j</artifactId> |
|
105 |
<scope>runtime</scope> |
|
106 |
</dependency> |
|
107 |
<dependency> |
|
108 |
<groupId>com.openhtmltopdf</groupId> |
|
109 |
<artifactId>openhtmltopdf-rtl-support</artifactId> |
|
110 |
<scope>runtime</scope> |
|
111 |
</dependency> |
|
112 |
<dependency> |
|
113 |
<groupId>com.openhtmltopdf</groupId> |
|
114 |
<artifactId>openhtmltopdf-svg-support</artifactId> |
|
115 |
<scope>runtime</scope> |
|
116 |
</dependency> |
|
117 |
<dependency> |
|
118 |
<groupId>com.openhtmltopdf</groupId> |
|
119 |
<artifactId>openhtmltopdf-pdfbox</artifactId> |
|
120 |
<scope>compile</scope> |
|
121 |
</dependency> |
|
122 |
<dependency> |
|
123 |
<groupId>org.apache.pdfbox</groupId> |
|
124 |
<artifactId>xmpbox</artifactId> |
|
125 |
<scope>runtime</scope> |
|
126 |
<!--<type>bundle</type>--> |
|
127 |
<version>2.0.16</version> |
|
128 |
</dependency> |
|
129 |
|
|
130 |
<!-- |
|
131 |
<dependency> |
|
132 |
<groupId>com.ibm.icu</groupId> |
|
133 |
<artifactId>icu4j</artifactId> |
|
134 |
<scope>runtime</scope> |
|
135 |
</dependency> |
|
136 |
<dependency> |
|
137 |
<groupId>org.apache.xmlgraphics</groupId> |
|
138 |
<artifactId>batik-transcoder</artifactId> |
|
139 |
<scope>runtime</scope> |
|
140 |
</dependency> |
|
141 |
<dependency> |
|
142 |
<groupId>org.apache.xmlgraphics</groupId> |
|
143 |
<artifactId>batik-shared-resources</artifactId> |
|
144 |
<scope>runtime</scope> |
|
145 |
</dependency> |
|
146 |
<dependency> |
|
147 |
<groupId>org.apache.xmlgraphics</groupId> |
|
148 |
<artifactId>batik-svggen</artifactId> |
|
149 |
<scope>runtime</scope> |
|
150 |
</dependency> |
|
151 |
<dependency> |
|
152 |
<groupId>org.apache.xmlgraphics</groupId> |
|
153 |
<artifactId>batik-codec</artifactId> |
|
154 |
<scope>runtime</scope> |
|
155 |
</dependency> |
|
156 |
<dependency> |
|
157 |
<groupId>org.apache.xmlgraphics</groupId> |
|
158 |
<artifactId>xmlgraphics-commons</artifactId> |
|
159 |
<scope>runtime</scope> |
|
160 |
</dependency> |
|
161 |
--> |
|
86 | 162 |
</dependencies> |
87 | 163 |
|
88 | 164 |
<properties> |
org.gvsig.pdf/trunk/org.gvsig.pdf/org.gvsig.pdf.lib/org.gvsig.pdf.lib.impl/src/main/java/org/gvsig/pdf/lib/impl/DefaultPDFDocument.java | ||
---|---|---|
1 | 1 |
package org.gvsig.pdf.lib.impl; |
2 | 2 |
|
3 |
import com.openhtmltopdf.pdfboxout.PdfRendererBuilder; |
|
3 | 4 |
import java.awt.image.BufferedImage; |
4 | 5 |
import java.io.ByteArrayInputStream; |
6 |
import java.io.ByteArrayOutputStream; |
|
5 | 7 |
import java.io.File; |
6 | 8 |
import java.io.FileInputStream; |
7 | 9 |
import java.io.FileNotFoundException; |
... | ... | |
14 | 16 |
import org.apache.commons.codec.DecoderException; |
15 | 17 |
import org.apache.commons.codec.binary.Base64; |
16 | 18 |
import org.apache.commons.io.IOUtils; |
19 |
import org.apache.commons.lang3.StringUtils; |
|
17 | 20 |
import org.apache.pdfbox.pdmodel.PDDocument; |
18 | 21 |
import org.apache.pdfbox.rendering.ImageType; |
19 | 22 |
import org.apache.pdfbox.rendering.PDFRenderer; |
... | ... | |
69 | 72 |
} |
70 | 73 |
} else if (source instanceof String) { |
71 | 74 |
String strSource = (String) source; |
72 |
File f = new File(strSource); |
|
73 |
if (f.exists()) { |
|
74 |
try { |
|
75 |
is = new FileInputStream(f); |
|
76 |
} catch (FileNotFoundException ex) { |
|
77 |
LOGGER.warn("Not been able to load existing file", ex); |
|
78 |
throw new IOException(ex); |
|
75 |
if( StringUtils.startsWithIgnoreCase(strSource, "<html>") ) { |
|
76 |
byte[] pdfbytes = html2pdf(strSource); |
|
77 |
if( pdfbytes==null ) { |
|
78 |
throw new IOException(); |
|
79 | 79 |
} |
80 |
is = new ByteArrayInputStream(pdfbytes); |
|
80 | 81 |
} else { |
81 |
try { |
|
82 |
URL url = new URL(strSource); |
|
83 |
is = url.openStream(); |
|
84 |
is.available(); // Force exception if is null |
|
85 |
} catch (Exception ex) { |
|
82 |
File f = new File(strSource); |
|
83 |
if (f.exists()) { |
|
86 | 84 |
try { |
87 |
byte[] data = Hex.decodeHex(strSource.toCharArray()); |
|
88 |
is = new ByteArrayInputStream(data); |
|
89 |
} catch (DecoderException ex2) { |
|
85 |
is = new FileInputStream(f); |
|
86 |
} catch (FileNotFoundException ex) { |
|
87 |
LOGGER.warn("Not been able to load existing file", ex); |
|
88 |
throw new IOException(ex); |
|
89 |
} |
|
90 |
} else { |
|
91 |
try { |
|
92 |
URL url = new URL(strSource); |
|
93 |
is = url.openStream(); |
|
94 |
is.available(); // Force exception if is null |
|
95 |
} catch (Exception ex) { |
|
90 | 96 |
try { |
91 |
byte[] data = Base64.decodeBase64(strSource);
|
|
97 |
byte[] data = Hex.decodeHex(strSource.toCharArray());
|
|
92 | 98 |
is = new ByteArrayInputStream(data); |
93 |
} catch (Exception ex3) { |
|
94 |
throw new IOException(ex3); |
|
99 |
} catch (DecoderException ex2) { |
|
100 |
try { |
|
101 |
byte[] data = Base64.decodeBase64(strSource); |
|
102 |
is = new ByteArrayInputStream(data); |
|
103 |
} catch (Exception ex3) { |
|
104 |
throw new IOException(ex3); |
|
105 |
} |
|
95 | 106 |
} |
96 | 107 |
} |
97 | 108 |
} |
... | ... | |
195 | 206 |
this.nummberOfPages = -1; |
196 | 207 |
this.document = null; |
197 | 208 |
} |
209 |
|
|
210 |
private byte[] html2pdf(String html) { |
|
211 |
ByteArrayOutputStream pdfstream = null; |
|
212 |
try { |
|
213 |
pdfstream = new ByteArrayOutputStream(); |
|
214 |
|
|
215 |
PdfRendererBuilder builder = new PdfRendererBuilder(); |
|
216 |
builder.useFastMode(); |
|
217 |
builder.toStream(pdfstream); |
|
218 |
builder.withHtmlContent(html,null); |
|
219 |
builder.run(); |
|
220 |
return pdfstream.toByteArray(); |
|
221 |
} catch(Throwable t) { |
|
222 |
LOGGER.warn("Can't convert HTML to PDF.",t); |
|
223 |
return null; |
|
224 |
} finally { |
|
225 |
IOUtils.closeQuietly(pdfstream); |
|
226 |
} |
|
227 |
} |
|
198 | 228 |
} |
org.gvsig.pdf/trunk/org.gvsig.pdf/org.gvsig.pdf.lib/org.gvsig.pdf.lib.impl/pom.xml | ||
---|---|---|
52 | 52 |
<dependency> |
53 | 53 |
<groupId>org.apache.pdfbox</groupId> |
54 | 54 |
<artifactId>pdfbox</artifactId> |
55 |
<scope>compile</scope> |
|
55 | 56 |
</dependency> |
56 | 57 |
<dependency> |
57 | 58 |
<groupId>de.rototor.pdfbox</groupId> |
58 | 59 |
<artifactId>graphics2d</artifactId> |
60 |
<scope>compile</scope> |
|
59 | 61 |
</dependency> |
60 | 62 |
<dependency> |
61 | 63 |
<groupId>org.apache.tika</groupId> |
62 | 64 |
<artifactId>tika-core</artifactId> |
65 |
<scope>compile</scope> |
|
63 | 66 |
</dependency> |
67 |
|
|
68 |
<dependency> |
|
69 |
<groupId>com.openhtmltopdf</groupId> |
|
70 |
<artifactId>openhtmltopdf-pdfbox</artifactId> |
|
71 |
<scope>compile</scope> |
|
72 |
</dependency> |
|
73 |
<dependency> |
|
74 |
<groupId>com.openhtmltopdf</groupId> |
|
75 |
<artifactId>openhtmltopdf-core</artifactId> |
|
76 |
<scope>compile</scope> |
|
77 |
</dependency> |
|
78 |
|
|
64 | 79 |
</dependencies> |
65 | 80 |
</project> |
Also available in: Unified diff