本文整理了Java中org.apache.pdfbox.pdmodel.PDDocument.getDocumentCatalog()
方法的一些代码示例,展示了PDDocument.getDocumentCatalog()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。PDDocument.getDocumentCatalog()
方法的具体详情如下:
包路径:org.apache.pdfbox.pdmodel.PDDocument
类名称:PDDocument
方法名:getDocumentCatalog
[英]This will get the document CATALOG. This is guaranteed to not return null.
[中]这将获得文档目录。这保证不会返回null。
代码示例来源:origin: apache/pdfbox
/**
* Returns the page tree.
*
* @return the page tree
*/
public PDPageTree getPages()
{
return getDocumentCatalog().getPages();
}
代码示例来源:origin: stackoverflow.com
PDDocument doc = PDDocument.load("C:/mydoc3.pdf");
List<PDPage> pages = doc.getDocumentCatalog().getAllPages();
for(PDPage page:pages){
Map<String,PDFont> pageFonts=page.getResources().getFonts();
}
代码示例来源:origin: apache/tika
private boolean shouldHandleXFAOnly(PDDocument pdDocument, PDFParserConfig config) {
if (config.getIfXFAExtractOnlyXFA() &&
pdDocument.getDocumentCatalog() != null &&
pdDocument.getDocumentCatalog().getAcroForm() != null &&
pdDocument.getDocumentCatalog().getAcroForm().getXFA() != null) {
return true;
}
return false;
}
代码示例来源:origin: apache/pdfbox
/**
* This will return the total page count of the PDF document.
*
* @return The total number of pages in the PDF document.
*/
public int getNumberOfPages()
{
return getDocumentCatalog().getPages().getCount();
}
代码示例来源:origin: apache/pdfbox
/**
* Indicates whether an optional content group is enabled.
* @param group the group
* @return true if the group is enabled
*/
public boolean isGroupEnabled(PDOptionalContentGroup group)
{
PDOptionalContentProperties ocProperties = document.getDocumentCatalog().getOCProperties();
return ocProperties == null || ocProperties.isGroupEnabled(group);
}
代码示例来源:origin: apache/tika
void extractBookmarkText() throws SAXException, IOException, TikaException {
PDDocumentOutline outline = document.getDocumentCatalog().getDocumentOutline();
if (outline != null) {
extractBookmarkText(outline);
}
}
代码示例来源:origin: apache/pdfbox
/**
* Retrieve all signature fields from the document.
*
* @return a <code>List</code> of <code>PDSignatureField</code>s
*/
public List<PDSignatureField> getSignatureFields()
{
List<PDSignatureField> fields = new ArrayList<>();
PDAcroForm acroForm = getDocumentCatalog().getAcroForm();
if (acroForm != null)
{
for (PDField field : acroForm.getFieldTree())
{
if (field instanceof PDSignatureField)
{
fields.add((PDSignatureField)field);
}
}
}
return fields;
}
代码示例来源:origin: apache/pdfbox
/**
* Returns the page at the given 0-based index.
* <p>
* This method is too slow to get all the pages from a large PDF document
* (1000 pages or more). For such documents, use the iterator of
* {@link PDDocument#getPages()} instead.
*
* @param pageIndex the 0-based page index
* @return the page at the given index.
*/
public PDPage getPage(int pageIndex) // todo: REPLACE most calls to this method with BELOW method
{
return getDocumentCatalog().getPages().get(pageIndex);
}
代码示例来源:origin: apache/pdfbox
@Override
public void createAcroForm(PDDocument template)
{
PDAcroForm theAcroForm = new PDAcroForm(template);
template.getDocumentCatalog().setAcroForm(theAcroForm);
pdfStructure.setAcroForm(theAcroForm);
LOG.info("AcroForm has been created");
}
代码示例来源:origin: apache/pdfbox
/**
* Check if metadata dictionary has no stream filter
*
* @param doc the document to check.
* @return the list of validation errors.
*/
protected List<ValidationError> checkStreamFilterUsage(PDDocument doc)
{
List<ValidationError> ve = new ArrayList<>();
List<?> filters = doc.getDocumentCatalog().getMetadata().getFilters();
if (filters != null && !filters.isEmpty())
{
ve.add(new ValidationError(PreflightConstants.ERROR_METADATA_MAIN,
"Using stream filter on metadata dictionary is forbidden"));
}
return ve;
}
}
代码示例来源:origin: apache/pdfbox
/**
* This will print all the fields from the document.
*
* @param pdfDocument The PDF to get the fields from.
*
* @throws IOException If there is an error getting the fields.
*/
public void printFields(PDDocument pdfDocument) throws IOException
{
PDDocumentCatalog docCatalog = pdfDocument.getDocumentCatalog();
PDAcroForm acroForm = docCatalog.getAcroForm();
List<PDField> fields = acroForm.getFields();
System.out.println(fields.size() + " top-level fields were found on the form");
for (PDField field : fields)
{
processField(field, "|--", field.getPartialName());
}
}
代码示例来源:origin: apache/pdfbox
/**
* This will takes the values from the fdf document and import them into the
* PDF document.
*
* @param pdfDocument The document to put the fdf data into.
* @param fdfDocument The FDF document to get the data from.
*
* @throws IOException If there is an error setting the data in the field.
*/
public void importFDF( PDDocument pdfDocument, FDFDocument fdfDocument ) throws IOException
{
PDDocumentCatalog docCatalog = pdfDocument.getDocumentCatalog();
PDAcroForm acroForm = docCatalog.getAcroForm();
acroForm.setCacheFields( true );
acroForm.importFDF( fdfDocument );
}
代码示例来源:origin: stackoverflow.com
//Using PDFBox library available from http://pdfbox.apache.org/
//Writes pdf document of specific pages as a new pdf file
//Reads in pdf document
PDDocument pdDoc = PDDocument.load(file);
//Creates a new pdf document
PDDocument document = null;
//Adds specific page "i" where "i" is the page number and then saves the new pdf document
try {
document = new PDDocument();
document.addPage((PDPage) pdDoc.getDocumentCatalog().getAllPages().get(i));
document.save("file path"+"new document title"+".pdf");
document.close();
}catch(Exception e){}
代码示例来源:origin: apache/tika
@Override
protected void startDocument(PDDocument pdf) throws IOException {
try {
xhtml.startDocument();
try {
handleDestinationOrAction(pdf.getDocumentCatalog().getOpenAction(), ActionTrigger.DOCUMENT_OPEN);
} catch (IOException e) {
//See PDFBOX-3773
//swallow -- no need to report this
}
} catch (TikaException|SAXException e) {
throw new IOExceptionWithCause("Unable to start a document", e);
}
}
代码示例来源:origin: apache/pdfbox
public static void main(String[] args) throws IOException
{
// Load the PDF document created by SimpleForm.java
try (PDDocument document = PDDocument.load(new File("target/SimpleForm.pdf")))
{
// Note that the JavaScript will depend on the reader application.
// The classes and methods available to Adobe Reader and Adobe Acrobat
// are documented in the Acrobat SDK.
String javaScript = "var now = util.printd('yyyy-mm-dd', new Date());"
+ "var oField = this.getField('SampleField');"
+ "oField.value = now;";
// Create an action as JavaScript action
PDActionJavaScript jsAction = new PDActionJavaScript();
jsAction.setAction(javaScript);
// Set the action to be executed when the document is opened
document.getDocumentCatalog().setOpenAction(jsAction);
document.save("target/UpdateFieldOnDocumentOpen.pdf");
}
}
}
代码示例来源:origin: apache/pdfbox
private void initRectMap()
{
PDAcroForm acroForm = document.getDocumentCatalog().getAcroForm();
if (acroForm == null)
{
return;
}
for (PDField field : acroForm.getFieldTree())
{
String fullyQualifiedName = field.getFullyQualifiedName();
for (PDAnnotationWidget widget : field.getWidgets())
{
if (page.equals(widget.getPage()))
{
rectMap.put(widget.getRectangle(), fullyQualifiedName);
}
}
}
}
代码示例来源:origin: apache/tika
private void handleXFAOnly(PDDocument pdDocument, ContentHandler handler,
Metadata metadata, ParseContext context)
throws SAXException, IOException, TikaException {
XFAExtractor ex = new XFAExtractor();
XHTMLContentHandler xhtml = new XHTMLContentHandler(handler, metadata);
xhtml.startDocument();
try (InputStream is = new ByteArrayInputStream(
pdDocument.getDocumentCatalog().getAcroForm().getXFA().getBytes())) {
ex.extract(is, xhtml, metadata, context);
} catch (XMLStreamException e) {
throw new TikaException("XML error in XFA", e);
}
xhtml.endDocument();
}
代码示例来源:origin: apache/pdfbox
/**
* Create a new document to write the split contents to.
*
* @return the newly created PDDocument.
* @throws IOException If there is an problem creating the new document.
*/
protected PDDocument createNewDocument() throws IOException
{
PDDocument document = memoryUsageSetting == null ?
new PDDocument() : new PDDocument(memoryUsageSetting);
document.getDocument().setVersion(getSourceDocument().getVersion());
document.setDocumentInformation(getSourceDocument().getDocumentInformation());
document.getDocumentCatalog().setViewerPreferences(
getSourceDocument().getDocumentCatalog().getViewerPreferences());
return document;
}
代码示例来源:origin: apache/pdfbox
public static void main(String[] args) throws IOException
{
// Load the PDF document created by SimpleForm.java
try (PDDocument document = PDDocument.load(new File("target/SimpleForm.pdf")))
{
PDAcroForm acroForm = document.getDocumentCatalog().getAcroForm();
// Get the field and the widget associated to it.
// Note: there might be multiple widgets
PDField field = acroForm.getField("SampleField");
PDAnnotationWidget widget = field.getWidgets().get(0);
// Create the definition for a green border
PDAppearanceCharacteristicsDictionary fieldAppearance =
new PDAppearanceCharacteristicsDictionary(new COSDictionary());
PDColor green = new PDColor(new float[] { 0, 1, 0 }, PDDeviceRGB.INSTANCE);
fieldAppearance.setBorderColour(green);
// Set the information to be used by the widget which is responsible
// for the visual style of the form field.
widget.setAppearanceCharacteristics(fieldAppearance);
document.save("target/AddBorderToField.pdf");
}
}
}
代码示例来源:origin: apache/pdfbox
@Override
public void validate(PreflightContext ctx) throws ValidationException
{
PDDocument pdfbox = ctx.getDocument();
this.catalog = pdfbox.getDocumentCatalog();
if (this.catalog == null)
{
ctx.addValidationError(new ValidationError(ERROR_SYNTAX_NOCATALOG, "There are no Catalog entry in the Document"));
}
else
{
validateActions(ctx);
validateLang(ctx);
validateNames(ctx);
validateOCProperties(ctx);
validateOutputIntent(ctx);
}
}
内容来源于网络,如有侵权,请联系作者删除!