@Override public void injectProcSetArray(PDFormXObject innerForm, PDPage page, PDResources innerFormResources, PDResources imageFormResources, PDResources holderFormResources, COSArray procSet) { innerForm.getResources().getCOSObject().setItem(COSName.PROC_SET, procSet); page.getCOSObject().setItem(COSName.PROC_SET, procSet); innerFormResources.getCOSObject().setItem(COSName.PROC_SET, procSet); imageFormResources.getCOSObject().setItem(COSName.PROC_SET, procSet); holderFormResources.getCOSObject().setItem(COSName.PROC_SET, procSet); LOG.info("Inserted ProcSet to PDF"); }
/** * Check that fonts present in the Resources dictionary match with PDF/A-1 rules * * @param context * @param resources * @throws ValidationException */ protected void validateFonts(PreflightContext context, PDResources resources) throws ValidationException { Map<String, PDFont> mapOfFonts = getFonts(resources.getCOSObject(), context); for (Entry<String, PDFont> entry : mapOfFonts.entrySet()) { ContextHelper.validateElement(context, entry.getValue(), FONT_PROCESS); } }
private static boolean hasRecursion(PreflightContext context, Object element, PreflightPath validationPath) { if (element instanceof PDResources) { for (int i = 0; i < validationPath.size(); ++i) { Object obj = validationPath.getPathElement(i, Object.class); if (obj instanceof PDResources) { PDResources pdRes = (PDResources) obj; if (pdRes.getCOSObject() == ((PDResources) element).getCOSObject()) { context.addValidationError(new ValidationError(ERROR_PDF_PROCESSING, "Resources recursion")); return true; } } } } return false; }
@Override public void createWidgetDictionary(PDSignatureField signatureField, PDResources holderFormResources) throws IOException { COSDictionary widgetDict = signatureField.getWidgets().get(0).getCOSObject(); widgetDict.setNeedToBeUpdated(true); widgetDict.setItem(COSName.DR, holderFormResources.getCOSObject()); pdfStructure.setWidgetDictionary(widgetDict); LOG.info("WidgetDictionary has been created"); }
/** * * @param context * @param resources * @throws ValidationException */ protected void validateExtGStates(PreflightContext context, PDResources resources) throws ValidationException { COSBase egsEntry = resources.getCOSObject().getItem(TRANSPARENCY_DICTIONARY_KEY_EXTGSTATE); COSDocument cosDocument = context.getDocument().getDocument(); COSDictionary extGState = COSUtils.getAsDictionary(egsEntry, cosDocument); if (egsEntry != null) { ContextHelper.validateElement(context, extGState, EXTGSTATE_PROCESS); } }
private Map<Integer,LayoutPage> getLayoutPages(PDDocument doc) throws IOException { int numberOfPages = doc.getNumberOfPages(); Map<Integer,LayoutPage> layoutPages = new HashMap<>(numberOfPages); for (int i=0;i<numberOfPages;i++) { PDPage page = doc.getPage(i); COSBase contents = page.getCOSObject().getDictionaryObject(COSName.CONTENTS); PDResources resources = page.getResources(); if (resources == null) { resources = new PDResources(); } layoutPages.put(i, new LayoutPage(page.getMediaBox(), createCombinedContentStream(contents), resources.getCOSObject())); } return layoutPages; }
COSDictionary fontDict = defaultResources.getCOSObject().getCOSDictionary(COSName.FONT); if (fontDict == null) defaultResources.getCOSObject().setItem(COSName.FONT, fontDict); defaultResources.getCOSObject().setNeedToBeUpdated(true); fontDict.setNeedToBeUpdated(true); defaultResources.getCOSObject().setNeedToBeUpdated(true); fontDict.setNeedToBeUpdated(true);
private LayoutPage getLayoutPage(PDDocument doc) throws IOException { PDPage page = doc.getPage(0); COSBase contents = page.getCOSObject().getDictionaryObject(COSName.CONTENTS); PDResources resources = page.getResources(); if (resources == null) { resources = new PDResources(); } return new LayoutPage(page.getMediaBox(), createCombinedContentStream(contents), resources.getCOSObject()); }
protected void validateXObjects(PreflightContext context, PDResources resources) throws ValidationException COSDictionary mapOfXObj = COSUtils.getAsDictionary(resources.getCOSObject().getItem(COSName.XOBJECT), cosDocument); if (mapOfXObj != null)
@Override public void createImageForm(PDResources imageFormResources, PDResources innerFormResource, PDStream imageFormStream, PDRectangle bbox, AffineTransform at, PDImageXObject img) throws IOException { PDFormXObject imageForm = new PDFormXObject(imageFormStream); imageForm.setBBox(bbox); imageForm.setMatrix(at); imageForm.setResources(imageFormResources); imageForm.setFormType(1); imageFormResources.getCOSObject().setDirect(true); COSName imageFormName = COSName.getPDFName("n2"); innerFormResource.put(imageFormName, imageForm); COSName imageName = imageFormResources.add(img, "img"); pdfStructure.setImageForm(imageForm); pdfStructure.setImageFormName(imageFormName); pdfStructure.setImageName(imageName); LOG.info("Created image form"); }
private void assignAcroFormDefaultResource(PDAcroForm acroForm, COSDictionary newDict) { // read and set/update AcroForm default resource dictionary /DR if available COSBase newBase = newDict.getDictionaryObject(COSName.DR); if (newBase instanceof COSDictionary) { COSDictionary newDR = (COSDictionary) newBase; PDResources defaultResources = acroForm.getDefaultResources(); if (defaultResources == null) { acroForm.getCOSObject().setItem(COSName.DR, newDR); newDR.setDirect(true); newDR.setNeedToBeUpdated(true); } else { COSDictionary oldDR = defaultResources.getCOSObject(); COSBase newXObjectBase = newDR.getItem(COSName.XOBJECT); COSBase oldXObjectBase = oldDR.getItem(COSName.XOBJECT); if (newXObjectBase instanceof COSDictionary && oldXObjectBase instanceof COSDictionary) { ((COSDictionary) oldXObjectBase).addAll((COSDictionary) newXObjectBase); oldDR.setNeedToBeUpdated(true); } } } }
@Override public void injectProcSetArray(PDFormXObject innerForm, PDPage page, PDResources innerFormResources, PDResources imageFormResources, PDResources holderFormResources, COSArray procSet) { innerForm.getResources().getCOSObject().setItem(COSName.PROC_SET, procSet); page.getCOSObject().setItem(COSName.PROC_SET, procSet); innerFormResources.getCOSObject().setItem(COSName.PROC_SET, procSet); imageFormResources.getCOSObject().setItem(COSName.PROC_SET, procSet); holderFormResources.getCOSObject().setItem(COSName.PROC_SET, procSet); LOG.info("Inserted ProcSet to PDF"); }
@Override public void injectProcSetArray(PDFormXObject innerForm, PDPage page, PDResources innerFormResources, PDResources imageFormResources, PDResources holderFormResources, COSArray procSet) { innerForm.getResources().getCOSObject().setItem(COSName.PROC_SET, procSet); page.getCOSObject().setItem(COSName.PROC_SET, procSet); innerFormResources.getCOSObject().setItem(COSName.PROC_SET, procSet); imageFormResources.getCOSObject().setItem(COSName.PROC_SET, procSet); holderFormResources.getCOSObject().setItem(COSName.PROC_SET, procSet); LOG.info("Inserted ProcSet to PDF"); }
/** * Check that fonts present in the Resources dictionary match with PDF/A-1 rules * * @param context * @param resources * @throws ValidationException */ protected void validateFonts(PreflightContext context, PDResources resources) throws ValidationException { Map<String, PDFont> mapOfFonts = getFonts(resources.getCOSObject(), context); for (Entry<String, PDFont> entry : mapOfFonts.entrySet()) { ContextHelper.validateElement(context, entry.getValue(), FONT_PROCESS); } }
@Override public void createWidgetDictionary(PDSignatureField signatureField, PDResources holderFormResources) throws IOException { COSDictionary widgetDict = signatureField.getWidgets().get(0).getCOSObject(); widgetDict.setNeedToBeUpdated(true); widgetDict.setItem(COSName.DR, holderFormResources.getCOSObject()); pdfStructure.setWidgetDictionary(widgetDict); LOG.info("WidgetDictionary has been created"); }
@Override public void createWidgetDictionary(PDSignatureField signatureField, PDResources holderFormResources) throws IOException { COSDictionary widgetDict = signatureField.getWidgets().get(0).getCOSObject(); widgetDict.setNeedToBeUpdated(true); widgetDict.setItem(COSName.DR, holderFormResources.getCOSObject()); pdfStructure.setWidgetDictionary(widgetDict); LOG.info("WidgetDictionary has been created"); }
private static PDResources getResources(PDInheritableResources resources) { PDResources currRes = resources.getCurrentResources(); COSDictionary dictionary = resources.getInheritedResources().getCOSObject(); PDResources pageRes = new PDResources(new COSDictionary(dictionary)); for (COSName name : currRes.getColorSpaceNames()) { try { pageRes.put(name, currRes.getColorSpace(name)); } catch (IOException e) { LOGGER.debug("Problem with color space coping.", e); } } return pageRes; }
private static void parseResources(PDResources resources) { if (resources != null && !isKeyVisited(resources.getCOSObject().getKey())) { parseResourcesXObjects(resources); parseResourcesExtGState(resources); parseResourcesPatterns(resources); parseResourcesFonts(resources); } }
private LayoutPage getLayoutPage(PDDocument doc) throws IOException { PDPage page = doc.getPage(0); COSBase contents = page.getCOSObject().getDictionaryObject(COSName.CONTENTS); PDResources resources = page.getResources(); if (resources == null) { resources = new PDResources(); } return new LayoutPage(page.getMediaBox(), createCombinedContentStream(contents), resources.getCOSObject()); }
private LayoutPage getLayoutPage(PDDocument doc) throws IOException { PDPage page = doc.getPage(0); COSBase contents = page.getCOSObject().getDictionaryObject(COSName.CONTENTS); PDResources resources = page.getResources(); if (resources == null) { resources = new PDResources(); } return new LayoutPage(page.getMediaBox(), createContentStream(contents), resources.getCOSObject()); }