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;
}
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;
}
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;
}
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);
}
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());
}
Aggregations