Search in sources :

Example 41 with Rectangle

use of com.itextpdf.kernel.geom.Rectangle in project i7j-pdfsweep by itext.

the class CleanUpTextTest method cleanZeroWidthTextInvalidFont.

@Test
@LogMessages(messages = { @LogMessage(messageTemplate = IoLogMessageConstant.FONT_DICTIONARY_WITH_NO_FONT_DESCRIPTOR), @LogMessage(messageTemplate = IoLogMessageConstant.FONT_DICTIONARY_WITH_NO_WIDTHS) })
public void cleanZeroWidthTextInvalidFont() throws IOException, InterruptedException {
    String input = inputPath + "cleanZeroWidthTextInvalidFont.pdf";
    String output = outputPath + "cleanZeroWidthTextInvalidFont.pdf";
    String cmp = inputPath + "cmp_cleanZeroWidthTextInvalidFont.pdf";
    cleanUp(input, output, Arrays.asList(new PdfCleanUpLocation(1, new Rectangle(50, 50, 500, 500))));
    compareByContent(cmp, output, outputPath);
}
Also used : PdfCleanUpLocation(com.itextpdf.pdfcleanup.PdfCleanUpLocation) Rectangle(com.itextpdf.kernel.geom.Rectangle) IntegrationTest(com.itextpdf.test.annotations.type.IntegrationTest) ExtendedITextTest(com.itextpdf.test.ExtendedITextTest) Test(org.junit.Test) LogMessages(com.itextpdf.test.annotations.LogMessages)

Example 42 with Rectangle

use of com.itextpdf.kernel.geom.Rectangle in project i7j-pdfsweep by itext.

the class MaskedImagesTest method imageTransparencyTextOnTransparentField.

@Test
public void imageTransparencyTextOnTransparentField() throws IOException, InterruptedException {
    String fileName = "textOnTransparentField";
    String input = inputPath + fileName + ".pdf";
    String output = outputPath + fileName + "_cleaned.pdf";
    String cmp = inputPath + "cmp_" + fileName + ".pdf";
    List<PdfCleanUpLocation> cleanUpLocations = Collections.singletonList(new PdfCleanUpLocation(1, new Rectangle(280, 360, 200, 75)));
    PdfDocument pdfDocument = new PdfDocument(new PdfReader(input), new PdfWriter(output));
    PdfCleaner.cleanUp(pdfDocument, cleanUpLocations);
    new PdfCanvas(pdfDocument.getFirstPage().newContentStreamBefore(), pdfDocument.getFirstPage().getResources(), pdfDocument).setColor(ColorConstants.LIGHT_GRAY, true).rectangle(0, 0, 1000, 1000).fill().setColor(ColorConstants.BLACK, true);
    pdfDocument.close();
    Assert.assertNull(new CompareTool().compareByContent(output, cmp, outputPath));
}
Also used : PdfWriter(com.itextpdf.kernel.pdf.PdfWriter) PdfCleanUpLocation(com.itextpdf.pdfcleanup.PdfCleanUpLocation) Rectangle(com.itextpdf.kernel.geom.Rectangle) CompareTool(com.itextpdf.kernel.utils.CompareTool) CleanUpImagesCompareTool(com.itextpdf.pdfcleanup.util.CleanUpImagesCompareTool) PdfCanvas(com.itextpdf.kernel.pdf.canvas.PdfCanvas) PdfReader(com.itextpdf.kernel.pdf.PdfReader) PdfDocument(com.itextpdf.kernel.pdf.PdfDocument) IntegrationTest(com.itextpdf.test.annotations.type.IntegrationTest) ExtendedITextTest(com.itextpdf.test.ExtendedITextTest) Test(org.junit.Test)

Example 43 with Rectangle

use of com.itextpdf.kernel.geom.Rectangle in project i7j-pdfsweep by itext.

the class MaskedImagesTest method runTest.

private static void runTest(String fileName, String fuzzValue) throws IOException, InterruptedException {
    String input = inputPath + fileName + ".pdf";
    String output = outputPath + fileName + "_cleaned.pdf";
    String cmp = inputPath + "cmp_" + fileName + ".pdf";
    List<PdfCleanUpLocation> cleanUpLocations = Collections.singletonList(new PdfCleanUpLocation(1, new Rectangle(308, 520, 200, 75)));
    PdfDocument pdfDocument = new PdfDocument(new PdfReader(input), new PdfWriter(output));
    PdfCleaner.cleanUp(pdfDocument, cleanUpLocations);
    pdfDocument.close();
    CleanUpImagesCompareTool cmpTool = new CleanUpImagesCompareTool();
    String errorMessage = cmpTool.extractAndCompareImages(output, cmp, outputPath, fuzzValue);
    String compareByContentResult = cmpTool.compareByContent(output, cmp, outputPath);
    if (compareByContentResult != null) {
        errorMessage += compareByContentResult;
    }
    if (!errorMessage.equals("")) {
        Assert.fail(errorMessage);
    }
}
Also used : PdfWriter(com.itextpdf.kernel.pdf.PdfWriter) PdfCleanUpLocation(com.itextpdf.pdfcleanup.PdfCleanUpLocation) Rectangle(com.itextpdf.kernel.geom.Rectangle) CleanUpImagesCompareTool(com.itextpdf.pdfcleanup.util.CleanUpImagesCompareTool) PdfReader(com.itextpdf.kernel.pdf.PdfReader) PdfDocument(com.itextpdf.kernel.pdf.PdfDocument)

Example 44 with Rectangle

use of com.itextpdf.kernel.geom.Rectangle in project i7j-pdfsweep by itext.

the class PdfCleanUpToolTest method cleanUpTest13.

@Test
public void cleanUpTest13() throws IOException, InterruptedException {
    String input = INPUT_PATH + "maskImage.pdf";
    String output = OUTPUT_PATH + "maskImage.pdf";
    String cmp = INPUT_PATH + "cmp_maskImage.pdf";
    List<PdfCleanUpLocation> cleanUpLocations = Arrays.asList(new PdfCleanUpLocation(1, new Rectangle(97f, 405f, 480f - 97f, 445f - 405f), ColorConstants.GRAY));
    cleanUp(input, output, cleanUpLocations);
    compareByContent(cmp, output, OUTPUT_PATH, "diff_13");
}
Also used : Rectangle(com.itextpdf.kernel.geom.Rectangle) PdfString(com.itextpdf.kernel.pdf.PdfString) IntegrationTest(com.itextpdf.test.annotations.type.IntegrationTest) ExtendedITextTest(com.itextpdf.test.ExtendedITextTest) Test(org.junit.Test)

Example 45 with Rectangle

use of com.itextpdf.kernel.geom.Rectangle in project i7j-pdfsweep by itext.

the class PdfCleanUpToolTest method autoCleanWithLocationAndStreamParamsTest.

@Test
public void autoCleanWithLocationAndStreamParamsTest() throws Exception {
    String input = INPUT_PATH + "fontCleanup.pdf";
    String output = OUTPUT_PATH + "autoCleanWithLocationAndStreamParamsTest.pdf";
    String cmp = INPUT_PATH + "cmp_autoCleanWithLocationAndStreamParamsTest.pdf";
    CompositeCleanupStrategy strategy = new CompositeCleanupStrategy();
    strategy.add(new RegexBasedCleanupStrategy("leonard"));
    List<PdfCleanUpLocation> additionalLocation = Arrays.asList(new PdfCleanUpLocation(1, new Rectangle(0, 0, 200, 100)));
    PdfCleaner.autoSweepCleanUp(new FileInputStream(input), new FileOutputStream(output), strategy, additionalLocation);
    compareByContent(cmp, output, OUTPUT_PATH, "autoCleanWithLocationAndStreamParamsTest");
}
Also used : RegexBasedCleanupStrategy(com.itextpdf.pdfcleanup.autosweep.RegexBasedCleanupStrategy) CompositeCleanupStrategy(com.itextpdf.pdfcleanup.autosweep.CompositeCleanupStrategy) FileOutputStream(java.io.FileOutputStream) Rectangle(com.itextpdf.kernel.geom.Rectangle) PdfString(com.itextpdf.kernel.pdf.PdfString) FileInputStream(java.io.FileInputStream) IntegrationTest(com.itextpdf.test.annotations.type.IntegrationTest) ExtendedITextTest(com.itextpdf.test.ExtendedITextTest) Test(org.junit.Test)

Aggregations

Rectangle (com.itextpdf.kernel.geom.Rectangle)118 ExtendedITextTest (com.itextpdf.test.ExtendedITextTest)76 IntegrationTest (com.itextpdf.test.annotations.type.IntegrationTest)76 Test (org.junit.Test)76 PdfString (com.itextpdf.kernel.pdf.PdfString)42 PdfDocument (com.itextpdf.kernel.pdf.PdfDocument)41 PdfWriter (com.itextpdf.kernel.pdf.PdfWriter)37 ArrayList (java.util.ArrayList)29 PdfReader (com.itextpdf.kernel.pdf.PdfReader)22 PdfCanvas (com.itextpdf.kernel.pdf.canvas.PdfCanvas)16 Paragraph (com.itextpdf.layout.element.Paragraph)15 PdfFont (com.itextpdf.kernel.font.PdfFont)12 Document (com.itextpdf.layout.Document)12 Canvas (com.itextpdf.layout.Canvas)11 PdfPage (com.itextpdf.kernel.pdf.PdfPage)10 ColumnDocumentRenderer (com.itextpdf.layout.ColumnDocumentRenderer)9 LogMessages (com.itextpdf.test.annotations.LogMessages)9 AreaBreak (com.itextpdf.layout.element.AreaBreak)8 PdfCleanUpLocation (com.itextpdf.pdfcleanup.PdfCleanUpLocation)8 HyphenationConfig (com.itextpdf.layout.hyphenation.HyphenationConfig)7