clean tests for linux

This commit is contained in:
Jörg Prante 2021-03-03 10:21:30 +01:00
parent 49278772e8
commit 813a781d25
23 changed files with 92 additions and 130 deletions

View file

@ -1,6 +1,6 @@
group = org.xbib.graphics group = org.xbib.graphics
name = graphics name = graphics
version = 4.0.1 version = 4.0.2
gradle.wrapper.version = 6.6.1 gradle.wrapper.version = 6.6.1
pdfbox.version = 2.0.22 pdfbox.version = 2.0.22

View file

@ -22,7 +22,7 @@ import java.nio.file.Files;
import java.nio.file.Paths; import java.nio.file.Paths;
import java.util.Locale; import java.util.Locale;
public class SvgRendererTest { public class SVGRendererTest {
private Locale originalDefaultLocale; private Locale originalDefaultLocale;

View file

@ -26,7 +26,6 @@ clipsave
gsave gsave
0.0 0.0 0.0 rgb 0.0 0.0 0.0 rgb
1.0 setlinewidth 0 setlinejoin 0 setlinecap [] 0.0 setdash 1.0 setlinewidth 0 setlinejoin 0 setlinecap [] 0.0 setdash
/DejaVuSansLat /DejaVuSans latinize /DejaVuSansLat 12.0 selectfont
1.0 1.0 1.0 rgb 1.0 1.0 1.0 rgb
newpath 0.0 0.0 128.0 60.0 rect Z fill newpath 0.0 0.0 128.0 60.0 rect Z fill
0.0 0.0 0.0 rgb 0.0 0.0 0.0 rgb

View file

@ -32,15 +32,11 @@ q
/Fnt0 12.0 Tf /Fnt0 12.0 Tf
q q
0 J 0 J
/Fnt0 12.0 Tf
0 0 m 128 0 l 128 60 l 0 60 l 0 0 l h f 0 0 m 128 0 l 128 60 l 0 60 l 0 0 l h f
Q Q
q q
0 0 0 rg 0 0 0 RG 0 0 0 rg 0 0 0 RG
0 J 0 J
/Fnt0 12.0 Tf
5 5 m 6 5 l 6 45 l 5 45 l h f 5 5 m 6 5 l 6 45 l 5 45 l h f
7 5 m 8 5 l 8 45 l 7 45 l h f 7 5 m 8 5 l 8 45 l 7 45 l h f
9 5 m 13 5 l 13 45 l 9 45 l h f 9 5 m 13 5 l 13 45 l 9 45 l h f
@ -93,7 +89,7 @@ Q
endstream endstream
endobj endobj
5 0 obj 5 0 obj
1684 1654
endobj endobj
6 0 obj 6 0 obj
<< <<
@ -121,13 +117,13 @@ xref
0000000058 00000 n 0000000058 00000 n
0000000115 00000 n 0000000115 00000 n
0000000248 00000 n 0000000248 00000 n
0000001984 00000 n 0000001954 00000 n
0000002004 00000 n 0000001974 00000 n
trailer trailer
<< <<
/Size 7 /Size 7
/Root 1 0 R /Root 1 0 R
>> >>
startxref startxref
2267 2237
%%EOF %%EOF

View file

@ -26,7 +26,6 @@ clipsave
gsave gsave
0.0 0.0 0.0 rgb 0.0 0.0 0.0 rgb
1.0 setlinewidth 0 setlinejoin 0 setlinecap [] 0.0 setdash 1.0 setlinewidth 0 setlinejoin 0 setlinecap [] 0.0 setdash
/DejaVuSansLat /DejaVuSans latinize /DejaVuSansLat 12.0 selectfont
0.0 1.0 0.0 rgb 0.0 1.0 0.0 rgb
newpath 0.0 0.0 128.0 60.0 rect Z fill newpath 0.0 0.0 128.0 60.0 rect Z fill
1.0 0.0 0.0 rgb 1.0 0.0 0.0 rgb

View file

@ -33,15 +33,11 @@ q
q q
0 1 0 rg 0 1 0 RG 0 1 0 rg 0 1 0 RG
0 J 0 J
/Fnt0 12.0 Tf
0 0 m 128 0 l 128 60 l 0 60 l 0 0 l h f 0 0 m 128 0 l 128 60 l 0 60 l 0 0 l h f
Q Q
q q
1 0 0 rg 1 0 0 RG 1 0 0 rg 1 0 0 RG
0 J 0 J
/Fnt0 12.0 Tf
5 5 m 6 5 l 6 45 l 5 45 l h f 5 5 m 6 5 l 6 45 l 5 45 l h f
7 5 m 8 5 l 8 45 l 7 45 l h f 7 5 m 8 5 l 8 45 l 7 45 l h f
9 5 m 13 5 l 13 45 l 9 45 l h f 9 5 m 13 5 l 13 45 l 9 45 l h f
@ -94,7 +90,7 @@ Q
endstream endstream
endobj endobj
5 0 obj 5 0 obj
1702 1672
endobj endobj
6 0 obj 6 0 obj
<< <<
@ -122,13 +118,13 @@ xref
0000000058 00000 n 0000000058 00000 n
0000000115 00000 n 0000000115 00000 n
0000000248 00000 n 0000000248 00000 n
0000002002 00000 n 0000001972 00000 n
0000002022 00000 n 0000001992 00000 n
trailer trailer
<< <<
/Size 7 /Size 7
/Root 1 0 R /Root 1 0 R
>> >>
startxref startxref
2285 2255
%%EOF %%EOF

View file

@ -26,7 +26,6 @@ clipsave
gsave gsave
0.0 0.0 0.0 rgb 0.0 0.0 0.0 rgb
1.0 setlinewidth 0 setlinejoin 0 setlinecap [] 0.0 setdash 1.0 setlinewidth 0 setlinejoin 0 setlinecap [] 0.0 setdash
/DejaVuSansLat /DejaVuSans latinize /DejaVuSansLat 12.0 selectfont
1.0 1.0 1.0 rgb 1.0 1.0 1.0 rgb
newpath 0.0 0.0 128.0 82.0 rect Z fill newpath 0.0 0.0 128.0 82.0 rect Z fill
0.0 0.0 0.0 rgb 0.0 0.0 0.0 rgb

View file

@ -32,15 +32,11 @@ q
/Fnt0 12.0 Tf /Fnt0 12.0 Tf
q q
0 J 0 J
/Fnt0 12.0 Tf
0 0 m 128 0 l 128 82 l 0 82 l 0 0 l h f 0 0 m 128 0 l 128 82 l 0 82 l 0 0 l h f
Q Q
q q
0 0 0 rg 0 0 0 RG 0 0 0 rg 0 0 0 RG
0 J 0 J
/Fnt0 12.0 Tf
5 5 m 6 5 l 6 45 l 5 45 l h f 5 5 m 6 5 l 6 45 l 5 45 l h f
7 5 m 8 5 l 8 45 l 7 45 l h f 7 5 m 8 5 l 8 45 l 7 45 l h f
9 5 m 13 5 l 13 45 l 9 45 l h f 9 5 m 13 5 l 13 45 l 9 45 l h f
@ -93,7 +89,7 @@ Q
endstream endstream
endobj endobj
5 0 obj 5 0 obj
1688 1658
endobj endobj
6 0 obj 6 0 obj
<< <<
@ -121,13 +117,13 @@ xref
0000000058 00000 n 0000000058 00000 n
0000000115 00000 n 0000000115 00000 n
0000000248 00000 n 0000000248 00000 n
0000001988 00000 n 0000001958 00000 n
0000002008 00000 n 0000001978 00000 n
trailer trailer
<< <<
/Size 7 /Size 7
/Root 1 0 R /Root 1 0 R
>> >>
startxref startxref
2271 2241
%%EOF %%EOF

View file

@ -26,7 +26,6 @@ clipsave
gsave gsave
0.0 0.0 0.0 rgb 0.0 0.0 0.0 rgb
1.0 setlinewidth 0 setlinejoin 0 setlinecap [] 0.0 setdash 1.0 setlinewidth 0 setlinejoin 0 setlinecap [] 0.0 setdash
/DejaVuSansLat /DejaVuSans latinize /DejaVuSansLat 12.0 selectfont
1.0 1.0 1.0 rgb 1.0 1.0 1.0 rgb
newpath 0.0 0.0 256.0 120.0 rect Z fill newpath 0.0 0.0 256.0 120.0 rect Z fill
0.0 0.0 0.0 rgb 0.0 0.0 0.0 rgb

View file

@ -32,15 +32,11 @@ q
/Fnt0 12.0 Tf /Fnt0 12.0 Tf
q q
0 J 0 J
/Fnt0 12.0 Tf
0 0 m 256 0 l 256 120 l 0 120 l 0 0 l h f 0 0 m 256 0 l 256 120 l 0 120 l 0 0 l h f
Q Q
q q
0 0 0 rg 0 0 0 RG 0 0 0 rg 0 0 0 RG
0 J 0 J
/Fnt0 12.0 Tf
10 10 m 12 10 l 12 90 l 10 90 l h f 10 10 m 12 10 l 12 90 l 10 90 l h f
14 10 m 16 10 l 16 90 l 14 90 l h f 14 10 m 16 10 l 16 90 l 14 90 l h f
18 10 m 26 10 l 26 90 l 18 90 l h f 18 10 m 26 10 l 26 90 l 18 90 l h f
@ -93,7 +89,7 @@ Q
endstream endstream
endobj endobj
5 0 obj 5 0 obj
1845 1815
endobj endobj
6 0 obj 6 0 obj
<< <<
@ -121,13 +117,13 @@ xref
0000000058 00000 n 0000000058 00000 n
0000000115 00000 n 0000000115 00000 n
0000000248 00000 n 0000000248 00000 n
0000002145 00000 n 0000002115 00000 n
0000002165 00000 n 0000002135 00000 n
trailer trailer
<< <<
/Size 7 /Size 7
/Root 1 0 R /Root 1 0 R
>> >>
startxref startxref
2428 2398
%%EOF %%EOF

View file

@ -26,7 +26,6 @@ clipsave
gsave gsave
0.0 0.0 0.0 rgb 0.0 0.0 0.0 rgb
1.0 setlinewidth 0 setlinejoin 0 setlinecap [] 0.0 setdash 1.0 setlinewidth 0 setlinejoin 0 setlinecap [] 0.0 setdash
/DejaVuSansLat /DejaVuSans latinize /DejaVuSansLat 12.0 selectfont
1.0 1.0 1.0 rgb 1.0 1.0 1.0 rgb
newpath 0.0 0.0 158.0 90.0 rect Z fill newpath 0.0 0.0 158.0 90.0 rect Z fill
0.0 0.0 0.0 rgb 0.0 0.0 0.0 rgb

View file

@ -32,15 +32,11 @@ q
/Fnt0 12.0 Tf /Fnt0 12.0 Tf
q q
0 J 0 J
/Fnt0 12.0 Tf
0 0 m 158 0 l 158 90 l 0 90 l 0 0 l h f 0 0 m 158 0 l 158 90 l 0 90 l 0 0 l h f
Q Q
q q
0 0 0 rg 0 0 0 RG 0 0 0 rg 0 0 0 RG
0 J 0 J
/Fnt0 12.0 Tf
20 20 m 21 20 l 21 60 l 20 60 l h f 20 20 m 21 20 l 21 60 l 20 60 l h f
22 20 m 23 20 l 23 60 l 22 60 l h f 22 20 m 23 20 l 23 60 l 22 60 l h f
24 20 m 28 20 l 28 60 l 24 60 l h f 24 20 m 28 20 l 28 60 l 24 60 l h f
@ -93,7 +89,7 @@ Q
endstream endstream
endobj endobj
5 0 obj 5 0 obj
1795 1765
endobj endobj
6 0 obj 6 0 obj
<< <<
@ -121,13 +117,13 @@ xref
0000000058 00000 n 0000000058 00000 n
0000000115 00000 n 0000000115 00000 n
0000000247 00000 n 0000000247 00000 n
0000002094 00000 n 0000002064 00000 n
0000002114 00000 n 0000002084 00000 n
trailer trailer
<< <<
/Size 7 /Size 7
/Root 1 0 R /Root 1 0 R
>> >>
startxref startxref
2377 2347
%%EOF %%EOF

View file

@ -26,7 +26,6 @@ clipsave
gsave gsave
0.0 0.0 0.0 rgb 0.0 0.0 0.0 rgb
1.0 setlinewidth 0 setlinejoin 0 setlinecap [] 0.0 setdash 1.0 setlinewidth 0 setlinejoin 0 setlinecap [] 0.0 setdash
/DejaVuSansLat /DejaVuSans latinize /DejaVuSansLat 12.0 selectfont
1.0 1.0 1.0 rgb 1.0 1.0 1.0 rgb
newpath 0.0 0.0 420.0 410.0 rect Z fill newpath 0.0 0.0 420.0 410.0 rect Z fill
0.0 0.0 0.0 rgb 0.0 0.0 0.0 rgb

View file

@ -32,15 +32,11 @@ q
/Fnt0 12.0 Tf /Fnt0 12.0 Tf
q q
0 J 0 J
/Fnt0 12.0 Tf
0 0 m 420 0 l 420 410 l 0 410 l 0 0 l h f 0 0 m 420 0 l 420 410 l 0 410 l 0 0 l h f
Q Q
q q
0 0 0 rg 0 0 0 RG 0 0 0 rg 0 0 0 RG
0 J 0 J
/Fnt0 12.0 Tf
43.45 38.4 m 48.825 35.275 l 48.825 29.025 l 43.45 25.9 l 38.075 29.025 l 38.075 35.275 l h f 43.45 38.4 m 48.825 35.275 l 48.825 29.025 l 43.45 25.9 l 38.075 29.025 l 38.075 35.275 l h f
68.05 38.4 m 73.425 35.275 l 73.425 29.025 l 68.05 25.9 l 62.675 29.025 l 62.675 35.275 l h f 68.05 38.4 m 73.425 35.275 l 73.425 29.025 l 68.05 25.9 l 62.675 29.025 l 62.675 35.275 l h f
92.65 38.4 m 98.025 35.275 l 98.025 29.025 l 92.65 25.9 l 87.275 29.025 l 87.275 35.275 l h f 92.65 38.4 m 98.025 35.275 l 98.025 29.025 l 92.65 25.9 l 87.275 29.025 l 87.275 35.275 l h f
@ -414,41 +410,31 @@ q
Q Q
q q
0 J 0 J
/Fnt0 12.0 Tf
248.64999999999998 203 m 248.64999999999998 227.76997102991106 228.56997102991107 247.85 203.79999999999998 247.85 c 179.0300289700889 247.85 158.95 227.76997102991106 158.95 203 c 158.95 178.2300289700889 179.0300289700889 158.15 203.79999999999998 158.15 c 228.56997102991107 158.15 248.64999999999998 178.2300289700889 248.64999999999998 203 c h f 248.64999999999998 203 m 248.64999999999998 227.76997102991106 228.56997102991107 247.85 203.79999999999998 247.85 c 179.0300289700889 247.85 158.95 227.76997102991106 158.95 203 c 158.95 178.2300289700889 179.0300289700889 158.15 203.79999999999998 158.15 c 228.56997102991107 158.15 248.64999999999998 178.2300289700889 248.64999999999998 203 c h f
Q Q
q q
0 0 0 rg 0 0 0 RG 0 0 0 rg 0 0 0 RG
0 J 0 J
/Fnt0 12.0 Tf
239.3 203 m 239.3 222.60610861899318 223.40610861899316 238.5 203.79999999999998 238.5 c 184.19389138100684 238.5 168.29999999999998 222.60610861899318 168.29999999999998 203 c 168.29999999999998 183.39389138100685 184.19389138100684 167.5 203.79999999999998 167.5 c 223.40610861899316 167.5 239.3 183.39389138100685 239.3 203 c h f 239.3 203 m 239.3 222.60610861899318 223.40610861899316 238.5 203.79999999999998 238.5 c 184.19389138100684 238.5 168.29999999999998 222.60610861899318 168.29999999999998 203 c 168.29999999999998 183.39389138100685 184.19389138100684 167.5 203.79999999999998 167.5 c 223.40610861899316 167.5 239.3 183.39389138100685 239.3 203 c h f
Q Q
q q
0 J 0 J
/Fnt0 12.0 Tf
229.89999999999998 203 m 229.89999999999998 217.41463197058368 218.2146319705837 229.1 203.79999999999998 229.1 c 189.38536802941627 229.1 177.7 217.41463197058368 177.7 203 c 177.7 188.5853680294163 189.38536802941627 176.9 203.79999999999998 176.9 c 218.2146319705837 176.9 229.89999999999998 188.5853680294163 229.89999999999998 203 c h f 229.89999999999998 203 m 229.89999999999998 217.41463197058368 218.2146319705837 229.1 203.79999999999998 229.1 c 189.38536802941627 229.1 177.7 217.41463197058368 177.7 203 c 177.7 188.5853680294163 189.38536802941627 176.9 203.79999999999998 176.9 c 218.2146319705837 176.9 229.89999999999998 188.5853680294163 229.89999999999998 203 c h f
Q Q
q q
0 0 0 rg 0 0 0 RG 0 0 0 rg 0 0 0 RG
0 J 0 J
/Fnt0 12.0 Tf
220.35 203 m 220.35 212.14031260969963 212.94031260969962 219.55 203.79999999999998 219.55 c 194.65968739030035 219.55 187.24999999999997 212.14031260969963 187.24999999999997 203 c 187.24999999999997 193.85968739030037 194.65968739030035 186.45 203.79999999999998 186.45 c 212.94031260969962 186.45 220.35 193.85968739030037 220.35 203 c h f 220.35 203 m 220.35 212.14031260969963 212.94031260969962 219.55 203.79999999999998 219.55 c 194.65968739030035 219.55 187.24999999999997 212.14031260969963 187.24999999999997 203 c 187.24999999999997 193.85968739030037 194.65968739030035 186.45 203.79999999999998 186.45 c 212.94031260969962 186.45 220.35 193.85968739030037 220.35 203 c h f
Q Q
q q
0 J 0 J
/Fnt0 12.0 Tf
210.95 203.00000000000003 m 210.95 206.9488359612902 207.74883596129015 210.15000000000003 203.79999999999998 210.15000000000003 c 199.8511640387098 210.15000000000003 196.64999999999998 206.9488359612902 196.64999999999998 203.00000000000003 c 196.64999999999998 199.05116403870986 199.8511640387098 195.85000000000002 203.79999999999998 195.85000000000002 c 207.74883596129015 195.85000000000002 210.95 199.05116403870986 210.95 203.00000000000003 c h f 210.95 203.00000000000003 m 210.95 206.9488359612902 207.74883596129015 210.15000000000003 203.79999999999998 210.15000000000003 c 199.8511640387098 210.15000000000003 196.64999999999998 206.9488359612902 196.64999999999998 203.00000000000003 c 196.64999999999998 199.05116403870986 199.8511640387098 195.85000000000002 203.79999999999998 195.85000000000002 c 207.74883596129015 195.85000000000002 210.95 199.05116403870986 210.95 203.00000000000003 c h f
Q Q
Q Q
endstream endstream
endobj endobj
5 0 obj 5 0 obj
64455 64350
endobj endobj
6 0 obj 6 0 obj
<< <<
@ -470,13 +456,13 @@ xref
0000000058 00000 n 0000000058 00000 n
0000000115 00000 n 0000000115 00000 n
0000000248 00000 n 0000000248 00000 n
0000064755 00000 n 0000064650 00000 n
0000064776 00000 n 0000064671 00000 n
trailer trailer
<< <<
/Size 7 /Size 7
/Root 1 0 R /Root 1 0 R
>> >>
startxref startxref
64947 64842
%%EOF %%EOF

View file

@ -91,7 +91,7 @@ public class PDFConverter {
this.compatibilityLevel = compatibilityLevel; this.compatibilityLevel = compatibilityLevel;
this.pdfx = pdfx; this.pdfx = pdfx;
this.paperSize = paperSize; this.paperSize = paperSize;
this.tmpPath = Paths.get("/var/tmp/" + this); this.tmpPath = Paths.get(System.getProperty("java.io.tmpdir", "/var/tmp")).resolve(toString());
} }
/** /**

View file

@ -25,6 +25,7 @@ import java.io.OutputStream;
import java.nio.file.FileVisitResult; import java.nio.file.FileVisitResult;
import java.nio.file.Files; import java.nio.file.Files;
import java.nio.file.Path; import java.nio.file.Path;
import java.nio.file.PathMatcher;
import java.nio.file.Paths; import java.nio.file.Paths;
import java.nio.file.SimpleFileVisitor; import java.nio.file.SimpleFileVisitor;
import java.nio.file.StandardCopyOption; import java.nio.file.StandardCopyOption;
@ -46,26 +47,31 @@ public class PDFRasterizer implements Closeable {
private static final Logger logger = Logger.getLogger(PDFRasterizer.class.getName()); private static final Logger logger = Logger.getLogger(PDFRasterizer.class.getName());
private final String creator; private String creator;
private final String author; private String author;
private final String subject; private String subject;
private final Map<String, ImageReader> imageReaders; private final Map<String, ImageReader> imageReaders;
private final Path tmpPath; private final Path tmpPath;
public PDFRasterizer(String subject) { public PDFRasterizer() {
this("org.xbib.graphics.ghostscript/4.0.1", "Jörg Prante", subject); this.imageReaders = createImageReaders();
this.tmpPath = Paths.get(System.getProperty("java.io.tmpdir", "/var/tmp")).resolve(toString());
} }
public PDFRasterizer(String creator, String author, String subject) { public void setCreator(String creator) {
this.creator = creator; this.creator = creator;
}
public void setAuthor(String author) {
this.author = author; this.author = author;
}
public void setSubject(String subject) {
this.subject = subject; this.subject = subject;
this.imageReaders = createImageReaders();
this.tmpPath = Paths.get("/var/tmp/" + this);
} }
@Override @Override
@ -199,21 +205,33 @@ public class PDFRasterizer implements Closeable {
} }
} }
public synchronized int mergeImagesToPDF(Path sourceDir, Path targetFile) throws IOException { public int mergeImagesToPDF(Path sourceDir, Path targetFile) throws IOException {
logger.info("mergeImagesToPDF: source=" + sourceDir + " target=" + targetFile); return mergeImagesToPDF(sourceDir, targetFile, "**/*");
}
public synchronized int mergeImagesToPDF(Path sourceDir, Path targetFile, String globPattern) throws IOException {
logger.info("mergeImagesToPDF: source=" + sourceDir + " target=" + targetFile + " glob =" + globPattern);
int pagecount = 0; int pagecount = 0;
PathMatcher pathMatcher = sourceDir.getFileSystem().getPathMatcher("glob:" + globPattern);
List<PDDocument> coverPageDocs = new ArrayList<>(); List<PDDocument> coverPageDocs = new ArrayList<>();
try (Stream<Path> files = Files.list(sourceDir); try (Stream<Path> files = Files.list(sourceDir);
PDDocument pdDocument = new PDDocument(MemoryUsageSetting.setupTempFileOnly()); PDDocument pdDocument = new PDDocument(MemoryUsageSetting.setupTempFileOnly());
OutputStream outputStream = new BufferedOutputStream(Files.newOutputStream(targetFile))) { OutputStream outputStream = new BufferedOutputStream(Files.newOutputStream(targetFile))) {
List<Path> entries = files.sorted() List<Path> entries = files.sorted()
.filter(PDFRasterizer::checkForRealFile) .filter(PDFRasterizer::checkForRealFile)
.filter(pathMatcher::matches)
.collect(Collectors.toList()); .collect(Collectors.toList());
pdDocument.getDocumentInformation().setTitle(targetFile.getFileName().toString()); pdDocument.getDocumentInformation().setTitle(targetFile.getFileName().toString());
pdDocument.getDocumentInformation().setCreationDate(Calendar.getInstance()); pdDocument.getDocumentInformation().setCreationDate(Calendar.getInstance());
if (creator != null) {
pdDocument.getDocumentInformation().setCreator(creator); pdDocument.getDocumentInformation().setCreator(creator);
}
if (subject != null) {
pdDocument.getDocumentInformation().setSubject(subject); pdDocument.getDocumentInformation().setSubject(subject);
}
if (author != null) {
pdDocument.getDocumentInformation().setAuthor(author); pdDocument.getDocumentInformation().setAuthor(author);
}
for (Path path : entries) { for (Path path : entries) {
if (path.getFileName().toString().toLowerCase(Locale.ROOT).endsWith(".pdf")) { if (path.getFileName().toString().toLowerCase(Locale.ROOT).endsWith(".pdf")) {
logger.info("found pdf " + path); logger.info("found pdf " + path);
@ -237,7 +255,6 @@ public class PDFRasterizer implements Closeable {
logger.log(Level.WARNING, "skipping image because too large: " + path + " size = " + size); logger.log(Level.WARNING, "skipping image because too large: " + path + " size = " + size);
} else { } else {
BufferedImage bufferedImage = readImage(path); BufferedImage bufferedImage = readImage(path);
if (bufferedImage != null) {
PDPage page = new PDPage(new PDRectangle(bufferedImage.getWidth(), bufferedImage.getHeight())); PDPage page = new PDPage(new PDRectangle(bufferedImage.getWidth(), bufferedImage.getHeight()));
pdDocument.addPage(page); pdDocument.addPage(page);
PDImageXObject pdImageXObject = LosslessFactory.createFromImage(pdDocument, bufferedImage); PDImageXObject pdImageXObject = LosslessFactory.createFromImage(pdDocument, bufferedImage);
@ -253,10 +270,6 @@ public class PDFRasterizer implements Closeable {
throw new IOException("unable to create PDImageXObject from buffered image"); throw new IOException("unable to create PDImageXObject from buffered image");
} }
bufferedImage.flush(); bufferedImage.flush();
} else {
logger.log(Level.WARNING, "unable to read into a buffered image frmo " + path);
throw new IOException("unable to read into a buffered image");
}
} }
} }
} }
@ -424,7 +437,7 @@ public class PDFRasterizer implements Closeable {
imageReader.setInput(imageInputStream); imageReader.setInput(imageInputStream);
ImageReadParam param = imageReader.getDefaultReadParam(); ImageReadParam param = imageReader.getDefaultReadParam();
BufferedImage bufferedImage = imageReader.read(0, param); BufferedImage bufferedImage = imageReader.read(0, param);
logger.log(Level.FINE, "path = " + path + "loaded: width = " + bufferedImage.getWidth() + logger.log(Level.FINE, "path = " + path + " loaded, width = " + bufferedImage.getWidth() +
" height = " + bufferedImage.getHeight() + " height = " + bufferedImage.getHeight() +
" color model = " + bufferedImage.getColorModel()); " color model = " + bufferedImage.getColorModel());
imageInputStream.close(); imageInputStream.close();

View file

@ -22,12 +22,9 @@ public class PDFRasterizerTest {
@Test @Test
public void testPDFCreation() throws IOException { public void testPDFCreation() throws IOException {
String creator = "Xbib PDF";
String author = "Jörg Prante";
String subject = "Test";
Path sourceDir = Paths.get("src/test/resources/org/xbib/graphics/ghostscript/test/images-3656573"); Path sourceDir = Paths.get("src/test/resources/org/xbib/graphics/ghostscript/test/images-3656573");
Path targetFile = Paths.get("build/3656573.pdf"); Path targetFile = Paths.get("build/3656573.pdf");
PDFRasterizer pdfRasterizer = new PDFRasterizer(creator, author, subject); PDFRasterizer pdfRasterizer = new PDFRasterizer();
int pagecount = pdfRasterizer.mergeImagesToPDF(sourceDir, targetFile); int pagecount = pdfRasterizer.mergeImagesToPDF(sourceDir, targetFile);
logger.info("pagecount = " + pagecount); logger.info("pagecount = " + pagecount);
pdfRasterizer.close(); pdfRasterizer.close();
@ -35,12 +32,9 @@ public class PDFRasterizerTest {
@Test @Test
public void testPDFColorImage() throws IOException { public void testPDFColorImage() throws IOException {
String creator = "Xbib PDF";
String author = "Jörg Prante";
String subject = "Test";
Path sourceDir = Paths.get("src/test/resources/org/xbib/graphics/ghostscript/test/images"); Path sourceDir = Paths.get("src/test/resources/org/xbib/graphics/ghostscript/test/images");
Path targetFile = Paths.get("build/color.pdf"); Path targetFile = Paths.get("build/color.pdf");
PDFRasterizer pdfRasterizer = new PDFRasterizer(creator, author, subject); PDFRasterizer pdfRasterizer = new PDFRasterizer();
int pagecount = pdfRasterizer.mergeImagesToPDF(sourceDir, targetFile); int pagecount = pdfRasterizer.mergeImagesToPDF(sourceDir, targetFile);
logger.info("pagecount = " + pagecount); logger.info("pagecount = " + pagecount);
pdfRasterizer.close(); pdfRasterizer.close();
@ -52,7 +46,7 @@ public class PDFRasterizerTest {
Path target = Paths.get("build/20200024360-new.pdf"); Path target = Paths.get("build/20200024360-new.pdf");
Path tmp = Files.createTempDirectory("graphics-test"); Path tmp = Files.createTempDirectory("graphics-test");
try { try {
PDFRasterizer pdfRasterizer = new PDFRasterizer("xbib", "Jörg Prante", "Test"); PDFRasterizer pdfRasterizer = new PDFRasterizer();
pdfRasterizer.pdfToImage(source, tmp, null, null); pdfRasterizer.pdfToImage(source, tmp, null, null);
Path tmpTarget = tmp.resolve(target.getFileName()); Path tmpTarget = tmp.resolve(target.getFileName());
int pagecount = pdfRasterizer.mergeImagesToPDF(tmp, tmpTarget); int pagecount = pdfRasterizer.mergeImagesToPDF(tmp, tmpTarget);
@ -74,9 +68,7 @@ public class PDFRasterizerTest {
try { try {
delete(target); delete(target);
Files.createDirectories(target); Files.createDirectories(target);
PDFRasterizer rasterizer = new PDFRasterizer( PDFRasterizer rasterizer = new PDFRasterizer();
"org.xbib.graphics.ghostscript", "Jörg Prante",
"converted from " + p);
rasterizer.pdfToImage(p, target, "pdf-", "1-"); rasterizer.pdfToImage(p, target, "pdf-", "1-");
rasterizer.close(); rasterizer.close();
} catch (IOException e) { } catch (IOException e) {
@ -90,7 +82,6 @@ public class PDFRasterizerTest {
@Test @Test
public void testPDFRasterizerConvert() throws Exception { public void testPDFRasterizerConvert() throws Exception {
logger.log(Level.INFO, "testing java.io.tmpdir = " + System.getProperty("java.io.tmpdir"));
Path path = Paths.get("build/resources/test"); Path path = Paths.get("build/resources/test");
try (Stream<Path> stream = Files.list(path)) { try (Stream<Path> stream = Files.list(path)) {
stream.forEach(p -> { stream.forEach(p -> {
@ -100,9 +91,7 @@ public class PDFRasterizerTest {
try { try {
delete(target); delete(target);
Files.createDirectories(target.getParent()); Files.createDirectories(target.getParent());
PDFRasterizer rasterizer = new PDFRasterizer( PDFRasterizer rasterizer = new PDFRasterizer();
"org.xbib.graphics.ghostscript", "Jörg Prante",
"converted from " + p);
rasterizer.convert(p, target); rasterizer.convert(p, target);
rasterizer.close(); rasterizer.close();
} catch (IOException e) { } catch (IOException e) {

View file

@ -32,14 +32,11 @@ public class TiffTest {
@Test @Test
public void mergeTiff() throws IOException { public void mergeTiff() throws IOException {
String creator = "Malva PDF";
String author = "Jörg Prante";
String subject = "Test";
Path sourceDir = Paths.get("src/test/resources/org/xbib/graphics/ghostscript/test/"); Path sourceDir = Paths.get("src/test/resources/org/xbib/graphics/ghostscript/test/");
Path targetFile = Paths.get("build/tmp.pdf"); Path targetFile = Paths.get("build/tmp.pdf");
PDFRasterizer pdfRasterizer = new PDFRasterizer(creator, author, subject); PDFRasterizer pdfRasterizer = new PDFRasterizer();
int pagecount = pdfRasterizer.mergeImagesToPDF(sourceDir, targetFile); int pagecount = pdfRasterizer.mergeImagesToPDF(sourceDir, targetFile, "**/*.tif");
logger.info("pagecount = " + pagecount); logger.info("pagecount = " + pagecount);
assertEquals(3, pagecount); assertEquals(2, pagecount);
} }
} }

View file

@ -370,7 +370,7 @@ abstract class BaseBuilderSpec extends Specification {
when: when:
List layout = [ List layout = [
[ key: 'Typ', value: 'Online', 'bold':true], [ key: 'Typ', value: 'Online', 'bold':true],
[ key: 'Medea-Nummer', value: 'test'], [ key: 'Nummer', value: 'test'],
[ key: 'Bestelldatum', value: 'test'], [ key: 'Bestelldatum', value: 'test'],
[ key: 'Eingangsdatum', value: 'test'], [ key: 'Eingangsdatum', value: 'test'],
[ key: 'Besteller', value: 'test', line: true], [ key: 'Besteller', value: 'test', line: true],
@ -399,7 +399,7 @@ abstract class BaseBuilderSpec extends Specification {
paragraph(margin:[left: 6.cm, right: 1.cm, top: -1.5.cm]) { paragraph(margin:[left: 6.cm, right: 1.cm, top: -1.5.cm]) {
font.size = 24.pt font.size = 24.pt
font.bold = true font.bold = true
text 'Aufsatzbestellung Lieferschein' text 'Lieferschein'
} }
paragraph { paragraph {
table(margin:[left: 1.cm, top: 2.cm], width: 19.cm, padding: 0.pt, border:[size:0.pt]) { table(margin:[left: 1.cm, top: 2.cm], width: 19.cm, padding: 0.pt, border:[size:0.pt]) {

View file

@ -28,13 +28,13 @@ class FontSpec extends Specification {
} }
def "printable characters"() { def "printable characters"() {
String s = "\u0098 Hello Jörg" String s = "\u0098 Hello World"
when: when:
s = s.replaceAll("\\p{C}", "") s = s.replaceAll("\\p{C}", "")
then: then:
s == " Hello Jörg" s == " Hello World"
} }
def "glyph exists"() { def "glyph exists"() {

View file

@ -9,6 +9,8 @@ import java.nio.file.Files
import java.nio.file.Paths import java.nio.file.Paths
import java.util.regex.Pattern import java.util.regex.Pattern
import static org.junit.Assert.assertTrue
@Log4j2 @Log4j2
class PdfDocumentBuilderTest { class PdfDocumentBuilderTest {
@ -48,7 +50,7 @@ class PdfDocumentBuilderTest {
PdfDocumentBuilder builder = new PdfDocumentBuilder(outputStream) PdfDocumentBuilder builder = new PdfDocumentBuilder(outputStream)
List layout = [ List layout = [
[key: 'Typ', value: 'Online', 'bold': true], [key: 'Typ', value: 'Online', 'bold': true],
[key: 'Medea-Nummer', value: 'test'], [key: 'Nummer', value: 'test'],
[key: 'Bestelldatum', value: 'test'], [key: 'Bestelldatum', value: 'test'],
[key: 'Eingangsdatum', value: 'test'], [key: 'Eingangsdatum', value: 'test'],
[key: 'Besteller', value: 'test', line: true], [key: 'Besteller', value: 'test', line: true],
@ -147,7 +149,7 @@ class PdfDocumentBuilderTest {
@Test @Test
void testPdfWithImage() { void testPdfWithImage() {
byte[] logo = getClass().getResourceAsStream('/img/logo-print.png').bytes byte[] logo = getClass().getResourceAsStream('/img/img.png').bytes
OutputStream outputStream = Files.newOutputStream(Paths.get("build/testimage.pdf")) OutputStream outputStream = Files.newOutputStream(Paths.get("build/testimage.pdf"))
outputStream.withCloseable { outputStream.withCloseable {
PdfDocumentBuilder builder = new PdfDocumentBuilder(outputStream) PdfDocumentBuilder builder = new PdfDocumentBuilder(outputStream)
@ -159,7 +161,7 @@ class PdfDocumentBuilderTest {
builder.create { builder.create {
document(font: [family: 'Helvetica'], margin: [top: 1.cm]) { document(font: [family: 'Helvetica'], margin: [top: 1.cm]) {
paragraph(margin: [left: 7.mm]) { paragraph(margin: [left: 7.mm]) {
image(data: logo, name: 'logo-print.png', width: 125.px, height: 45.px) image(data: logo, name: 'img.png', width: 125.px, height: 45.px)
} }
paragraph(margin: [left: 6.cm, right: 1.cm, top: 0.cm]) { paragraph(margin: [left: 6.cm, right: 1.cm, top: 0.cm]) {
font.size = 24.pt font.size = 24.pt
@ -229,11 +231,12 @@ class PdfDocumentBuilderTest {
Pattern detectHan = Pattern.compile('.*\\p{script=Han}.*') Pattern detectHan = Pattern.compile('.*\\p{script=Han}.*')
Pattern detectLatin = Pattern.compile('.*\\p{script=Latin}.*') Pattern detectLatin = Pattern.compile('.*\\p{script=Latin}.*')
String chinese = "北京 東京大学" String chinese = "北京 東京大学"
String caron = "Hey Jörg, this is Latin Small Letter C with Caron \u010d" String caron = "Hey, this is Latin Small Letter C with Caron \u010d"
log.info("chinese = ${detectHan.matcher(chinese).matches()}") log.info("chinese = ${detectHan.matcher(chinese).matches()}")
assertTrue(detectHan.matcher(chinese).matches())
log.info("caron = ${detectLatin.matcher(caron).matches()}") log.info("caron = ${detectLatin.matcher(caron).matches()}")
assertTrue(detectLatin.matcher(caron).matches())
String normalized = caron.replaceAll("\\P{IsLatin}","") String normalized = caron.replaceAll("\\P{IsLatin}","")
log.info("normalized=${normalized}") log.info("normalized=${normalized}")
} }
} }

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.5 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 673 B