本文整理汇总了Java中com.itextpdf.text.pdf.PdfDictionary.getAsArray方法的典型用法代码示例。如果您正苦于以下问题:Java PdfDictionary.getAsArray方法的具体用法?Java PdfDictionary.getAsArray怎么用?Java PdfDictionary.getAsArray使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.itextpdf.text.pdf.PdfDictionary
的用法示例。
在下文中一共展示了PdfDictionary.getAsArray方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: extractAttachments
import com.itextpdf.text.pdf.PdfDictionary; //导入方法依赖的package包/类
/**
* These two methods ({@link #extractAttachments(PdfReader, String)} and
* {@link #extractAttachment(PdfReader, File, PdfString, PdfDictionary)})
* essentially are the OP's original code posted in his question. They
* extract files without the folder structure.
*/
public static void extractAttachments(PdfReader reader, String dir) throws IOException
{
File folder = new File(dir);
folder.mkdirs();
PdfDictionary root = reader.getCatalog();
PdfDictionary names = root.getAsDict(PdfName.NAMES);
System.out.println("" + names.getKeys().toString());
PdfDictionary embedded = names.getAsDict(PdfName.EMBEDDEDFILES);
System.out.println("" + embedded.toString());
PdfArray filespecs = embedded.getAsArray(PdfName.NAMES);
//System.out.println(filespecs.getAsString(root1));
for (int i = 0; i < filespecs.size();)
{
extractAttachment(reader, folder, filespecs.getAsString(i++), filespecs.getAsDict(i++));
}
}
示例2: extractAttachmentsWithFolders
import com.itextpdf.text.pdf.PdfDictionary; //导入方法依赖的package包/类
/**
* <p>
* These two methods ({@link #extractAttachmentsWithFolders(PdfReader, String)} and
* {@link #extractAttachment(PdfReader, Map, PdfString, PdfDictionary)}) extend the
* functionality of the OP's original code posted in his question. They extract files
* with the folder structure.
* </p>
* <p>
* The information concerning the portfolio folder structure is retrieved using
* the method {@link #retrieveFolders(PdfReader, File)} and its helper method
* {@link #collectFolders(Map, PdfDictionary, File)}.
* </p>
*/
public static void extractAttachmentsWithFolders(PdfReader reader, String dir) throws IOException, DocumentException
{
File folder = new File(dir);
folder.mkdirs();
Map<Integer, File> folders = retrieveFolders(reader, folder);
PdfDictionary root = reader.getCatalog();
PdfDictionary names = root.getAsDict(PdfName.NAMES);
System.out.println("" + names.getKeys().toString());
PdfDictionary embedded = names.getAsDict(PdfName.EMBEDDEDFILES);
System.out.println("" + embedded.toString());
PdfArray filespecs = embedded.getAsArray(PdfName.NAMES);
for (int i = 0; i < filespecs.size();)
{
extractAttachment(reader, folders, folder, filespecs.getAsString(i++), filespecs.getAsDict(i++));
}
}
示例3: renderText
import com.itextpdf.text.pdf.PdfDictionary; //导入方法依赖的package包/类
@Override
public void renderText(TextRenderInfo renderInfo)
{
DocumentFont font =renderInfo.getFont();
PdfDictionary dict = font.getFontDictionary();
PdfDictionary encoding = dict.getAsDict(PdfName.ENCODING);
PdfArray diffs = encoding.getAsArray(PdfName.DIFFERENCES);
;
StringBuilder builder = new StringBuilder();
for (byte b : renderInfo.getPdfString().getBytes())
{
PdfName name = diffs.getAsName((char)b);
String s = name.toString().substring(2);
int i = Integer.parseUnsignedInt(s, 16);
builder.append((char)i);
}
try
{
stringField.set(renderInfo, builder.toString());
}
catch (IllegalArgumentException | IllegalAccessException e)
{
e.printStackTrace();
}
strategy.renderText(renderInfo);
}
示例4: copyLinks
import com.itextpdf.text.pdf.PdfDictionary; //导入方法依赖的package包/类
/**
* <p>
* A primitive attempt at copying links from page <code>sourcePage</code>
* of <code>PdfReader reader</code> to page <code>targetPage</code> of
* <code>PdfStamper stamper</code>.
* </p>
* <p>
* This method is meant only for the use case at hand, i.e. copying a link
* to an external URI without expecting any advanced features.
* </p>
*/
void copyLinks(PdfStamper stamper, int targetPage, PdfReader reader, int sourcePage)
{
PdfDictionary sourcePageDict = reader.getPageNRelease(sourcePage);
PdfArray annotations = sourcePageDict.getAsArray(PdfName.ANNOTS);
if (annotations != null && annotations.size() > 0)
{
for (PdfObject annotationObject : annotations)
{
annotationObject = PdfReader.getPdfObject(annotationObject);
if (!annotationObject.isDictionary())
continue;
PdfDictionary annotation = (PdfDictionary) annotationObject;
if (!PdfName.LINK.equals(annotation.getAsName(PdfName.SUBTYPE)))
continue;
PdfArray rectArray = annotation.getAsArray(PdfName.RECT);
if (rectArray == null || rectArray.size() < 4)
continue;
Rectangle rectangle = PdfReader.getNormalizedRectangle(rectArray);
PdfName hightLight = annotation.getAsName(PdfName.H);
if (hightLight == null)
hightLight = PdfAnnotation.HIGHLIGHT_INVERT;
PdfDictionary actionDict = annotation.getAsDict(PdfName.A);
if (actionDict == null || !PdfName.URI.equals(actionDict.getAsName(PdfName.S)))
continue;
PdfString urlPdfString = actionDict.getAsString(PdfName.URI);
if (urlPdfString == null)
continue;
PdfAction action = new PdfAction(urlPdfString.toString());
PdfAnnotation link = PdfAnnotation.createLink(stamper.getWriter(), rectangle, hightLight, action);
stamper.addAnnotation(link, targetPage);
}
}
}
示例5: show
import com.itextpdf.text.pdf.PdfDictionary; //导入方法依赖的package包/类
void show(FdfReader fdfReader)
{
PdfDictionary catalog = fdfReader.getCatalog();
catalog = catalog.getAsDict(PdfName.FDF);
Assert.assertNotNull("FDF catalogue is null", catalog);
PdfArray annots = catalog.getAsArray(PdfName.ANNOTS);
Assert.assertNotNull("FDF annotations are null", annots);
System.out.println(annots);
}
示例6: testWidgetToField
import com.itextpdf.text.pdf.PdfDictionary; //导入方法依赖的package包/类
/**
* <a href="http://stackoverflow.com/questions/31402602/how-to-rename-only-the-first-found-duplicate-acrofield-in-pdf">
* How to rename only the first found duplicate acrofield in pdf?
* </a>
* <br>
* <a href="http://s000.tinyupload.com/index.php?file_id=34970992934525199618">
* test_duplicate_field2.pdf
* </a>
* <p>
* Demonstration of how to transform generate a new field for a widget.
* </p>
*/
@Test
public void testWidgetToField() throws IOException, DocumentException
{
try ( InputStream resource = getClass().getResourceAsStream("test_duplicate_field2.pdf");
OutputStream result = new FileOutputStream(new File(RESULT_FOLDER, "test_duplicate_field2-widgetToField.pdf")) )
{
PdfReader reader = new PdfReader(resource);
PdfDictionary form = reader.getCatalog().getAsDict(PdfName.ACROFORM);
PdfArray fields = form.getAsArray(PdfName.FIELDS);
for (PdfObject object: fields)
{
PdfDictionary field = (PdfDictionary) PdfReader.getPdfObject(object);
if ("Text1".equals(field.getAsString(PdfName.T).toString()))
{
PdfDictionary newField = new PdfDictionary();
PRIndirectReference newFieldRef = reader.addPdfObject(newField);
fields.add(newFieldRef);
newField.putAll(field);
newField.put(PdfName.T, new PdfString("foobar"));
PdfArray newKids = new PdfArray();
newField.put(PdfName.KIDS, newKids);
PdfArray kids = field.getAsArray(PdfName.KIDS);
PdfObject widget = kids.remove(0);
newKids.add(widget);
PdfDictionary widgetDict = (PdfDictionary) PdfReader.getPdfObject(widget);
widgetDict.put(PdfName.PARENT, newFieldRef);
break;
}
}
PdfStamper stamper = new PdfStamper(reader, result);
stamper.close();
}
}
示例7: testMarkAnnotationsReadOnly
import com.itextpdf.text.pdf.PdfDictionary; //导入方法依赖的package包/类
/**
* <a href="http://stackoverflow.com/questions/37275267/how-to-make-pdf-annotation-as-read-only-using-itext">
* how to make pdf annotation as read only using itext?
* </a>
* <br/>
* test-annotated.pdf <i>simple PDF with sticky note</i>
*
* <p>
* This test shows how to set the read-only flags of all annotations of a document.
* </p>
*/
@Test
public void testMarkAnnotationsReadOnly() throws IOException, DocumentException
{
try ( InputStream resourceStream = getClass().getResourceAsStream("test-annotated.pdf");
OutputStream outputStream = new FileOutputStream(new File(RESULT_FOLDER, "test-annotated-ro.pdf")) )
{
PdfReader reader = new PdfReader(resourceStream);
PdfStamper stamper = new PdfStamper(reader, outputStream);
for (int page = 1; page <= reader.getNumberOfPages(); page++)
{
PdfDictionary pageDictionary = reader.getPageN(page);
PdfArray annotationArray = pageDictionary.getAsArray(PdfName.ANNOTS);
if (annotationArray == null)
continue;
for (PdfObject object : annotationArray)
{
PdfObject directObject = PdfReader.getPdfObject(object);
if (directObject instanceof PdfDictionary)
{
PdfDictionary annotationDictionary = (PdfDictionary) directObject;
PdfNumber flagsNumber = annotationDictionary.getAsNumber(PdfName.F);
int flags = flagsNumber != null ? flagsNumber.intValue() : 0;
flags |= PdfAnnotation.FLAGS_READONLY;
annotationDictionary.put(PdfName.F, new PdfNumber(flags));
}
}
}
stamper.close();
}
}
示例8: testInsertTitlePage
import com.itextpdf.text.pdf.PdfDictionary; //导入方法依赖的package包/类
/**
* <a href="http://stackoverflow.com/questions/28911509/how-to-retain-page-labels-when-concatenating-an-existing-pdf-with-a-pdf-created">
* How to retain page labels when concatenating an existing pdf with a pdf created from scratch?
* </a>
* <p>
* A proposal how to implement the task using a {@link PdfStamper}.
*/
@Test
public void testInsertTitlePage() throws IOException, DocumentException
{
try ( InputStream documentStream = getClass().getResourceAsStream("Labels.pdf");
InputStream titleStream = getClass().getResourceAsStream("Cover.pdf");
OutputStream outputStream = new FileOutputStream(new File(RESULT_FOLDER, "labels-with-cover-page.pdf")) )
{
PdfReader titleReader = new PdfReader(titleStream);
PdfReader reader = new PdfReader(documentStream);
PdfStamper stamper = new PdfStamper(reader, outputStream);
PdfImportedPage page = stamper.getImportedPage(titleReader, 1);
stamper.insertPage(1, titleReader.getPageSize(1));
PdfContentByte content = stamper.getUnderContent(1);
content.addTemplate(page, 0, 0);
copyLinks(stamper, 1, titleReader, 1);
PdfDictionary root = reader.getCatalog();
PdfDictionary labels = root.getAsDict(PdfName.PAGELABELS);
if (labels != null)
{
PdfArray newNums = new PdfArray();
newNums.add(new PdfNumber(0));
PdfDictionary coverDict = new PdfDictionary();
coverDict.put(PdfName.P, new PdfString("Cover Page"));
newNums.add(coverDict);
PdfArray nums = labels.getAsArray(PdfName.NUMS);
if (nums != null)
{
for (int i = 0; i < nums.size() - 1; )
{
int n = nums.getAsNumber(i++).intValue();
newNums.add(new PdfNumber(n+1));
newNums.add(nums.getPdfObject(i++));
}
}
labels.put(PdfName.NUMS, newNums);
stamper.markUsed(labels);
}
stamper.close();
}
}
示例9: verify
import com.itextpdf.text.pdf.PdfDictionary; //导入方法依赖的package包/类
boolean verify(PdfReader reader, PdfDictionary value) throws GeneralSecurityException
{
PdfArray byteRange = value.getAsArray(PdfName.BYTERANGE);
if (byteRange == null || byteRange.isEmpty())
{
System.out.printf(" Signed range: missing\n");
}
else
{
StringBuilder builder = new StringBuilder();
builder.append(" Signed range:");
for (PdfObject arrObj: byteRange)
{
builder.append(' ').append(arrObj);
}
int byteRangeSize = byteRange.size();
if (byteRangeSize % 2 == 1)
{
builder.append(" (Invalid: odd number of entries)");
}
else
{
StringBuilder interoperability = new StringBuilder();
if (byteRangeSize != 4)
{
interoperability.append(", not exactly one gap");
}
int rangeStart = byteRange.getAsNumber(0).intValue();
if (rangeStart != 0)
{
interoperability.append(", first range does not start at 0");
}
for (int i = 2; i < byteRangeSize; i+=2)
{
int lastRangeEnd = rangeStart + byteRange.getAsNumber(i-1).intValue();
rangeStart = byteRange.getAsNumber(i).intValue();
if (lastRangeEnd > rangeStart)
{
interoperability.append(", unordered or overlapping ranges");
break;
}
}
if (interoperability.length() > 0)
{
builder.append(" (Interoperability issues").append(interoperability).append(')');
}
int finalRangeEnd = byteRange.getAsNumber(byteRangeSize-2).intValue() + byteRange.getAsNumber(byteRangeSize-1).intValue();
if (finalRangeEnd == reader.getFileLength())
{
builder.append(" (covers whole file)");
}
else
{
builder.append(" (covers partial file up to ").append(finalRangeEnd).append(")");
}
}
System.out.println(builder);
}
PdfPKCS7 pkcs7 = verifySignature(reader, value, null);
System.out.printf(" Validity: %s\n", pkcs7.verify());
return pkcs7 != null;
}