/** * Gets the array of predefined procedure set names (see ISO-320001 Paragraph 14.2). * Deprecated in PDF 2.0. * * @return the array of predefined procedure set names. */ public PdfArray getProcSet() { return getPdfObject().getAsArray(PdfName.ProcSet); }
/** * Creates form XObject from page content. * The page shall be from the document, to which FormXObject will be added. * * @param page an instance of {@link PdfPage} */ public PdfFormXObject(PdfPage page) { this(page.getCropBox()); getPdfObject().getOutputStream().writeBytes(page.getContentBytes()); resources = new PdfResources((PdfDictionary) page.getResources().getPdfObject().clone()); getPdfObject().put(PdfName.Resources, resources.getPdfObject()); }
@Override public PdfName addFont(PdfDocument pdfDocument, PdfFont font) { PdfName fontName = null; if (font != null && font.getPdfObject().getIndirectReference() != null) { fontName = drFonts.get(font.getPdfObject().getIndirectReference()); } if (fontName != null) { addResource(font.getPdfObject(), PdfName.Font, fontName); return fontName; } else { return super.addFont(pdfDocument, font); } } }
/** * Gets the names of all the added resources. * * @return the name of all the added resources. */ public Set<PdfName> getResourceNames() { Set<PdfName> names = new TreeSet<>(); // TODO: isn't it better to use HashSet? Do we really need certain order? for (PdfName resType : getPdfObject().keySet()) { names.addAll(getResourceNames(resType)); } return names; }
protected void addResource(PdfObject resource, PdfName resType, PdfName resName) { if (resType.equals(PdfName.XObject)) { checkAndResolveCircularReferences(resource); } if (readOnly) { setPdfObject(getPdfObject().clone(Collections.<PdfName>emptyList())); buildResources(getPdfObject()); isModified = true; readOnly = false; } if (getPdfObject().containsKey(resType) && getPdfObject().getAsDictionary(resType).containsKey(resName)) return; resourceToName.put(resource, resName); PdfDictionary resourceCategory = getPdfObject().getAsDictionary(resType); if (resourceCategory == null) { getPdfObject().put(resType, resourceCategory = new PdfDictionary()); } resourceCategory.put(resName, resource); }
PdfImageXObject imgXObj = new PdfImageXObject(img); canvas.addXObject(imgXObj, width - borderWidth, 0, 0, height - borderWidth, borderWidth / 2, borderWidth / 2); xObject.getResources().addImage(imgXObj); } else if (form != null) { canvas.addXObject(form, (height - borderWidth) / form.getHeight(), 0, 0, (height - borderWidth) / form.getHeight(), borderWidth / 2, borderWidth / 2); xObject.getResources().addForm(form); } else { drawButton(canvas, 0, 0, width, height, text, font, fontSize); xObject.addFontFromDR(fontName, font); setDefaultAppearance(generateDefaultAppearanceString(font, fontSize, color, resources)); xObject.getResources().addFont(getDocument(), font);
public PdfResources getResources() { if (this.resources == null) { PdfDictionary resourcesDict = getPdfObject().getAsDictionary(PdfName.Resources); if (resourcesDict == null) { resourcesDict = new PdfDictionary(); getPdfObject().put(PdfName.Resources, resourcesDict); } this.resources = new PdfResources(resourcesDict); } return resources; }
PdfCanvas canvasOn = new PdfCanvas(streamOn, new PdfResources(), getDocument()); PdfFormXObject xObjectOn = new PdfFormXObject(rect); drawBorder(canvasOn, xObjectOn, width, height); drawCheckBox(canvasOn, width, height, fontSize, true); xObjectOn.getPdfObject().getOutputStream().writeBytes(streamOn.getBytes()); xObjectOn.getResources().addFont(getDocument(), getFont()); PdfCanvas canvasOff = new PdfCanvas(streamOff, new PdfResources(), getDocument()); PdfFormXObject xObjectOff = new PdfFormXObject(rect); drawBorder(canvasOff, xObjectOff, width, height); drawCheckBox(canvasOff, width, height, fontSize, false); xObjectOff.getPdfObject().getOutputStream().writeBytes(streamOff.getBytes()); xObjectOff.getResources().addFont(getDocument(), getFont());
if (resources != null && resources.isModified() && !resources.isReadOnly()) { getPdfObject().put(PdfName.Resources, resources.getPdfObject());
/** * Adds {@code PdfFormXObject} to canvas. * * @param form the {@code PdfImageXObject} object * @param a an element of the transformation matrix * @param b an element of the transformation matrix * @param c an element of the transformation matrix * @param d an element of the transformation matrix * @param e an element of the transformation matrix * @param f an element of the transformation matrix * @return current canvas. */ private PdfCanvas addForm(PdfFormXObject form, float a, float b, float c, float d, float e, float f) { saveState(); concatMatrix(a, b, c, d, e, f); PdfName name = resources.addForm(form); contentStream.getOutputStream().write(name).writeSpace().writeBytes(Do); restoreState(); return this; }
put(PdfName.Resources, resources); this.resources = new PdfResources(resources); this.resources.setReadOnly(readOnly);
private PdfCanvas addImage(PdfXObject xObject, float a, float b, float c, float d, float e, float f) { saveState(); concatMatrix(a, b, c, d, e, f); PdfName name = resources.addImage(xObject.getPdfObject()); contentStream.getOutputStream().write(name).writeSpace().writeBytes(Do); restoreState(); return this; }
contentStream.getOutputStream().writeFloats(colorValue).writeSpace().writeBytes(fill ? k : K); else if (colorSpace instanceof PdfSpecialCs.UncoloredTilingPattern) contentStream.getOutputStream().write(resources.addColorSpace(colorSpace)).writeSpace().writeBytes(fill ? cs : CS). writeNewLine().writeFloats(colorValue).writeSpace().write(resources.addPattern(pattern)).writeSpace().writeBytes(fill ? scn : SCN); else if (colorSpace instanceof PdfSpecialCs.Pattern) contentStream.getOutputStream().write(PdfName.Pattern).writeSpace().writeBytes(fill ? cs : CS). writeNewLine().write(resources.addPattern(pattern)).writeSpace().writeBytes(fill ? scn : SCN); else if (colorSpace.getPdfObject().isIndirect()) { if (!setColorValueOnly) { PdfName name = resources.addColorSpace(colorSpace); contentStream.getOutputStream().write(name).writeSpace().writeBytes(fill ? cs : CS);
private void addToPropertiesAndBeginLayer(IPdfOCG layer) { PdfName name = resources.addProperties(layer.getPdfObject()); contentStream.getOutputStream().write(PdfName.OC).writeSpace() .write(name).writeSpace().writeBytes(BDC).writeNewLine(); }
/** * Sets the ExtGState dictionary for the current graphics state * * @param extGState a dictionary that maps resource names to graphics state parameter dictionaries * @return current canvas. */ public PdfCanvas setExtGState(PdfExtGState extGState) { if (!extGState.isFlushed()) currentGs.updateFromExtGState(extGState, document); PdfName name = resources.addExtGState(extGState); contentStream.getOutputStream().write(name).writeSpace().writeBytes(gs); document.checkIsoConformance(currentGs, IsoKey.EXTENDED_GRAPHICS_STATE); return this; }
PdfImageXObject imgXObj = new PdfImageXObject(img); canvas.addXObject(imgXObj, width - borderWidth, 0, 0, height - borderWidth, borderWidth / 2, borderWidth / 2); xObject.getResources().addImage(imgXObj); } else if (form != null) { canvas.addXObject(form, (height - borderWidth) / form.getHeight(), 0, 0, (height - borderWidth) / form.getHeight(), borderWidth / 2, borderWidth / 2); xObject.getResources().addForm(form); } else { drawButton(canvas, 0, 0, width, height, text, font, fontSize); xObject.addFontFromDR(fontName, font); setDefaultAppearance(generateDefaultAppearanceString(font, fontSize, color, resources)); xObject.getResources().addFont(getDocument(), font);
/** * Gets {@link PdfResources} of the Form XObject. * Note, if there is no resources, a new instance will be created. * * @return not null instance of {@link PdfResources}. */ public PdfResources getResources() { if (this.resources == null) { PdfDictionary resourcesDict = getPdfObject().getAsDictionary(PdfName.Resources); if (resourcesDict == null) { resourcesDict = new PdfDictionary(); getPdfObject().put(PdfName.Resources, resourcesDict); } this.resources = new PdfResources(resourcesDict); } return resources; }
PdfCanvas canvasOn = new PdfCanvas(streamOn, new PdfResources(), getDocument()); PdfFormXObject xObjectOn = new PdfFormXObject(rect); drawBorder(canvasOn, xObjectOn, width, height); drawCheckBox(canvasOn, width, height, fontSize, true); xObjectOn.getPdfObject().getOutputStream().writeBytes(streamOn.getBytes()); xObjectOn.getResources().addFont(getDocument(), getFont()); PdfCanvas canvasOff = new PdfCanvas(streamOff, new PdfResources(), getDocument()); PdfFormXObject xObjectOff = new PdfFormXObject(rect); drawBorder(canvasOff, xObjectOff, width, height); drawCheckBox(canvasOff, width, height, fontSize, false); xObjectOff.getPdfObject().getOutputStream().writeBytes(streamOff.getBytes()); xObjectOff.getResources().addFont(getDocument(), getFont());
topLayer.getResources().addForm(xobj, new PdfName("n0")); PdfCanvas canvas1 = new PdfCanvas(topLayer, document); canvas1.addXObject(xobj, 1, 0, 0, 1, 0, 0); topLayer.getResources().addForm(n0, new PdfName("n0")); PdfCanvas canvas1 = new PdfCanvas(topLayer, document); canvas1.addXObject(n0, 1, 0, 0, 1, 0, 0); topLayer.getResources().addForm(n2, new PdfName("n2")); PdfCanvas canvas1 = new PdfCanvas(topLayer, document); canvas1.addXObject(n2, 1, 0, 0, 1, 0, 0); napp.getResources().addForm(topLayer, new PdfName("FRM"));
/** * Adds {@code PdfImageXObject} to canvas. * * @param image the {@code PdfImageXObject} object * @param a an element of the transformation matrix * @param b an element of the transformation matrix * @param c an element of the transformation matrix * @param d an element of the transformation matrix * @param e an element of the transformation matrix * @param f an element of the transformation matrix * @return canvas a reference to this object. */ private PdfCanvas addImage(PdfImageXObject image, float a, float b, float c, float d, float e, float f) { saveState(); concatMatrix(a, b, c, d, e, f); PdfName name = resources.addImage(image); contentStream.getOutputStream().write(name).writeSpace().writeBytes(Do); restoreState(); return this; }