use of com.itextpdf.kernel.pdf.PdfReader in project i7j-pdfsweep by itext.
the class PdfCleanUpToolTest method autoCleanPageWithAdditionalLocationTest.
@Test
public void autoCleanPageWithAdditionalLocationTest() throws Exception {
String input = INPUT_PATH + "fontCleanup.pdf";
String output = OUTPUT_PATH + "autoCleanPageWithAdditionalLocationTest.pdf";
String cmp = INPUT_PATH + "cmp_autoCleanPageWithAdditionalLocationTest.pdf";
CompositeCleanupStrategy strategy = new CompositeCleanupStrategy();
strategy.add(new RegexBasedCleanupStrategy("leonard"));
List<PdfCleanUpLocation> additionalLocation = Arrays.asList(new PdfCleanUpLocation(1, new Rectangle(0, 0, 200, 100), ColorConstants.RED));
try (PdfReader reader = new PdfReader(input);
PdfWriter writer = new PdfWriter(output);
PdfDocument document = new PdfDocument(reader, writer)) {
PdfCleaner.autoSweepCleanUp(document.getPage(1), strategy, additionalLocation);
}
compareByContent(cmp, output, OUTPUT_PATH, "autoCleanPageWithAdditionalLocationTest");
}
use of com.itextpdf.kernel.pdf.PdfReader in project i7j-pdfsweep by itext.
the class PdfCleanUpToolTest method documentInNonStampingModeTest.
@Test
public void documentInNonStampingModeTest() throws IOException {
PdfDocument pdfDocument = new PdfDocument(new PdfReader(INPUT_PATH + "fontCleanup.pdf"));
List<PdfCleanUpLocation> cleanUpLocations = Arrays.asList(new PdfCleanUpLocation(1, new Rectangle(0, 0, 500, 500)));
Exception e = Assert.assertThrows(PdfException.class, () -> PdfCleaner.cleanUp(pdfDocument, cleanUpLocations));
Assert.assertEquals(CleanupExceptionMessageConstant.PDF_DOCUMENT_MUST_BE_OPENED_IN_STAMPING_MODE, e.getMessage());
}
use of com.itextpdf.kernel.pdf.PdfReader in project i7j-pdfsweep by itext.
the class PdfCleanUpToolTest method autoCleanPageWithAdditionalLocationAndPropertyTest.
@Test
public void autoCleanPageWithAdditionalLocationAndPropertyTest() throws Exception {
String input = INPUT_PATH + "fontCleanup.pdf";
String output = OUTPUT_PATH + "autoCleanPageWithAdditionalLocationAndPropertyTest.pdf";
String cmp = INPUT_PATH + "cmp_autoCleanPageWithAdditionalLocationAndPropertyTest.pdf";
CompositeCleanupStrategy strategy = new CompositeCleanupStrategy();
strategy.add(new RegexBasedCleanupStrategy("leonard"));
List<PdfCleanUpLocation> additionalLocation = Arrays.asList(new PdfCleanUpLocation(1, new Rectangle(0, 0, 200, 100), ColorConstants.RED));
try (PdfReader reader = new PdfReader(input);
PdfWriter writer = new PdfWriter(output);
PdfDocument document = new PdfDocument(reader, writer)) {
PdfCleaner.autoSweepCleanUp(document.getPage(1), strategy, additionalLocation, new CleanUpProperties());
}
compareByContent(cmp, output, OUTPUT_PATH, "autoCleanPageWithAdditionalLocationAndPropertyTest");
}
use of com.itextpdf.kernel.pdf.PdfReader in project MtgDesktopCompanion by nicho92.
the class DCIDeckSheetExport method exportDeck.
@Override
public void exportDeck(MagicDeck deck, File dest) throws IOException {
try (var pdfSrc = new PdfDocument(new PdfReader(this.getClass().getResource("/data/mtg_constructed_deck_registration_sheet.pdf").openStream()));
var docSrc = new Document(pdfSrc);
var pdfDest = new PdfDocument(new PdfWriter(dest));
var docDest = new Document(pdfDest)) {
pdfDest.setDefaultPageSize(PageSize.A4);
pdfSrc.copyPagesTo(1, 1, pdfDest);
float h = pdfDest.getDefaultPageSize().getHeight();
float w = pdfDest.getDefaultPageSize().getWidth();
// HEADER
docDest.add(createParagraphe(getString(LAST_NAME).substring(0, 1).toUpperCase(), w - 35, h - 103));
if (!getString(FORCED_DATE).equalsIgnoreCase(""))
docDest.add(createParagraphe(getString(FORCED_DATE), w / 3.2f, h - 127));
else
docDest.add(createParagraphe(new SimpleDateFormat(getString(DATE_FORMAT)).format(new Date()), w / 3.2f, h - 127));
docDest.add(createParagraphe(getString(LOCATION), w / 3.2f, h - 150));
docDest.add(createParagraphe(getString(EVENT_NAME), w / 1.40f, h - 127));
docDest.add(createParagraphe(deck.getName(), w / 1.40f, h - 150));
if (getString(DECK_DESIGNER).equals(""))
docDest.add(createParagraphe(getString(LAST_NAME) + " " + getString(FIRST_NAME), w / 1.40f, h - 175));
else
docDest.add(createParagraphe(getString(DECK_DESIGNER), w / 1.40f, h - 175));
// MAIN DECK
var count = 0;
for (Entry<MagicCard, Integer> e : deck.getMain().entrySet().stream().filter(e -> !e.getKey().isBasicLand()).toList()) {
docDest.add(createParagraphe(e.getValue() + space + e.getKey().getName(), w / 6.4f, h - 240 - count));
count += 18;
notify(e.getKey());
}
count = 0;
for (Entry<MagicCard, Integer> e : deck.getMain().entrySet().stream().filter(e -> e.getKey().isBasicLand()).toList()) {
docDest.add(createParagraphe(e.getValue() + space + e.getKey().getName(), w / 1.65f, h - 240 - count));
count += 18;
notify(e.getKey());
}
// SIDEBOARD
count = 0;
for (MagicCard mc : deck.getSideBoard().keySet()) {
docDest.add(createParagraphe(deck.getSideBoard().get(mc) + space + mc.getName(), w / 1.65f, h - 474 - count));
notify(mc);
count += 18;
}
// BOTTOM card count
docDest.add(createParagraphe(String.valueOf(deck.getMainAsList().size()), (w / 2) - 25, 40));
docDest.add(createParagraphe(String.valueOf(deck.getSideAsList().size()), w - 55, 95));
// LEFT TEXT
var p = createParagraphe(getString(LAST_NAME), 60, 90);
p.setRotationAngle(1.5708f);
docDest.add(p);
p = createParagraphe(getString(FIRST_NAME), 60, 300);
p.setRotationAngle(1.5708f);
docDest.add(p);
var dci = getString(DCI_NUMBER);
count = 0;
for (var i = 0; i < dci.length(); i++) {
var c = dci.charAt(i);
p = createParagraphe(String.valueOf(c), 60, (430 + count));
p.setRotationAngle(1.5708f);
docDest.add(p);
count += 22;
}
} catch (Exception e) {
throw new IOException(e.getMessage());
}
}
use of com.itextpdf.kernel.pdf.PdfReader in project java-example by saxingz.
the class A0025PdfApplication method main.
public static void main(String[] args) throws IOException {
byte[] user = "".getBytes();
byte[] owner = "xyz".getBytes();
// PdfDocument pdfDoc =
// new PdfDocument(new PdfReader("D:\\D_desktop\\book\\big2.pdf"),
// new PdfWriter("D:\\D_desktop\\book\\big4.pdf",
// new WriterProperties()
// .setStandardEncryption(user, owner,
// EncryptionConstants.ALLOW_PRINTING | EncryptionConstants.ALLOW_COPY,
// EncryptionConstants.ENCRYPTION_AES_256)));
PdfDocument pdfDoc = new PdfDocument(new PdfReader(INPATH), new PdfWriter(OUTPATH));
Document document = new Document(pdfDoc);
Rectangle pageSize;
PdfCanvas canvas;
int totalPage = pdfDoc.getNumberOfPages();
for (int i = 1; i <= totalPage; i++) {
System.out.print("进度: " + i + " / " + totalPage + "\t");
PdfPage page = pdfDoc.getPage(i);
pageSize = page.getPageSize();
canvas = new PdfCanvas(page);
addText2(canvas, pageSize, totalPage, i, document, pdfDoc, page);
}
pdfDoc.close();
}
Aggregations