本文整理匯總了Java中com.itextpdf.text.pdf.PdfReader.getPdfObject方法的典型用法代碼示例。如果您正苦於以下問題:Java PdfReader.getPdfObject方法的具體用法?Java PdfReader.getPdfObject怎麽用?Java PdfReader.getPdfObject使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類com.itextpdf.text.pdf.PdfReader
的用法示例。
在下文中一共展示了PdfReader.getPdfObject方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: FindImages
import com.itextpdf.text.pdf.PdfReader; //導入方法依賴的package包/類
/**
* @see #testExtractImageLikeSteveB()
*/
private static List<BufferedImage> FindImages(PdfReader reader, PdfDictionary pdfPage) throws IOException
{
List<BufferedImage> result = new ArrayList<>();
Iterable<PdfObject> imgPdfObject = FindImageInPDFDictionary(pdfPage);
for (PdfObject image : imgPdfObject)
{
int xrefIndex = ((PRIndirectReference)image).getNumber();
PdfObject stream = reader.getPdfObject(xrefIndex);
// Exception occurs here :
PdfImageObject pdfImage = new PdfImageObject((PRStream)stream);
BufferedImage img = pdfImage.getBufferedImage();
// Do something with the image
result.add(img);
}
return result;
}
示例2: copyLinks
import com.itextpdf.text.pdf.PdfReader; //導入方法依賴的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);
}
}
}
示例3: testWidgetToField
import com.itextpdf.text.pdf.PdfReader; //導入方法依賴的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();
}
}
示例4: testMarkAnnotationsReadOnly
import com.itextpdf.text.pdf.PdfReader; //導入方法依賴的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();
}
}
示例5: verify
import com.itextpdf.text.pdf.PdfReader; //導入方法依賴的package包/類
/**
* This method checks the signatures referenced from the AcroForm Fields.
*/
void verify(PdfReader reader) throws GeneralSecurityException
{
PdfDictionary top = (PdfDictionary)PdfReader.getPdfObjectRelease(reader.getCatalog().get(PdfName.ACROFORM));
if (top == null)
{
System.out.println("No AcroForm, so nothing to verify");
return;
}
PdfArray arrfds = (PdfArray)PdfReader.getPdfObjectRelease(top.get(PdfName.FIELDS));
if (arrfds == null || arrfds.isEmpty())
{
System.out.println("No AcroForm Fields, so nothing to verify");
return;
}
for (PdfObject object : arrfds)
{
object = PdfReader.getPdfObject(object);
if (object == null)
{
System.out.println("* A null entry.");
}
else if (!object.isDictionary())
{
System.out.println("* A non-dictionary entry.");
}
else
{
verify(reader, (PdfDictionary) object, null, null, null, false);
}
}
}