use of com.itextpdf.kernel.pdf.PdfReader in project i7j-pdfsweep by itext.
the class FilteredImagesCacheTest method filteredImagesCacheFlushingTest01.
@Test
public void filteredImagesCacheFlushingTest01() throws IOException, InterruptedException {
String input = inputPath + "severalImageXObjectOccurrences.pdf";
String output = outputPath + "filteredImagesCacheFlushingTest01.pdf";
String cmp = inputPath + "cmp_filteredImagesCacheFlushingTest01.pdf";
PdfDocument pdfDocument = new PdfDocument(new PdfReader(input), new PdfWriter(output));
PdfCleanUpTool cleanUpTool = new PdfCleanUpTool(pdfDocument);
cleanUpTool.addCleanupLocation(new PdfCleanUpLocation(1, new Rectangle(150, 300, 300, 150)));
cleanUpTool.cleanUp();
PdfImageXObject img = pdfDocument.getPage(2).getResources().getImage(new PdfName("Im1"));
img.getPdfObject().release();
cleanUpTool.addCleanupLocation(new PdfCleanUpLocation(2, new Rectangle(150, 300, 300, 150)));
cleanUpTool.cleanUp();
cleanUpTool.addCleanupLocation(new PdfCleanUpLocation(3, new Rectangle(150, 300, 300, 150)));
cleanUpTool.cleanUp();
pdfDocument.close();
compareByContent(cmp, output, outputPath, "1.2");
assertNumberXObjects(output, 1);
}
use of com.itextpdf.kernel.pdf.PdfReader in project i7j-pdfsweep by itext.
the class FilteredImagesCacheTest method filteredImagesCacheTest04.
@Test
public void filteredImagesCacheTest04() throws IOException, InterruptedException {
// same image with different scaling and the same resultant image area
String input = inputPath + "multipleScaledImageXObjectOccurrences.pdf";
String output = outputPath + "filteredImagesCacheTest04.pdf";
String cmp = inputPath + "cmp_filteredImagesCacheTest04.pdf";
PdfDocument pdfDocument = new PdfDocument(new PdfReader(input), new PdfWriter(output));
List<PdfCleanUpLocation> cleanUpLocations = new ArrayList<>();
float x = 559;
float y = 600.2f;
float width = 100;
float height = 100;
Rectangle region1 = new Rectangle(x - width, y - height, width, height);
float scaleFactor = 1.2f;
width *= scaleFactor;
height *= scaleFactor;
Rectangle region2 = new Rectangle(x - width, y - height, width, height);
for (int i = 0; i < pdfDocument.getNumberOfPages(); i += 2) {
cleanUpLocations.add(new PdfCleanUpLocation(i + 1, region1));
cleanUpLocations.add(new PdfCleanUpLocation(i + 2, region2));
}
cleanUp(pdfDocument, cleanUpLocations);
compareByContent(cmp, output, outputPath, "1.2");
assertNumberXObjects(output, 1);
}
use of com.itextpdf.kernel.pdf.PdfReader in project i7j-pdfsweep by itext.
the class FilteredImagesCacheTest method filteredImagesCacheTest03.
@Test
public void filteredImagesCacheTest03() throws IOException, InterruptedException {
// same areas, different src images
String input = inputPath + "multipleDifferentImageXObjectOccurrences.pdf";
String output = outputPath + "filteredImagesCacheTest03.pdf";
String cmp = inputPath + "cmp_filteredImagesCacheTest03.pdf";
PdfDocument pdfDocument = new PdfDocument(new PdfReader(input), new PdfWriter(output));
List<PdfCleanUpLocation> cleanUpLocations = new ArrayList<>();
for (int i = 0; i < pdfDocument.getNumberOfPages(); ++i) {
cleanUpLocations.add(new PdfCleanUpLocation(i + 1, new Rectangle(150, 300, 300, 150)));
}
cleanUp(pdfDocument, cleanUpLocations);
compareByContent(cmp, output, outputPath, "1.2");
assertNumberXObjects(output, 2);
}
use of com.itextpdf.kernel.pdf.PdfReader in project i7j-pdfsweep by itext.
the class FilteredImagesCacheTest method filteredImagesCacheTest01.
@Test
public void filteredImagesCacheTest01() throws IOException, InterruptedException {
// basic test with reusing of xobjects
String input = inputPath + "multipleImageXObjectOccurrences.pdf";
String output = outputPath + "filteredImagesCacheTest01.pdf";
String cmp = inputPath + "cmp_filteredImagesCacheTest01.pdf";
PdfDocument pdfDocument = new PdfDocument(new PdfReader(input), new PdfWriter(output));
List<PdfCleanUpLocation> cleanUpLocations = new ArrayList<>();
for (int i = 0; i < pdfDocument.getNumberOfPages(); ++i) {
cleanUpLocations.add(new PdfCleanUpLocation(i + 1, new Rectangle(150, 300, 300, 150)));
}
cleanUp(pdfDocument, cleanUpLocations);
compareByContent(cmp, output, outputPath, "1.2");
assertNumberXObjects(output, 1);
}
use of com.itextpdf.kernel.pdf.PdfReader in project i7j-pdfsweep by itext.
the class FilteredImagesCacheTest method assertNumberXObjects.
private void assertNumberXObjects(String output, int n) throws IOException {
PdfDocument doc = new PdfDocument(new PdfReader(output));
int xObjCount = 0;
for (int i = 0; i < doc.getNumberOfPdfObjects(); ++i) {
PdfObject pdfObject = doc.getPdfObject(i);
if (pdfObject != null && pdfObject.isStream()) {
PdfDictionary dict = (PdfDictionary) pdfObject;
if (PdfName.Image.equals(dict.getAsName(PdfName.Subtype)) && dict.containsKey(PdfName.Width) && dict.containsKey(PdfName.Height)) {
++xObjCount;
}
}
}
Assert.assertEquals(n, xObjCount);
}
Aggregations