use of com.itextpdf.kernel.pdf.PdfDocument 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.PdfDocument 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);
}
use of com.itextpdf.kernel.pdf.PdfDocument in project i7j-pdfsweep by itext.
the class FilteredImagesCacheTest method filteredImagesCacheFlushingTest02.
@Test
public void filteredImagesCacheFlushingTest02() throws IOException, InterruptedException {
String input = inputPath + "severalImageXObjectOccurrences.pdf";
String output = outputPath + "filteredImagesCacheFlushingTest02.pdf";
String cmp = inputPath + "cmp_filteredImagesCacheFlushingTest02.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(1).getResources().getImage(new PdfName("Im1"));
img.makeIndirect(pdfDocument).flush();
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.PdfDocument in project i7j-pdfsweep by itext.
the class PdfAutoSweepToolsTest method highlightTest.
@Test
public void highlightTest() throws IOException, InterruptedException {
String input = INPUT_PATH + "Lipsum.pdf";
String output = OUTPUT_PATH + "highlightTest.pdf";
String cmp = INPUT_PATH + "cmp_highlightTest.pdf";
CompositeCleanupStrategy strategy = new CompositeCleanupStrategy();
strategy.add(new RegexBasedCleanupStrategy("(D|d)olor").setRedactionColor(ColorConstants.GREEN));
PdfDocument pdf = new PdfDocument(new PdfReader(input), new PdfWriter(output).setCompressionLevel(CompressionConstants.NO_COMPRESSION));
// sweep
PdfAutoSweepTools autoSweep = new PdfAutoSweepTools(strategy);
autoSweep.highlight(pdf);
pdf.close();
// compare
compareByContent(cmp, output, OUTPUT_PATH, "diff_highlightTest_");
}
use of com.itextpdf.kernel.pdf.PdfDocument in project i7j-pdfsweep by itext.
the class PdfAutoSweepToolsTest method getPdfCleanUpLocationsTest.
@Test
public void getPdfCleanUpLocationsTest() throws IOException {
String input = INPUT_PATH + "Lipsum.pdf";
CompositeCleanupStrategy strategy = new CompositeCleanupStrategy();
strategy.add(new RegexBasedCleanupStrategy("(D|d)olor"));
PdfDocument pdf = new PdfDocument(new PdfReader(input), new PdfWriter(new ByteArrayOutputStream()));
// sweep
List cleanUpLocations = (List) new PdfAutoSweepTools(strategy).getPdfCleanUpLocations(pdf.getPage(1));
pdf.close();
// compare
Assert.assertEquals(2, cleanUpLocations.size());
}
Aggregations