Search in sources :

Example 41 with COSDictionary

use of com.tom_roush.pdfbox.cos.COSDictionary in project PdfBox-Android by TomRoush.

the class PDFormFieldAdditionalActions method getV.

/**
 * This will get a JavaScript action to be performed
 * when the field's value is changed. This allows the
 * new value to be checked for validity.
 * The name V stands for "validate".
 *
 * @return The V entry of form field's additional actions dictionary.
 */
public PDAction getV() {
    COSDictionary v = (COSDictionary) actions.getDictionaryObject(COSName.V);
    PDAction retval = null;
    if (v != null) {
        retval = PDActionFactory.createAction(v);
    }
    return retval;
}
Also used : COSDictionary(com.tom_roush.pdfbox.cos.COSDictionary)

Example 42 with COSDictionary

use of com.tom_roush.pdfbox.cos.COSDictionary in project PdfBox-Android by TomRoush.

the class PDFormFieldAdditionalActions method getC.

/**
 * This will get a JavaScript action to be performed in order to recalculate
 * the value of this field when that of another field changes. The order in which
 * the document's fields are recalculated is defined by the CO entry in the
 * interactive form dictionary.
 * The name C stands for "calculate".
 *
 * @return The C entry of form field's additional actions dictionary.
 */
public PDAction getC() {
    COSDictionary c = (COSDictionary) actions.getDictionaryObject(COSName.C);
    PDAction retval = null;
    if (c != null) {
        retval = PDActionFactory.createAction(c);
    }
    return retval;
}
Also used : COSDictionary(com.tom_roush.pdfbox.cos.COSDictionary)

Example 43 with COSDictionary

use of com.tom_roush.pdfbox.cos.COSDictionary in project PdfBox-Android by TomRoush.

the class PDPageAdditionalActions method getO.

/**
 * This will get an action to be performed when the page
 * is opened. This action is independent of any that may be
 * defined by the OpenAction entry in the document catalog,
 * and is executed after such an action.
 *
 * @return The O entry of page object's additional actions dictionary.
 */
public PDAction getO() {
    COSDictionary o = (COSDictionary) actions.getDictionaryObject(COSName.O);
    PDAction retval = null;
    if (o != null) {
        retval = PDActionFactory.createAction(o);
    }
    return retval;
}
Also used : COSDictionary(com.tom_roush.pdfbox.cos.COSDictionary)

Example 44 with COSDictionary

use of com.tom_roush.pdfbox.cos.COSDictionary in project PdfBox-Android by TomRoush.

the class TestPDPageAnnotationsFiltering method initMock.

@Before
public void initMock() {
    COSDictionary mockedPageWithAnnotations = new COSDictionary();
    COSArray annotsDictionary = new COSArray();
    annotsDictionary.add(new PDAnnotationRubberStamp().getCOSObject());
    annotsDictionary.add(new PDAnnotationSquareCircle(PDAnnotationSquareCircle.SUB_TYPE_SQUARE).getCOSObject());
    annotsDictionary.add(new PDAnnotationLink().getCOSObject());
    mockedPageWithAnnotations.setItem(COSName.ANNOTS, annotsDictionary);
    page = new PDPage(mockedPageWithAnnotations);
}
Also used : PDAnnotationRubberStamp(com.tom_roush.pdfbox.pdmodel.interactive.annotation.PDAnnotationRubberStamp) COSDictionary(com.tom_roush.pdfbox.cos.COSDictionary) COSArray(com.tom_roush.pdfbox.cos.COSArray) PDAnnotationLink(com.tom_roush.pdfbox.pdmodel.interactive.annotation.PDAnnotationLink) PDAnnotationSquareCircle(com.tom_roush.pdfbox.pdmodel.interactive.annotation.PDAnnotationSquareCircle) Before(org.junit.Before)

Example 45 with COSDictionary

use of com.tom_roush.pdfbox.cos.COSDictionary in project PdfBox-Android by TomRoush.

the class TestFontEmbedding method testCIDFontType2VerticalSubsetProportional.

/**
 * Embed a proportional TTF as vertical CIDFontType2 with subsetting.
 *
 * @throws IOException
 */
@Test
public void testCIDFontType2VerticalSubsetProportional() throws IOException {
    String text = "「ABC」";
    String expectedExtractedtext = "「\nA\nB\nC\n」";
    File pdf = new File(OUT_DIR, "CIDFontType2VP.pdf");
    PDDocument document = new PDDocument();
    PDPage page = new PDPage(PDRectangle.A4);
    document.addPage(page);
    File ipafont = new File("target/fonts/ipagp00303", "ipagp.ttf");
    assumeTrue(ipafont.exists());
    PDType0Font vfont = PDType0Font.loadVertical(document, ipafont);
    PDPageContentStream contentStream = new PDPageContentStream(document, page);
    contentStream.beginText();
    contentStream.setFont(vfont, 20);
    contentStream.newLineAtOffset(50, 700);
    contentStream.showText(text);
    contentStream.endText();
    contentStream.close();
    // Check the font substitution
    byte[] encode = vfont.encode(text);
    int cid = ((encode[0] & 0xFF) << 8) + (encode[1] & 0xFF);
    // it's 12461 without substitution
    assertEquals(12607, cid);
    // Check the dictionaries
    COSDictionary fontDict = vfont.getCOSObject();
    assertEquals(COSName.IDENTITY_V, fontDict.getDictionaryObject(COSName.ENCODING));
    document.save(pdf);
    // Vertical metrics are fixed during subsetting, so do this after calling save()
    COSDictionary descFontDict = vfont.getDescendantFont().getCOSObject();
    COSArray dw2 = (COSArray) descFontDict.getDictionaryObject(COSName.DW2);
    // This font uses default values for DW2
    assertNull(dw2);
    // c [ w1_1y v_1x v_1y ... w1_ny v_nx v_ny ]
    COSArray w2 = (COSArray) descFontDict.getDictionaryObject(COSName.W2);
    assertEquals(2, w2.size());
    // Start CID
    assertEquals(12607, w2.getInt(0));
    COSArray metrics = (COSArray) w2.getObject(1);
    int i = 0;
    for (int n : new int[] { -570, 500, 450, -570, 500, 880 }) {
        assertEquals(n, metrics.getInt(i++));
    }
    document.close();
    // Check text extraction
    String extracted = getUnicodeText(pdf);
    assertEquals(expectedExtractedtext, extracted.replaceAll("\r", "").trim());
}
Also used : PDPage(com.tom_roush.pdfbox.pdmodel.PDPage) COSDictionary(com.tom_roush.pdfbox.cos.COSDictionary) COSArray(com.tom_roush.pdfbox.cos.COSArray) PDDocument(com.tom_roush.pdfbox.pdmodel.PDDocument) PDPageContentStream(com.tom_roush.pdfbox.pdmodel.PDPageContentStream) File(java.io.File) Test(org.junit.Test)

Aggregations

COSDictionary (com.tom_roush.pdfbox.cos.COSDictionary)221 COSArray (com.tom_roush.pdfbox.cos.COSArray)68 COSBase (com.tom_roush.pdfbox.cos.COSBase)68 IOException (java.io.IOException)25 ArrayList (java.util.ArrayList)24 COSName (com.tom_roush.pdfbox.cos.COSName)23 COSObject (com.tom_roush.pdfbox.cos.COSObject)22 COSArrayList (com.tom_roush.pdfbox.pdmodel.common.COSArrayList)15 HashMap (java.util.HashMap)14 COSStream (com.tom_roush.pdfbox.cos.COSStream)13 Map (java.util.Map)12 PDPage (com.tom_roush.pdfbox.pdmodel.PDPage)10 COSString (com.tom_roush.pdfbox.cos.COSString)7 PDDocument (com.tom_roush.pdfbox.pdmodel.PDDocument)6 PDResources (com.tom_roush.pdfbox.pdmodel.PDResources)6 ByteArrayOutputStream (java.io.ByteArrayOutputStream)6 List (java.util.List)6 ByteArrayInputStream (java.io.ByteArrayInputStream)5 File (java.io.File)5 Test (org.junit.Test)5