clean tests for linux
This commit is contained in:
parent
49278772e8
commit
813a781d25
23 changed files with 92 additions and 130 deletions
|
@ -1,6 +1,6 @@
|
|||
group = org.xbib.graphics
|
||||
name = graphics
|
||||
version = 4.0.1
|
||||
version = 4.0.2
|
||||
|
||||
gradle.wrapper.version = 6.6.1
|
||||
pdfbox.version = 2.0.22
|
||||
|
|
|
@ -22,7 +22,7 @@ import java.nio.file.Files;
|
|||
import java.nio.file.Paths;
|
||||
import java.util.Locale;
|
||||
|
||||
public class SvgRendererTest {
|
||||
public class SVGRendererTest {
|
||||
|
||||
private Locale originalDefaultLocale;
|
||||
|
|
@ -26,7 +26,6 @@ clipsave
|
|||
gsave
|
||||
0.0 0.0 0.0 rgb
|
||||
1.0 setlinewidth 0 setlinejoin 0 setlinecap [] 0.0 setdash
|
||||
/DejaVuSansLat /DejaVuSans latinize /DejaVuSansLat 12.0 selectfont
|
||||
1.0 1.0 1.0 rgb
|
||||
newpath 0.0 0.0 128.0 60.0 rect Z fill
|
||||
0.0 0.0 0.0 rgb
|
||||
|
|
|
@ -32,15 +32,11 @@ q
|
|||
/Fnt0 12.0 Tf
|
||||
q
|
||||
0 J
|
||||
|
||||
/Fnt0 12.0 Tf
|
||||
0 0 m 128 0 l 128 60 l 0 60 l 0 0 l h f
|
||||
Q
|
||||
q
|
||||
0 0 0 rg 0 0 0 RG
|
||||
0 J
|
||||
|
||||
/Fnt0 12.0 Tf
|
||||
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
|
||||
9 5 m 13 5 l 13 45 l 9 45 l h f
|
||||
|
@ -93,7 +89,7 @@ Q
|
|||
endstream
|
||||
endobj
|
||||
5 0 obj
|
||||
1684
|
||||
1654
|
||||
endobj
|
||||
6 0 obj
|
||||
<<
|
||||
|
@ -121,13 +117,13 @@ xref
|
|||
0000000058 00000 n
|
||||
0000000115 00000 n
|
||||
0000000248 00000 n
|
||||
0000001984 00000 n
|
||||
0000002004 00000 n
|
||||
0000001954 00000 n
|
||||
0000001974 00000 n
|
||||
trailer
|
||||
<<
|
||||
/Size 7
|
||||
/Root 1 0 R
|
||||
>>
|
||||
startxref
|
||||
2267
|
||||
2237
|
||||
%%EOF
|
||||
|
|
|
@ -26,7 +26,6 @@ clipsave
|
|||
gsave
|
||||
0.0 0.0 0.0 rgb
|
||||
1.0 setlinewidth 0 setlinejoin 0 setlinecap [] 0.0 setdash
|
||||
/DejaVuSansLat /DejaVuSans latinize /DejaVuSansLat 12.0 selectfont
|
||||
0.0 1.0 0.0 rgb
|
||||
newpath 0.0 0.0 128.0 60.0 rect Z fill
|
||||
1.0 0.0 0.0 rgb
|
||||
|
|
|
@ -33,15 +33,11 @@ q
|
|||
q
|
||||
0 1 0 rg 0 1 0 RG
|
||||
0 J
|
||||
|
||||
/Fnt0 12.0 Tf
|
||||
0 0 m 128 0 l 128 60 l 0 60 l 0 0 l h f
|
||||
Q
|
||||
q
|
||||
1 0 0 rg 1 0 0 RG
|
||||
0 J
|
||||
|
||||
/Fnt0 12.0 Tf
|
||||
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
|
||||
9 5 m 13 5 l 13 45 l 9 45 l h f
|
||||
|
@ -94,7 +90,7 @@ Q
|
|||
endstream
|
||||
endobj
|
||||
5 0 obj
|
||||
1702
|
||||
1672
|
||||
endobj
|
||||
6 0 obj
|
||||
<<
|
||||
|
@ -122,13 +118,13 @@ xref
|
|||
0000000058 00000 n
|
||||
0000000115 00000 n
|
||||
0000000248 00000 n
|
||||
0000002002 00000 n
|
||||
0000002022 00000 n
|
||||
0000001972 00000 n
|
||||
0000001992 00000 n
|
||||
trailer
|
||||
<<
|
||||
/Size 7
|
||||
/Root 1 0 R
|
||||
>>
|
||||
startxref
|
||||
2285
|
||||
2255
|
||||
%%EOF
|
||||
|
|
|
@ -26,7 +26,6 @@ clipsave
|
|||
gsave
|
||||
0.0 0.0 0.0 rgb
|
||||
1.0 setlinewidth 0 setlinejoin 0 setlinecap [] 0.0 setdash
|
||||
/DejaVuSansLat /DejaVuSans latinize /DejaVuSansLat 12.0 selectfont
|
||||
1.0 1.0 1.0 rgb
|
||||
newpath 0.0 0.0 128.0 82.0 rect Z fill
|
||||
0.0 0.0 0.0 rgb
|
||||
|
|
|
@ -32,15 +32,11 @@ q
|
|||
/Fnt0 12.0 Tf
|
||||
q
|
||||
0 J
|
||||
|
||||
/Fnt0 12.0 Tf
|
||||
0 0 m 128 0 l 128 82 l 0 82 l 0 0 l h f
|
||||
Q
|
||||
q
|
||||
0 0 0 rg 0 0 0 RG
|
||||
0 J
|
||||
|
||||
/Fnt0 12.0 Tf
|
||||
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
|
||||
9 5 m 13 5 l 13 45 l 9 45 l h f
|
||||
|
@ -93,7 +89,7 @@ Q
|
|||
endstream
|
||||
endobj
|
||||
5 0 obj
|
||||
1688
|
||||
1658
|
||||
endobj
|
||||
6 0 obj
|
||||
<<
|
||||
|
@ -121,13 +117,13 @@ xref
|
|||
0000000058 00000 n
|
||||
0000000115 00000 n
|
||||
0000000248 00000 n
|
||||
0000001988 00000 n
|
||||
0000002008 00000 n
|
||||
0000001958 00000 n
|
||||
0000001978 00000 n
|
||||
trailer
|
||||
<<
|
||||
/Size 7
|
||||
/Root 1 0 R
|
||||
>>
|
||||
startxref
|
||||
2271
|
||||
2241
|
||||
%%EOF
|
||||
|
|
|
@ -26,7 +26,6 @@ clipsave
|
|||
gsave
|
||||
0.0 0.0 0.0 rgb
|
||||
1.0 setlinewidth 0 setlinejoin 0 setlinecap [] 0.0 setdash
|
||||
/DejaVuSansLat /DejaVuSans latinize /DejaVuSansLat 12.0 selectfont
|
||||
1.0 1.0 1.0 rgb
|
||||
newpath 0.0 0.0 256.0 120.0 rect Z fill
|
||||
0.0 0.0 0.0 rgb
|
||||
|
|
|
@ -32,15 +32,11 @@ q
|
|||
/Fnt0 12.0 Tf
|
||||
q
|
||||
0 J
|
||||
|
||||
/Fnt0 12.0 Tf
|
||||
0 0 m 256 0 l 256 120 l 0 120 l 0 0 l h f
|
||||
Q
|
||||
q
|
||||
0 0 0 rg 0 0 0 RG
|
||||
0 J
|
||||
|
||||
/Fnt0 12.0 Tf
|
||||
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
|
||||
18 10 m 26 10 l 26 90 l 18 90 l h f
|
||||
|
@ -93,7 +89,7 @@ Q
|
|||
endstream
|
||||
endobj
|
||||
5 0 obj
|
||||
1845
|
||||
1815
|
||||
endobj
|
||||
6 0 obj
|
||||
<<
|
||||
|
@ -121,13 +117,13 @@ xref
|
|||
0000000058 00000 n
|
||||
0000000115 00000 n
|
||||
0000000248 00000 n
|
||||
0000002145 00000 n
|
||||
0000002165 00000 n
|
||||
0000002115 00000 n
|
||||
0000002135 00000 n
|
||||
trailer
|
||||
<<
|
||||
/Size 7
|
||||
/Root 1 0 R
|
||||
>>
|
||||
startxref
|
||||
2428
|
||||
2398
|
||||
%%EOF
|
||||
|
|
|
@ -26,7 +26,6 @@ clipsave
|
|||
gsave
|
||||
0.0 0.0 0.0 rgb
|
||||
1.0 setlinewidth 0 setlinejoin 0 setlinecap [] 0.0 setdash
|
||||
/DejaVuSansLat /DejaVuSans latinize /DejaVuSansLat 12.0 selectfont
|
||||
1.0 1.0 1.0 rgb
|
||||
newpath 0.0 0.0 158.0 90.0 rect Z fill
|
||||
0.0 0.0 0.0 rgb
|
||||
|
|
|
@ -32,15 +32,11 @@ q
|
|||
/Fnt0 12.0 Tf
|
||||
q
|
||||
0 J
|
||||
|
||||
/Fnt0 12.0 Tf
|
||||
0 0 m 158 0 l 158 90 l 0 90 l 0 0 l h f
|
||||
Q
|
||||
q
|
||||
0 0 0 rg 0 0 0 RG
|
||||
0 J
|
||||
|
||||
/Fnt0 12.0 Tf
|
||||
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
|
||||
24 20 m 28 20 l 28 60 l 24 60 l h f
|
||||
|
@ -93,7 +89,7 @@ Q
|
|||
endstream
|
||||
endobj
|
||||
5 0 obj
|
||||
1795
|
||||
1765
|
||||
endobj
|
||||
6 0 obj
|
||||
<<
|
||||
|
@ -121,13 +117,13 @@ xref
|
|||
0000000058 00000 n
|
||||
0000000115 00000 n
|
||||
0000000247 00000 n
|
||||
0000002094 00000 n
|
||||
0000002114 00000 n
|
||||
0000002064 00000 n
|
||||
0000002084 00000 n
|
||||
trailer
|
||||
<<
|
||||
/Size 7
|
||||
/Root 1 0 R
|
||||
>>
|
||||
startxref
|
||||
2377
|
||||
2347
|
||||
%%EOF
|
||||
|
|
|
@ -26,7 +26,6 @@ clipsave
|
|||
gsave
|
||||
0.0 0.0 0.0 rgb
|
||||
1.0 setlinewidth 0 setlinejoin 0 setlinecap [] 0.0 setdash
|
||||
/DejaVuSansLat /DejaVuSans latinize /DejaVuSansLat 12.0 selectfont
|
||||
1.0 1.0 1.0 rgb
|
||||
newpath 0.0 0.0 420.0 410.0 rect Z fill
|
||||
0.0 0.0 0.0 rgb
|
||||
|
|
|
@ -32,15 +32,11 @@ q
|
|||
/Fnt0 12.0 Tf
|
||||
q
|
||||
0 J
|
||||
|
||||
/Fnt0 12.0 Tf
|
||||
0 0 m 420 0 l 420 410 l 0 410 l 0 0 l h f
|
||||
Q
|
||||
q
|
||||
0 0 0 rg 0 0 0 RG
|
||||
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
|
||||
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
|
||||
|
@ -414,41 +410,31 @@ q
|
|||
Q
|
||||
q
|
||||
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
|
||||
Q
|
||||
q
|
||||
0 0 0 rg 0 0 0 RG
|
||||
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
|
||||
Q
|
||||
q
|
||||
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
|
||||
Q
|
||||
q
|
||||
0 0 0 rg 0 0 0 RG
|
||||
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
|
||||
Q
|
||||
q
|
||||
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
|
||||
Q
|
||||
Q
|
||||
endstream
|
||||
endobj
|
||||
5 0 obj
|
||||
64455
|
||||
64350
|
||||
endobj
|
||||
6 0 obj
|
||||
<<
|
||||
|
@ -470,13 +456,13 @@ xref
|
|||
0000000058 00000 n
|
||||
0000000115 00000 n
|
||||
0000000248 00000 n
|
||||
0000064755 00000 n
|
||||
0000064776 00000 n
|
||||
0000064650 00000 n
|
||||
0000064671 00000 n
|
||||
trailer
|
||||
<<
|
||||
/Size 7
|
||||
/Root 1 0 R
|
||||
>>
|
||||
startxref
|
||||
64947
|
||||
64842
|
||||
%%EOF
|
||||
|
|
|
@ -91,7 +91,7 @@ public class PDFConverter {
|
|||
this.compatibilityLevel = compatibilityLevel;
|
||||
this.pdfx = pdfx;
|
||||
this.paperSize = paperSize;
|
||||
this.tmpPath = Paths.get("/var/tmp/" + this);
|
||||
this.tmpPath = Paths.get(System.getProperty("java.io.tmpdir", "/var/tmp")).resolve(toString());
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -25,6 +25,7 @@ import java.io.OutputStream;
|
|||
import java.nio.file.FileVisitResult;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.PathMatcher;
|
||||
import java.nio.file.Paths;
|
||||
import java.nio.file.SimpleFileVisitor;
|
||||
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 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 Path tmpPath;
|
||||
|
||||
public PDFRasterizer(String subject) {
|
||||
this("org.xbib.graphics.ghostscript/4.0.1", "Jörg Prante", subject);
|
||||
public PDFRasterizer() {
|
||||
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;
|
||||
}
|
||||
|
||||
public void setAuthor(String author) {
|
||||
this.author = author;
|
||||
}
|
||||
|
||||
public void setSubject(String subject) {
|
||||
this.subject = subject;
|
||||
this.imageReaders = createImageReaders();
|
||||
this.tmpPath = Paths.get("/var/tmp/" + this);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -199,21 +205,33 @@ public class PDFRasterizer implements Closeable {
|
|||
}
|
||||
}
|
||||
|
||||
public synchronized int mergeImagesToPDF(Path sourceDir, Path targetFile) throws IOException {
|
||||
logger.info("mergeImagesToPDF: source=" + sourceDir + " target=" + targetFile);
|
||||
public int mergeImagesToPDF(Path sourceDir, Path targetFile) throws IOException {
|
||||
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;
|
||||
PathMatcher pathMatcher = sourceDir.getFileSystem().getPathMatcher("glob:" + globPattern);
|
||||
List<PDDocument> coverPageDocs = new ArrayList<>();
|
||||
try (Stream<Path> files = Files.list(sourceDir);
|
||||
PDDocument pdDocument = new PDDocument(MemoryUsageSetting.setupTempFileOnly());
|
||||
OutputStream outputStream = new BufferedOutputStream(Files.newOutputStream(targetFile))) {
|
||||
List<Path> entries = files.sorted()
|
||||
.filter(PDFRasterizer::checkForRealFile)
|
||||
.filter(pathMatcher::matches)
|
||||
.collect(Collectors.toList());
|
||||
pdDocument.getDocumentInformation().setTitle(targetFile.getFileName().toString());
|
||||
pdDocument.getDocumentInformation().setCreationDate(Calendar.getInstance());
|
||||
if (creator != null) {
|
||||
pdDocument.getDocumentInformation().setCreator(creator);
|
||||
}
|
||||
if (subject != null) {
|
||||
pdDocument.getDocumentInformation().setSubject(subject);
|
||||
}
|
||||
if (author != null) {
|
||||
pdDocument.getDocumentInformation().setAuthor(author);
|
||||
}
|
||||
for (Path path : entries) {
|
||||
if (path.getFileName().toString().toLowerCase(Locale.ROOT).endsWith(".pdf")) {
|
||||
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);
|
||||
} else {
|
||||
BufferedImage bufferedImage = readImage(path);
|
||||
if (bufferedImage != null) {
|
||||
PDPage page = new PDPage(new PDRectangle(bufferedImage.getWidth(), bufferedImage.getHeight()));
|
||||
pdDocument.addPage(page);
|
||||
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");
|
||||
}
|
||||
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);
|
||||
ImageReadParam param = imageReader.getDefaultReadParam();
|
||||
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() +
|
||||
" color model = " + bufferedImage.getColorModel());
|
||||
imageInputStream.close();
|
||||
|
|
|
@ -22,12 +22,9 @@ public class PDFRasterizerTest {
|
|||
|
||||
@Test
|
||||
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 targetFile = Paths.get("build/3656573.pdf");
|
||||
PDFRasterizer pdfRasterizer = new PDFRasterizer(creator, author, subject);
|
||||
PDFRasterizer pdfRasterizer = new PDFRasterizer();
|
||||
int pagecount = pdfRasterizer.mergeImagesToPDF(sourceDir, targetFile);
|
||||
logger.info("pagecount = " + pagecount);
|
||||
pdfRasterizer.close();
|
||||
|
@ -35,12 +32,9 @@ public class PDFRasterizerTest {
|
|||
|
||||
@Test
|
||||
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 targetFile = Paths.get("build/color.pdf");
|
||||
PDFRasterizer pdfRasterizer = new PDFRasterizer(creator, author, subject);
|
||||
PDFRasterizer pdfRasterizer = new PDFRasterizer();
|
||||
int pagecount = pdfRasterizer.mergeImagesToPDF(sourceDir, targetFile);
|
||||
logger.info("pagecount = " + pagecount);
|
||||
pdfRasterizer.close();
|
||||
|
@ -52,7 +46,7 @@ public class PDFRasterizerTest {
|
|||
Path target = Paths.get("build/20200024360-new.pdf");
|
||||
Path tmp = Files.createTempDirectory("graphics-test");
|
||||
try {
|
||||
PDFRasterizer pdfRasterizer = new PDFRasterizer("xbib", "Jörg Prante", "Test");
|
||||
PDFRasterizer pdfRasterizer = new PDFRasterizer();
|
||||
pdfRasterizer.pdfToImage(source, tmp, null, null);
|
||||
Path tmpTarget = tmp.resolve(target.getFileName());
|
||||
int pagecount = pdfRasterizer.mergeImagesToPDF(tmp, tmpTarget);
|
||||
|
@ -74,9 +68,7 @@ public class PDFRasterizerTest {
|
|||
try {
|
||||
delete(target);
|
||||
Files.createDirectories(target);
|
||||
PDFRasterizer rasterizer = new PDFRasterizer(
|
||||
"org.xbib.graphics.ghostscript", "Jörg Prante",
|
||||
"converted from " + p);
|
||||
PDFRasterizer rasterizer = new PDFRasterizer();
|
||||
rasterizer.pdfToImage(p, target, "pdf-", "1-");
|
||||
rasterizer.close();
|
||||
} catch (IOException e) {
|
||||
|
@ -90,7 +82,6 @@ public class PDFRasterizerTest {
|
|||
|
||||
@Test
|
||||
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");
|
||||
try (Stream<Path> stream = Files.list(path)) {
|
||||
stream.forEach(p -> {
|
||||
|
@ -100,9 +91,7 @@ public class PDFRasterizerTest {
|
|||
try {
|
||||
delete(target);
|
||||
Files.createDirectories(target.getParent());
|
||||
PDFRasterizer rasterizer = new PDFRasterizer(
|
||||
"org.xbib.graphics.ghostscript", "Jörg Prante",
|
||||
"converted from " + p);
|
||||
PDFRasterizer rasterizer = new PDFRasterizer();
|
||||
rasterizer.convert(p, target);
|
||||
rasterizer.close();
|
||||
} catch (IOException e) {
|
||||
|
|
|
@ -32,14 +32,11 @@ public class TiffTest {
|
|||
|
||||
@Test
|
||||
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 targetFile = Paths.get("build/tmp.pdf");
|
||||
PDFRasterizer pdfRasterizer = new PDFRasterizer(creator, author, subject);
|
||||
int pagecount = pdfRasterizer.mergeImagesToPDF(sourceDir, targetFile);
|
||||
PDFRasterizer pdfRasterizer = new PDFRasterizer();
|
||||
int pagecount = pdfRasterizer.mergeImagesToPDF(sourceDir, targetFile, "**/*.tif");
|
||||
logger.info("pagecount = " + pagecount);
|
||||
assertEquals(3, pagecount);
|
||||
assertEquals(2, pagecount);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -370,7 +370,7 @@ abstract class BaseBuilderSpec extends Specification {
|
|||
when:
|
||||
List layout = [
|
||||
[ key: 'Typ', value: 'Online', 'bold':true],
|
||||
[ key: 'Medea-Nummer', value: 'test'],
|
||||
[ key: 'Nummer', value: 'test'],
|
||||
[ key: 'Bestelldatum', value: 'test'],
|
||||
[ key: 'Eingangsdatum', value: 'test'],
|
||||
[ 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]) {
|
||||
font.size = 24.pt
|
||||
font.bold = true
|
||||
text 'Aufsatzbestellung Lieferschein'
|
||||
text 'Lieferschein'
|
||||
}
|
||||
paragraph {
|
||||
table(margin:[left: 1.cm, top: 2.cm], width: 19.cm, padding: 0.pt, border:[size:0.pt]) {
|
||||
|
|
|
@ -28,13 +28,13 @@ class FontSpec extends Specification {
|
|||
}
|
||||
|
||||
def "printable characters"() {
|
||||
String s = "\u0098 Hello Jörg"
|
||||
String s = "\u0098 Hello World"
|
||||
|
||||
when:
|
||||
s = s.replaceAll("\\p{C}", "")
|
||||
|
||||
then:
|
||||
s == " Hello Jörg"
|
||||
s == " Hello World"
|
||||
}
|
||||
|
||||
def "glyph exists"() {
|
||||
|
|
|
@ -9,6 +9,8 @@ import java.nio.file.Files
|
|||
import java.nio.file.Paths
|
||||
import java.util.regex.Pattern
|
||||
|
||||
import static org.junit.Assert.assertTrue
|
||||
|
||||
@Log4j2
|
||||
class PdfDocumentBuilderTest {
|
||||
|
||||
|
@ -48,7 +50,7 @@ class PdfDocumentBuilderTest {
|
|||
PdfDocumentBuilder builder = new PdfDocumentBuilder(outputStream)
|
||||
List layout = [
|
||||
[key: 'Typ', value: 'Online', 'bold': true],
|
||||
[key: 'Medea-Nummer', value: 'test'],
|
||||
[key: 'Nummer', value: 'test'],
|
||||
[key: 'Bestelldatum', value: 'test'],
|
||||
[key: 'Eingangsdatum', value: 'test'],
|
||||
[key: 'Besteller', value: 'test', line: true],
|
||||
|
@ -147,7 +149,7 @@ class PdfDocumentBuilderTest {
|
|||
|
||||
@Test
|
||||
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.withCloseable {
|
||||
PdfDocumentBuilder builder = new PdfDocumentBuilder(outputStream)
|
||||
|
@ -159,7 +161,7 @@ class PdfDocumentBuilderTest {
|
|||
builder.create {
|
||||
document(font: [family: 'Helvetica'], margin: [top: 1.cm]) {
|
||||
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]) {
|
||||
font.size = 24.pt
|
||||
|
@ -229,11 +231,12 @@ class PdfDocumentBuilderTest {
|
|||
Pattern detectHan = Pattern.compile('.*\\p{script=Han}.*')
|
||||
Pattern detectLatin = Pattern.compile('.*\\p{script=Latin}.*')
|
||||
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()}")
|
||||
assertTrue(detectHan.matcher(chinese).matches())
|
||||
log.info("caron = ${detectLatin.matcher(caron).matches()}")
|
||||
assertTrue(detectLatin.matcher(caron).matches())
|
||||
String normalized = caron.replaceAll("\\P{IsLatin}","")
|
||||
log.info("normalized=${normalized}")
|
||||
|
||||
}
|
||||
}
|
||||
|
|
BIN
graphics-pdfbox-groovy/src/test/resources/img/img.png
Normal file
BIN
graphics-pdfbox-groovy/src/test/resources/img/img.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 7.5 KiB |
Binary file not shown.
Before Width: | Height: | Size: 673 B |
Loading…
Reference in a new issue