Search in sources :

Example 6 with PDFTextStripper

use of com.tom_roush.pdfbox.text.PDFTextStripper in project PdfBox-Android by TomRoush.

the class TestPublicKeyEncryption method setUp.

/**
 * {@inheritDoc}
 */
@Before
public void setUp() throws Exception {
    if (Cipher.getMaxAllowedKeyLength("AES") != Integer.MAX_VALUE) {
        // we need strong encryption for these tests
        fail("JCE unlimited strength jurisdiction policy files are not installed");
    }
    testContext = InstrumentationRegistry.getInstrumentation().getContext();
    PDFBoxResourceLoader.init(testContext);
    testResultsDir = new File(testContext.getCacheDir(), "pdfbox-test-output/crypto");
    testResultsDir.mkdirs();
    permission1 = new AccessPermission();
    permission1.setCanAssembleDocument(false);
    permission1.setCanExtractContent(false);
    permission1.setCanExtractForAccessibility(true);
    permission1.setCanFillInForm(false);
    permission1.setCanModify(false);
    permission1.setCanModifyAnnotations(false);
    permission1.setCanPrint(false);
    permission1.setCanPrintDegraded(false);
    permission2 = new AccessPermission();
    permission2.setCanAssembleDocument(false);
    permission2.setCanExtractContent(false);
    permission2.setCanExtractForAccessibility(true);
    permission2.setCanFillInForm(false);
    permission2.setCanModify(false);
    permission2.setCanModifyAnnotations(false);
    // it is true now !
    permission2.setCanPrint(true);
    permission2.setCanPrintDegraded(false);
    recipient1 = getRecipient("test1.der", permission1);
    recipient2 = getRecipient("test2.der", permission2);
    password1 = "test1";
    password2 = "test2";
    keyStore1 = "test1.pfx";
    keyStore2 = "test2.pfx";
    document = PDDocument.load(testContext.getAssets().open(path + "test.pdf"));
    text = new PDFTextStripper().getText(document);
    producer = document.getDocumentInformation().getProducer();
    document.setVersion(1.7f);
}
Also used : AccessPermission(com.tom_roush.pdfbox.pdmodel.encryption.AccessPermission) File(java.io.File) PDFTextStripper(com.tom_roush.pdfbox.text.PDFTextStripper) Before(org.junit.Before)

Example 7 with PDFTextStripper

use of com.tom_roush.pdfbox.text.PDFTextStripper in project PdfBox-Android by TomRoush.

the class TestFontEncoding method testPDFBox3884.

/**
 * PDFBOX-3826: Some unicodes are reached by several names in glyphlist.txt, e.g. tilde and
 * ilde.
 *
 * @throws IOException
 */
public void testPDFBox3884() throws IOException {
    PDDocument doc = new PDDocument();
    PDPage page = new PDPage();
    doc.addPage(page);
    PDPageContentStream cs = new PDPageContentStream(doc, page);
    cs.setFont(PDType1Font.HELVETICA, 20);
    cs.beginText();
    cs.newLineAtOffset(100, 700);
    // first tilde is "asciitilde" (from the keyboard), 2nd tilde is "tilde"
    // using ˜ would bring IllegalArgumentException prior to bugfix
    cs.showText("~˜");
    cs.endText();
    cs.close();
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    doc.save(baos);
    doc.close();
    // verify
    doc = PDDocument.load(baos.toByteArray());
    PDFTextStripper stripper = new PDFTextStripper();
    String text = stripper.getText(doc);
    assertEquals("~˜", text.trim());
    doc.close();
}
Also used : PDPage(com.tom_roush.pdfbox.pdmodel.PDPage) PDDocument(com.tom_roush.pdfbox.pdmodel.PDDocument) PDPageContentStream(com.tom_roush.pdfbox.pdmodel.PDPageContentStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) PDFTextStripper(com.tom_roush.pdfbox.text.PDFTextStripper)

Aggregations

PDFTextStripper (com.tom_roush.pdfbox.text.PDFTextStripper)7 PDDocument (com.tom_roush.pdfbox.pdmodel.PDDocument)6 PDPage (com.tom_roush.pdfbox.pdmodel.PDPage)3 PDPageContentStream (com.tom_roush.pdfbox.pdmodel.PDPageContentStream)2 File (java.io.File)2 AccessPermission (com.tom_roush.pdfbox.pdmodel.encryption.AccessPermission)1 PDFRenderer (com.tom_roush.pdfbox.rendering.PDFRenderer)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 FileInputStream (java.io.FileInputStream)1 IOException (java.io.IOException)1 Before (org.junit.Before)1 Test (org.junit.Test)1