📄 pdfformfield.java
字号:
*/ public PdfFormField getParent() { return parent; } public void addKid(PdfFormField field) { field.parent = this; if (kids == null) kids = new ArrayList(); kids.add(field); } ArrayList getKids() { return kids; } public int setFieldFlags(int flags) { PdfNumber obj = (PdfNumber)get(PdfName.FF); int old; if (obj == null) old = 0; else old = obj.intValue(); int v = old | flags; put(PdfName.FF, new PdfNumber(v)); return old; } public void setValueAsStringUnicode(String s) { put(PdfName.V, new PdfString(s, PdfObject.TEXT_UNICODE)); } public void setValueAsString(String s) { put(PdfName.V, new PdfString(s)); } public void setValueAsName(String s) { put(PdfName.V, new PdfName(s)); } public void setValue(PdfSignature sig) { put(PdfName.V, sig); } public void setDefaultValueAsString(String s) { put(PdfName.DV, new PdfString(s)); } public void setDefaultValueAsStringUnicode(String s) { put(PdfName.DV, new PdfString(s, PdfObject.TEXT_UNICODE)); } public void setDefaultValueAsName(String s) { put(PdfName.DV, new PdfName(s)); } public void setFieldName(String s) { put(PdfName.T, new PdfString(s)); } public void setUserName(String s) { put(PdfName.TU, new PdfString(s)); } public void setMappingName(String s) { put(PdfName.TM, new PdfString(s)); } public void setQuadding(int v) { put(PdfName.Q, new PdfNumber(v)); } static void mergeResources(PdfDictionary result, PdfDictionary source) { PdfDictionary dic = null; PdfDictionary res = null; PdfName target = null; for (int k = 0; k < mergeTarget.length; ++k) { target = mergeTarget[k]; if ((dic = (PdfDictionary)source.get(target)) != null) { if ((res = (PdfDictionary)result.get(target)) == null) { res = new PdfDictionary(); } res.merge(dic); result.put(target, res); } } } void setUsed() { used = true; if (parent != null) put(PdfName.PARENT, parent.getIndirectReference()); if (kids != null) { PdfArray array = new PdfArray(); for (int k = 0; k < kids.size(); ++k) array.add(((PdfFormField)kids.get(k)).getIndirectReference()); put(PdfName.KIDS, array); } if (templates == null) return; PdfDictionary dic = new PdfDictionary(); for (Iterator it = templates.keySet().iterator(); it.hasNext();) { PdfTemplate template = (PdfTemplate)it.next(); mergeResources(dic, (PdfDictionary)template.getResources()); } put(PdfName.DR, dic); } PdfDictionary getMK() { PdfDictionary mk = (PdfDictionary)get(PdfName.MK); if (mk == null) { mk = new PdfDictionary(); put(PdfName.MK, mk); } return mk; } public void setMKRotation(int rotation) { getMK().put(PdfName.R, new PdfNumber(rotation)); } PdfArray getMKColor(Color color) { PdfArray array = new PdfArray(); int type = ExtendedColor.getType(color); switch (type) { case ExtendedColor.TYPE_GRAY: { array.add(new PdfNumber(((GrayColor)color).getGray())); break; } case ExtendedColor.TYPE_CMYK: { CMYKColor cmyk = (CMYKColor)color; array.add(new PdfNumber(cmyk.getCyan())); array.add(new PdfNumber(cmyk.getMagenta())); array.add(new PdfNumber(cmyk.getYellow())); array.add(new PdfNumber(cmyk.getBlack())); break; } case ExtendedColor.TYPE_SEPARATION: case ExtendedColor.TYPE_PATTERN: case ExtendedColor.TYPE_SHADING: throw new RuntimeException("Separations, patterns and shadings are not allowed in MK dictionary."); default: array.add(new PdfNumber(color.getRed() / 255f)); array.add(new PdfNumber(color.getGreen() / 255f)); array.add(new PdfNumber(color.getBlue() / 255f)); } return array; } public void setMKBorderColor(Color color) { if (color == null) getMK().remove(PdfName.BC); else getMK().put(PdfName.BC, getMKColor(color)); } public void setMKBackgroundColor(Color color) { if (color == null) getMK().remove(PdfName.BG); else getMK().put(PdfName.BG, getMKColor(color)); } public void setMKNormalCaption(String caption) { getMK().put(PdfName.CA, new PdfString(caption)); } public void setMKRolloverCaption(String caption) { getMK().put(PdfName.RC, new PdfString(caption)); } public void setMKAlternateCaption(String caption) { getMK().put(PdfName.AC, new PdfString(caption)); } public void setMKNormalCaptionUnicode(String caption) { getMK().put(PdfName.CA, new PdfString(caption, PdfObject.TEXT_UNICODE)); } public void setMKRolloverCaptionUnicode(String caption) { getMK().put(PdfName.RC, new PdfString(caption, PdfObject.TEXT_UNICODE)); } public void setMKAlternateCaptionUnicode(String caption) { getMK().put(PdfName.AC, new PdfString(caption, PdfObject.TEXT_UNICODE)); } public void setMKNormalIcon(PdfTemplate template) { getMK().put(PdfName.I, template.getIndirectReference()); } public void setMKRolloverIcon(PdfTemplate template) { getMK().put(PdfName.RI, template.getIndirectReference()); } public void setMKAlternateIcon(PdfTemplate template) { getMK().put(PdfName.IX, template.getIndirectReference()); } public void setMKIconFit(PdfName scale, PdfName scalingType, float leftoverLeft, float leftoverBottom) { PdfDictionary dic = new PdfDictionary(); if (!scale.equals(PdfName.A)) dic.put(PdfName.SW, scale); if (!scalingType.equals(PdfName.P)) dic.put(PdfName.S, scalingType); if (leftoverLeft != 0.5f || leftoverBottom != 0.5f) { PdfArray array = new PdfArray(new PdfNumber(leftoverLeft)); array.add(new PdfNumber(leftoverBottom)); dic.put(PdfName.A, array); } getMK().put(PdfName.IF, dic); } public void setMKTextPosition(int tp) { getMK().put(PdfName.TP, new PdfNumber(tp)); } public static PdfAnnotation shallowDuplicate(PdfAnnotation annot) { PdfAnnotation dup; if (annot.isForm()) { dup = new PdfFormField(annot.writer); PdfFormField dupField = (PdfFormField)dup; PdfFormField srcField = (PdfFormField)annot; dupField.parent = srcField.parent; dupField.kids = srcField.kids; } else dup = new PdfAnnotation(annot.writer, null); dup.merge(annot); dup.form = annot.form; dup.annotation = annot.annotation; dup.templates = annot.templates; return dup; }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -