/** * Sets the value of the collection item. * @param value */ public void AddItem(String key, PdfNumber n) { PdfName fieldname = new PdfName(key); PdfCollectionField field = (PdfCollectionField)schema.Get(fieldname); if (field.fieldType == PdfCollectionField.NUMBER) { Put(fieldname, n); } }
virtual public void CopyStructTreeForPage(PdfNumber sourceArrayNumber, int newArrayNumber) { // int documentHash = GetDocumentHash(reader); // if (!openedDocuments.ContainsKey(documentHash)) // { // openedDocuments.Add(documentHash, null); // AddKid(structureTreeRoot, writer.CopyObject(structTreeRoot.Get(PdfName.K), true, true)); // } if (CopyPageMarks(parentTree, sourceArrayNumber, newArrayNumber) == ReturnType.NOTFOUND) { throw new BadPdfFormatException(MessageLocalization.GetComposedMessage("structparent.not.found")); } }
/** * Creates a PdfPattern object. * @param painter a pattern painter instance * @param compressionLevel the compressionLevel for the stream * @since 2.1.3 */ internal PdfPattern(PdfPatternPainter painter, int compressionLevel) : base() { PdfNumber one = new PdfNumber(1); PdfArray matrix = painter.Matrix; if ( matrix != null ) { Put(PdfName.MATRIX, matrix); } Put(PdfName.TYPE, PdfName.PATTERN); Put(PdfName.BBOX, new PdfRectangle(painter.BoundingBox)); Put(PdfName.RESOURCES, painter.Resources); Put(PdfName.TILINGTYPE, one); Put(PdfName.PATTERNTYPE, one); if (painter.IsStencil()) Put(PdfName.PAINTTYPE, new PdfNumber(2)); else Put(PdfName.PAINTTYPE, one); Put(PdfName.XSTEP, new PdfNumber(painter.XStep)); Put(PdfName.YSTEP, new PdfNumber(painter.YStep)); bytes = painter.ToPdf(null); Put(PdfName.LENGTH, new PdfNumber(bytes.Length)); FlateCompress(compressionLevel); }
private ReturnType CopyPageMarks(PdfDictionary parentTree, PdfNumber arrayNumber, int newArrayNumber) { PdfArray pages = (PdfArray)GetDirectObject(parentTree.Get(PdfName.NUMS)); if (pages == null) { PdfArray kids = (PdfArray)GetDirectObject(parentTree.Get(PdfName.KIDS)); if (kids == null) return ReturnType.NOTFOUND; int cur = kids.Size/2; int begin = 0; while (true) { PdfDictionary kidTree = (PdfDictionary)GetDirectObject(kids[cur + begin]); switch (CopyPageMarks(kidTree,arrayNumber,newArrayNumber)) { case ReturnType.FOUND: return ReturnType.FOUND; case ReturnType.ABOVE: begin += cur; cur /= 2; if (cur == 0) cur = 1; if (cur + begin == kids.Size) return ReturnType.ABOVE; break; case ReturnType.BELOW: if (cur + begin == 0) return ReturnType.BELOW; if (cur == 0) return ReturnType.NOTFOUND; cur /= 2; break; default: return ReturnType.NOTFOUND; } } } else { if (pages.Size == 0) return ReturnType.NOTFOUND; return FindAndCopyMarks(pages, arrayNumber.IntValue, newArrayNumber); } }
public void CopyStructTreeForPage(PdfNumber sourceArrayNumber, int newArrayNumber) { if (!openedDocuments[fileName]) { PdfObject res = writer.CopyObject(writer.CopyObject(structTreeRoot.Get(PdfName.K), true, true)); if (!(res is PdfIndirectReference)) res = writer.AddToBody(res).IndirectReference; structureTreeRoot.AddPageMark(newArrayNumber, (PdfIndirectReference)res); AddKid(structureTreeRoot, res); openedDocuments.Add(fileName, true); } if (CopyPageMarks(parentTree, sourceArrayNumber, newArrayNumber) == returnType.NOTFOUND) { throw new BadPdfFormatException(MessageLocalization.GetComposedMessage("structparent.not.found")); } }
PdfObject GetColorspace() { if (icc_profile != null) { if ((colorType & 2) == 0) return PdfName.DEVICEGRAY; else return PdfName.DEVICERGB; } if (gamma == 1f && !hasCHRM) { if ((colorType & 2) == 0) return PdfName.DEVICEGRAY; else return PdfName.DEVICERGB; } else { PdfArray array = new PdfArray(); PdfDictionary dic = new PdfDictionary(); if ((colorType & 2) == 0) { if (gamma == 1f) return PdfName.DEVICEGRAY; array.Add(PdfName.CALGRAY); dic.Put(PdfName.GAMMA, new PdfNumber(gamma)); dic.Put(PdfName.WHITEPOINT, new PdfLiteral("[1 1 1]")); array.Add(dic); } else { PdfObject wp = new PdfLiteral("[1 1 1]"); array.Add(PdfName.CALRGB); if (gamma != 1f) { PdfArray gm = new PdfArray(); PdfNumber n = new PdfNumber(gamma); gm.Add(n); gm.Add(n); gm.Add(n); dic.Put(PdfName.GAMMA, gm); } if (hasCHRM) { float z = yW*((xG-xB)*yR-(xR-xB)*yG+(xR-xG)*yB); float YA = yR*((xG-xB)*yW-(xW-xB)*yG+(xW-xG)*yB)/z; float XA = YA*xR/yR; float ZA = YA*((1-xR)/yR-1); float YB = -yG*((xR-xB)*yW-(xW-xB)*yR+(xW-xR)*yB)/z; float XB = YB*xG/yG; float ZB = YB*((1-xG)/yG-1); float YC = yB*((xR-xG)*yW-(xW-xG)*yW+(xW-xR)*yG)/z; float XC = YC*xB/yB; float ZC = YC*((1-xB)/yB-1); float XW = XA+XB+XC; float YW = 1;//YA+YB+YC; float ZW = ZA+ZB+ZC; PdfArray wpa = new PdfArray(); wpa.Add(new PdfNumber(XW)); wpa.Add(new PdfNumber(YW)); wpa.Add(new PdfNumber(ZW)); wp = wpa; PdfArray matrix = new PdfArray(); matrix.Add(new PdfNumber(XA)); matrix.Add(new PdfNumber(YA)); matrix.Add(new PdfNumber(ZA)); matrix.Add(new PdfNumber(XB)); matrix.Add(new PdfNumber(YB)); matrix.Add(new PdfNumber(ZB)); matrix.Add(new PdfNumber(XC)); matrix.Add(new PdfNumber(YC)); matrix.Add(new PdfNumber(ZC)); dic.Put(PdfName.MATRIX, matrix); } dic.Put(PdfName.WHITEPOINT, wp); array.Add(dic); } return array; } }
/** * Gets the button appearance. * @throws IOException on error * @throws DocumentException on error * @return the button appearance */ public PdfAppearance GetAppearance() { PdfAppearance app = GetBorderAppearance(); Rectangle box = new Rectangle(app.BoundingBox); if ((text == null || text.Length == 0) && (layout == LAYOUT_LABEL_ONLY || (image == null && template == null && iconReference == null))) { return(app); } if (layout == LAYOUT_ICON_ONLY && image == null && template == null && iconReference == null) { return(app); } BaseFont ufont = RealFont; bool borderExtra = borderStyle == PdfBorderDictionary.STYLE_BEVELED || borderStyle == PdfBorderDictionary.STYLE_INSET; float h = box.Height - borderWidth * 2; float bw2 = borderWidth; if (borderExtra) { h -= borderWidth * 2; bw2 *= 2; } float offsetX = (borderExtra ? 2 * borderWidth : borderWidth); offsetX = Math.Max(offsetX, 1); float offX = Math.Min(bw2, offsetX); tp = null; float textX = float.NaN; float textY = 0; float fsize = fontSize; float wt = box.Width - 2 * offX - 2; float ht = box.Height - 2 * offX; float adj = (iconFitToBounds ? 0 : offX + 1); int nlayout = layout; if (image == null && template == null && iconReference == null) { nlayout = LAYOUT_LABEL_ONLY; } Rectangle iconBox = null; while (true) { switch (nlayout) { case LAYOUT_LABEL_ONLY: case LAYOUT_LABEL_OVER_ICON: if (text != null && text.Length > 0 && wt > 0 && ht > 0) { fsize = CalculateFontSize(wt, ht); textX = (box.Width - ufont.GetWidthPoint(text, fsize)) / 2; textY = (box.Height - ufont.GetFontDescriptor(BaseFont.ASCENT, fsize)) / 2; } goto case LAYOUT_ICON_ONLY; case LAYOUT_ICON_ONLY: if (nlayout == LAYOUT_LABEL_OVER_ICON || nlayout == LAYOUT_ICON_ONLY) { iconBox = new Rectangle(box.Left + adj, box.Bottom + adj, box.Right - adj, box.Top - adj); } break; case LAYOUT_ICON_TOP_LABEL_BOTTOM: if (text == null || text.Length == 0 || wt <= 0 || ht <= 0) { nlayout = LAYOUT_ICON_ONLY; continue; } float nht = box.Height * 0.35f - offX; if (nht > 0) { fsize = CalculateFontSize(wt, nht); } else { fsize = 4; } textX = (box.Width - ufont.GetWidthPoint(text, fsize)) / 2; textY = offX - ufont.GetFontDescriptor(BaseFont.DESCENT, fsize); iconBox = new Rectangle(box.Left + adj, textY + fsize, box.Right - adj, box.Top - adj); break; case LAYOUT_LABEL_TOP_ICON_BOTTOM: if (text == null || text.Length == 0 || wt <= 0 || ht <= 0) { nlayout = LAYOUT_ICON_ONLY; continue; } nht = box.Height * 0.35f - offX; if (nht > 0) { fsize = CalculateFontSize(wt, nht); } else { fsize = 4; } textX = (box.Width - ufont.GetWidthPoint(text, fsize)) / 2; textY = box.Height - offX - fsize; if (textY < offX) { textY = offX; } iconBox = new Rectangle(box.Left + adj, box.Bottom + adj, box.Right - adj, textY + ufont.GetFontDescriptor(BaseFont.DESCENT, fsize)); break; case LAYOUT_LABEL_LEFT_ICON_RIGHT: if (text == null || text.Length == 0 || wt <= 0 || ht <= 0) { nlayout = LAYOUT_ICON_ONLY; continue; } float nw = box.Width * 0.35f - offX; if (nw > 0) { fsize = CalculateFontSize(wt, nw); } else { fsize = 4; } if (ufont.GetWidthPoint(text, fsize) >= wt) { nlayout = LAYOUT_LABEL_ONLY; fsize = fontSize; continue; } textX = offX + 1; textY = (box.Height - ufont.GetFontDescriptor(BaseFont.ASCENT, fsize)) / 2; iconBox = new Rectangle(textX + ufont.GetWidthPoint(text, fsize), box.Bottom + adj, box.Right - adj, box.Top - adj); break; case LAYOUT_ICON_LEFT_LABEL_RIGHT: if (text == null || text.Length == 0 || wt <= 0 || ht <= 0) { nlayout = LAYOUT_ICON_ONLY; continue; } nw = box.Width * 0.35f - offX; if (nw > 0) { fsize = CalculateFontSize(wt, nw); } else { fsize = 4; } if (ufont.GetWidthPoint(text, fsize) >= wt) { nlayout = LAYOUT_LABEL_ONLY; fsize = fontSize; continue; } textX = box.Width - ufont.GetWidthPoint(text, fsize) - offX - 1; textY = (box.Height - ufont.GetFontDescriptor(BaseFont.ASCENT, fsize)) / 2; iconBox = new Rectangle(box.Left + adj, box.Bottom + adj, textX - 1, box.Top - adj); break; } break; } if (textY < box.Bottom + offX) { textY = box.Bottom + offX; } if (iconBox != null && (iconBox.Width <= 0 || iconBox.Height <= 0)) { iconBox = null; } bool haveIcon = false; float boundingBoxWidth = 0; float boundingBoxHeight = 0; PdfArray matrix = null; if (iconBox != null) { if (image != null) { tp = new PdfTemplate(writer); tp.BoundingBox = new Rectangle(image); writer.AddDirectTemplateSimple(tp, PdfName.FRM); tp.AddImage(image, image.Width, 0, 0, image.Height, 0, 0); haveIcon = true; boundingBoxWidth = tp.BoundingBox.Width; boundingBoxHeight = tp.BoundingBox.Height; } else if (template != null) { tp = new PdfTemplate(writer); tp.BoundingBox = new Rectangle(template.Width, template.Height); writer.AddDirectTemplateSimple(tp, PdfName.FRM); tp.AddTemplate(template, template.BoundingBox.Left, template.BoundingBox.Bottom); haveIcon = true; boundingBoxWidth = tp.BoundingBox.Width; boundingBoxHeight = tp.BoundingBox.Height; } else if (iconReference != null) { PdfDictionary dic = (PdfDictionary)PdfReader.GetPdfObject(iconReference); if (dic != null) { Rectangle r2 = PdfReader.GetNormalizedRectangle(dic.GetAsArray(PdfName.BBOX)); matrix = dic.GetAsArray(PdfName.MATRIX); haveIcon = true; boundingBoxWidth = r2.Width; boundingBoxHeight = r2.Height; } } } if (haveIcon) { float icx = iconBox.Width / boundingBoxWidth; float icy = iconBox.Height / boundingBoxHeight; if (proportionalIcon) { switch (scaleIcon) { case SCALE_ICON_IS_TOO_BIG: icx = Math.Min(icx, icy); icx = Math.Min(icx, 1); break; case SCALE_ICON_IS_TOO_SMALL: icx = Math.Min(icx, icy); icx = Math.Max(icx, 1); break; case SCALE_ICON_NEVER: icx = 1; break; default: icx = Math.Min(icx, icy); break; } icy = icx; } else { switch (scaleIcon) { case SCALE_ICON_IS_TOO_BIG: icx = Math.Min(icx, 1); icy = Math.Min(icy, 1); break; case SCALE_ICON_IS_TOO_SMALL: icx = Math.Max(icx, 1); icy = Math.Max(icy, 1); break; case SCALE_ICON_NEVER: icx = icy = 1; break; default: break; } } float xpos = iconBox.Left + (iconBox.Width - (boundingBoxWidth * icx)) * iconHorizontalAdjustment; float ypos = iconBox.Bottom + (iconBox.Height - (boundingBoxHeight * icy)) * iconVerticalAdjustment; app.SaveState(); app.Rectangle(iconBox.Left, iconBox.Bottom, iconBox.Width, iconBox.Height); app.Clip(); app.NewPath(); if (tp != null) { app.AddTemplate(tp, icx, 0, 0, icy, xpos, ypos); } else { float cox = 0; float coy = 0; if (matrix != null && matrix.Size == 6) { PdfNumber nm = matrix.GetAsNumber(4); if (nm != null) { cox = nm.FloatValue; } nm = matrix.GetAsNumber(5); if (nm != null) { coy = nm.FloatValue; } } app.AddTemplateReference(iconReference, PdfName.FRM, icx, 0, 0, icy, xpos - cox * icx, ypos - coy * icy); } app.RestoreState(); } if (!float.IsNaN(textX)) { app.SaveState(); app.Rectangle(offX, offX, box.Width - 2 * offX, box.Height - 2 * offX); app.Clip(); app.NewPath(); if (textColor == null) { app.ResetGrayFill(); } else { app.SetColorFill(textColor); } app.BeginText(); app.SetFontAndSize(ufont, fsize); app.SetTextMatrix(textX, textY); app.ShowText(text); app.EndText(); app.RestoreState(); } return(app); }
private LockPermissions(int p) { number = new PdfNumber(p); }
/** * A positive integer that shall specify the precision or denominator of a * fractional amount: * <ul> * <li> * When the Fractional Value is {@link Fraction#DECIMAL}, this entry shall * be the precision of a decimal display; it shall be a multiple of 10. * Low-order zeros may be truncated unless FixedDenominator is true. Default * value: 100 (hundredths, corresponding to two decimal digits).</li> * <li>When the value of F is {@link Fraction#FRACTION}, this entry shall be * the denominator of a fractional display. The fraction may be reduced * unless the value of FD is true. Default value: 16.</li> * </ul> * * @param precision */ virtual public void SetPrecision(PdfNumber precision) { base.Put(PdfName.D, precision); }
/** Sets the field value and the display string. The display string * is used to build the appearance in the cases where the value * is modified by Acrobat with JavaScript and the algorithm is * known. * @param name the fully qualified field name or the partial name in the case of XFA forms * @param value the field value * @param display the string that is used for the appearance. If <CODE>null</CODE> * the <CODE>value</CODE> parameter will be used * @return <CODE>true</CODE> if the field was found and changed, * <CODE>false</CODE> otherwise * @throws IOException on error * @throws DocumentException on error */ public bool SetField(String name, String value, String display) { if (writer == null) throw new DocumentException("This AcroFields instance is read-only."); if (xfa.XfaPresent) { name = xfa.FindFieldName(name, this); if (name == null) return false; String shortName = XfaForm.Xml2Som.GetShortName(name); XmlNode xn = xfa.FindDatasetsNode(shortName); if (xn == null) { xn = xfa.DatasetsSom.InsertNode(xfa.DatasetsNode, shortName); } xfa.SetNodeText(xn, value); } Item item = (Item)fields[name]; if (item == null) return false; PdfDictionary merged = item.GetMerged( 0 ); PdfName type = merged.GetAsName(PdfName.FT); if (PdfName.TX.Equals(type)) { PdfNumber maxLen = merged.GetAsNumber(PdfName.MAXLEN); int len = 0; if (maxLen != null) len = maxLen.IntValue; if (len > 0) value = value.Substring(0, Math.Min(len, value.Length)); } if (display == null) display = value; if (PdfName.TX.Equals(type) || PdfName.CH.Equals(type)) { PdfString v = new PdfString(value, PdfObject.TEXT_UNICODE); for (int idx = 0; idx < item.Size; ++idx) { PdfDictionary valueDic = item.GetValue(idx); valueDic.Put(PdfName.V, v); valueDic.Remove(PdfName.I); MarkUsed(valueDic); merged = item.GetMerged(idx); merged.Remove(PdfName.I); merged.Put(PdfName.V, v); PdfDictionary widget = item.GetWidget(idx); if (generateAppearances) { PdfAppearance app = GetAppearance(merged, display, name); if (PdfName.CH.Equals(type)) { PdfNumber n = new PdfNumber(topFirst); widget.Put(PdfName.TI, n); merged.Put(PdfName.TI, n); } PdfDictionary appDic = widget.GetAsDict(PdfName.AP); if (appDic == null) { appDic = new PdfDictionary(); widget.Put(PdfName.AP, appDic); merged.Put(PdfName.AP, appDic); } appDic.Put(PdfName.N, app.IndirectReference); writer.ReleaseTemplate(app); } else { widget.Remove(PdfName.AP); merged.Remove(PdfName.AP); } MarkUsed(widget); } return true; } else if (PdfName.BTN.Equals(type)) { PdfNumber ff = item.GetMerged(0).GetAsNumber(PdfName.FF); int flags = 0; if (ff != null) flags = ff.IntValue; if ((flags & PdfFormField.FF_PUSHBUTTON) != 0) { //we'll assume that the value is an image in base64 Image img; try { img = Image.GetInstance(Convert.FromBase64String(value)); } catch { return false; } PushbuttonField pb = GetNewPushbuttonFromField(name); pb.Image = img; ReplacePushbuttonField(name, pb.Field); return true; } PdfName v = new PdfName(value); ArrayList lopt = new ArrayList(); PdfArray opts = item.GetValue(0).GetAsArray(PdfName.OPT); if (opts != null) { for (int k = 0; k < opts.Size; ++k) { PdfString valStr = opts.GetAsString(k); if (valStr != null) lopt.Add(valStr.ToUnicodeString()); else lopt.Add(null); } } int vidx = lopt.IndexOf(value); PdfName valt = null; PdfName vt; if (vidx >= 0) { vt = valt = new PdfName(vidx.ToString()); } else vt = v; for (int idx = 0; idx < item.Size; ++idx) { merged = item.GetMerged(idx); PdfDictionary widget = item.GetWidget(idx); PdfDictionary valDict = item.GetValue(idx); MarkUsed(item.GetValue(idx)); if (valt != null) { PdfString ps = new PdfString(value, PdfObject.TEXT_UNICODE); valDict.Put(PdfName.V, ps); merged.Put(PdfName.V, ps); } else { valDict.Put(PdfName.V, v); merged.Put(PdfName.V, v); } MarkUsed(widget); if (IsInAP(widget, vt)) { merged.Put(PdfName.AS, vt); widget.Put(PdfName.AS, vt); } else { merged.Put(PdfName.AS, PdfName.Off_); widget.Put(PdfName.AS, PdfName.Off_); } } return true; } return false; }
virtual protected internal PdfObject ReadOneObjStm (PRStream stream, int idx) { int first = stream.GetAsNumber(PdfName.FIRST).IntValue; byte[] b = GetStreamBytes(stream, tokens.File); PRTokeniser saveTokens = tokens; tokens = new PRTokeniser(new RandomAccessFileOrArray(new RandomAccessSourceFactory().CreateSource(b))); try { int address = 0; bool ok = true; ++idx; for (int k = 0; k < idx; ++k) { ok = tokens.NextToken(); if (!ok) break; if (tokens.TokenType != PRTokeniser.TokType.NUMBER) { ok = false; break; } ok = tokens.NextToken(); if (!ok) break; if (tokens.TokenType != PRTokeniser.TokType.NUMBER) { ok = false; break; } address = tokens.IntValue + first; } if (!ok) throw new InvalidPdfException(MessageLocalization.GetComposedMessage("error.reading.objstm")); tokens.Seek(address); tokens.NextToken(); PdfObject obj; if (tokens.TokenType == PRTokeniser.TokType.NUMBER) { obj = new PdfNumber(tokens.StringValue); } else { tokens.Seek(address); obj = ReadPRObject(); } return obj; } finally { tokens = saveTokens; } }
/** Sets the field value and the display string. The display string * is used to build the appearance in the cases where the value * is modified by Acrobat with JavaScript and the algorithm is * known. * @param name the fully qualified field name or the partial name in the case of XFA forms * @param value the field value * @param display the string that is used for the appearance. If <CODE>null</CODE> * the <CODE>value</CODE> parameter will be used * @return <CODE>true</CODE> if the field was found and changed, * <CODE>false</CODE> otherwise * @throws IOException on error * @throws DocumentException on error */ public bool SetField(String name, String value, String display) { if (writer == null) throw new DocumentException("This AcroFields instance is read-only."); if (xfa.XfaPresent) { name = xfa.FindFieldName(name, this); if (name == null) return false; String shortName = XfaForm.Xml2Som.GetShortName(name); xfa.SetNodeText(xfa.FindDatasetsNode(shortName), value); } Item item = (Item)fields[name]; if (item == null) return false; PdfName type = (PdfName)PdfReader.GetPdfObject(((PdfDictionary)item.merged[0]).Get(PdfName.FT)); if (PdfName.TX.Equals(type)) { PdfNumber maxLen = (PdfNumber)PdfReader.GetPdfObject(((PdfDictionary)item.merged[0]).Get(PdfName.MAXLEN)); int len = 0; if (maxLen != null) len = maxLen.IntValue; if (len > 0) value = value.Substring(0, Math.Min(len, value.Length)); } if (display == null) display = value; if (PdfName.TX.Equals(type) || PdfName.CH.Equals(type)) { PdfString v = new PdfString(value, PdfObject.TEXT_UNICODE); for (int idx = 0; idx < item.values.Count; ++idx) { PdfDictionary valueDic = (PdfDictionary)item.values[idx]; valueDic.Put(PdfName.V, v); valueDic.Remove(PdfName.I); MarkUsed(valueDic); PdfDictionary merged = (PdfDictionary)item.merged[idx]; merged.Remove(PdfName.I); merged.Put(PdfName.V, v); PdfDictionary widget = (PdfDictionary)item.widgets[idx]; if (generateAppearances) { PdfAppearance app = GetAppearance(merged, display, name); if (PdfName.CH.Equals(type)) { PdfNumber n = new PdfNumber(topFirst); widget.Put(PdfName.TI, n); merged.Put(PdfName.TI, n); } PdfDictionary appDic = (PdfDictionary)PdfReader.GetPdfObject(widget.Get(PdfName.AP)); if (appDic == null) { appDic = new PdfDictionary(); widget.Put(PdfName.AP, appDic); merged.Put(PdfName.AP, appDic); } appDic.Put(PdfName.N, app.IndirectReference); writer.ReleaseTemplate(app); } else { widget.Remove(PdfName.AP); merged.Remove(PdfName.AP); } MarkUsed(widget); } return true; } else if (PdfName.BTN.Equals(type)) { PdfNumber ff = (PdfNumber)PdfReader.GetPdfObject(((PdfDictionary)item.merged[0]).Get(PdfName.FF)); int flags = 0; if (ff != null) flags = ff.IntValue; if ((flags & PdfFormField.FF_PUSHBUTTON) != 0) return true; PdfName v = new PdfName(value); if ((flags & PdfFormField.FF_RADIO) == 0) { for (int idx = 0; idx < item.values.Count; ++idx) { ((PdfDictionary)item.values[idx]).Put(PdfName.V, v); MarkUsed((PdfDictionary)item.values[idx]); PdfDictionary merged = (PdfDictionary)item.merged[idx]; merged.Put(PdfName.V, v); merged.Put(PdfName.AS, v); PdfDictionary widget = (PdfDictionary)item.widgets[idx]; if (IsInAP(widget, v)) widget.Put(PdfName.AS, v); else widget.Put(PdfName.AS, PdfName.Off_); MarkUsed(widget); } } else { ArrayList lopt = new ArrayList(); PdfObject opts = PdfReader.GetPdfObject(((PdfDictionary)item.values[0]).Get(PdfName.OPT)); if (opts != null && opts.IsArray()) { ArrayList list = ((PdfArray)opts).ArrayList; for (int k = 0; k < list.Count; ++k) { PdfObject vv = PdfReader.GetPdfObject((PdfObject)list[k]); if (vv != null && vv.IsString()) lopt.Add(((PdfString)vv).ToUnicodeString()); else lopt.Add(null); } } int vidx = lopt.IndexOf(value); PdfName valt = null; PdfName vt; if (vidx >= 0) { vt = valt = new PdfName(vidx.ToString()); } else vt = v; for (int idx = 0; idx < item.values.Count; ++idx) { PdfDictionary merged = (PdfDictionary)item.merged[idx]; PdfDictionary widget = (PdfDictionary)item.widgets[idx]; MarkUsed((PdfDictionary)item.values[idx]); if (valt != null) { PdfString ps = new PdfString(value, PdfObject.TEXT_UNICODE); ((PdfDictionary)item.values[idx]).Put(PdfName.V, ps); merged.Put(PdfName.V, ps); } else { ((PdfDictionary)item.values[idx]).Put(PdfName.V, v); merged.Put(PdfName.V, v); } MarkUsed(widget); if (IsInAP(widget, vt)) { merged.Put(PdfName.AS, vt); widget.Put(PdfName.AS, vt); } else { merged.Put(PdfName.AS, PdfName.Off_); widget.Put(PdfName.AS, PdfName.Off_); } } } return true; } return false; }
/** * Sets a field property. Valid property names are: * <p> * <ul> * <li>flags - a set of flags specifying various characteristics of the field’s widget annotation. * The value of this entry replaces that of the F entry in the form’s corresponding annotation dictionary.<br> * <li>setflags - a set of flags to be set (turned on) in the F entry of the form’s corresponding * widget annotation dictionary. Bits equal to 1 cause the corresponding bits in F to be set to 1.<br> * <li>clrflags - a set of flags to be cleared (turned off) in the F entry of the form’s corresponding * widget annotation dictionary. Bits equal to 1 cause the corresponding * bits in F to be set to 0.<br> * <li>fflags - a set of flags specifying various characteristics of the field. The value * of this entry replaces that of the Ff entry in the form’s corresponding field dictionary.<br> * <li>setfflags - a set of flags to be set (turned on) in the Ff entry of the form’s corresponding * field dictionary. Bits equal to 1 cause the corresponding bits in Ff to be set to 1.<br> * <li>clrfflags - a set of flags to be cleared (turned off) in the Ff entry of the form’s corresponding * field dictionary. Bits equal to 1 cause the corresponding bits in Ff * to be set to 0.<br> * </ul> * @param field the field name * @param name the property name * @param value the property value * @param inst an array of <CODE>int</CODE> indexing into <CODE>AcroField.Item.merged</CODE> elements to process. * Set to <CODE>null</CODE> to process all * @return <CODE>true</CODE> if the property exists, <CODE>false</CODE> otherwise */ public bool SetFieldProperty(String field, String name, int value, int[] inst) { if (writer == null) throw new Exception("This AcroFields instance is read-only."); Item item = (Item)fields[field]; if (item == null) return false; InstHit hit = new InstHit(inst); if (Util.EqualsIgnoreCase(name, "flags")) { PdfNumber num = new PdfNumber(value); for (int k = 0; k < item.merged.Count; ++k) { if (hit.IsHit(k)) { ((PdfDictionary)item.merged[k]).Put(PdfName.F, num); ((PdfDictionary)item.widgets[k]).Put(PdfName.F, num); MarkUsed((PdfDictionary)item.widgets[k]); } } } else if (Util.EqualsIgnoreCase(name, "setflags")) { for (int k = 0; k < item.merged.Count; ++k) { if (hit.IsHit(k)) { PdfNumber num = (PdfNumber)PdfReader.GetPdfObject(((PdfDictionary)item.widgets[k]).Get(PdfName.F)); int val = 0; if (num != null) val = num.IntValue; num = new PdfNumber(val | value); ((PdfDictionary)item.merged[k]).Put(PdfName.F, num); ((PdfDictionary)item.widgets[k]).Put(PdfName.F, num); MarkUsed((PdfDictionary)item.widgets[k]); } } } else if (Util.EqualsIgnoreCase(name, "clrflags")) { for (int k = 0; k < item.merged.Count; ++k) { if (hit.IsHit(k)) { PdfNumber num = (PdfNumber)PdfReader.GetPdfObject(((PdfDictionary)item.widgets[k]).Get(PdfName.F)); int val = 0; if (num != null) val = num.IntValue; num = new PdfNumber(val & (~value)); ((PdfDictionary)item.merged[k]).Put(PdfName.F, num); ((PdfDictionary)item.widgets[k]).Put(PdfName.F, num); MarkUsed((PdfDictionary)item.widgets[k]); } } } else if (Util.EqualsIgnoreCase(name, "fflags")) { PdfNumber num = new PdfNumber(value); for (int k = 0; k < item.merged.Count; ++k) { if (hit.IsHit(k)) { ((PdfDictionary)item.merged[k]).Put(PdfName.FF, num); ((PdfDictionary)item.values[k]).Put(PdfName.FF, num); MarkUsed((PdfDictionary)item.values[k]); } } } else if (Util.EqualsIgnoreCase(name, "setfflags")) { for (int k = 0; k < item.merged.Count; ++k) { if (hit.IsHit(k)) { PdfNumber num = (PdfNumber)PdfReader.GetPdfObject(((PdfDictionary)item.values[k]).Get(PdfName.FF)); int val = 0; if (num != null) val = num.IntValue; num = new PdfNumber(val | value); ((PdfDictionary)item.merged[k]).Put(PdfName.FF, num); ((PdfDictionary)item.values[k]).Put(PdfName.FF, num); MarkUsed((PdfDictionary)item.values[k]); } } } else if (Util.EqualsIgnoreCase(name, "clrfflags")) { for (int k = 0; k < item.merged.Count; ++k) { if (hit.IsHit(k)) { PdfNumber num = (PdfNumber)PdfReader.GetPdfObject(((PdfDictionary)item.values[k]).Get(PdfName.FF)); int val = 0; if (num != null) val = num.IntValue; num = new PdfNumber(val & (~value)); ((PdfDictionary)item.merged[k]).Put(PdfName.FF, num); ((PdfDictionary)item.values[k]).Put(PdfName.FF, num); MarkUsed((PdfDictionary)item.values[k]); } } } else return false; return true; }
/** * Adds a <CODE>PdfNumber</CODE> to the <CODE>PdfArray</CODE>. * * @param number displacement of the string */ public void Add(PdfNumber number) { arrayList.Add(number.DoubleValue); }
protected PdfArray BranchForm(Hashtable level, PdfIndirectReference parent, string fname) { PdfArray arr = new PdfArray(); foreach (DictionaryEntry entry in level) { string name = (string)entry.Key; object obj = entry.Value; PdfIndirectReference ind = PdfIndirectReference; PdfDictionary dic = new PdfDictionary(); if (parent != null) { dic.Put(PdfName.Parent, parent); } dic.Put(PdfName.T, new PdfString(name, PdfObject.TEXT_UNICODE)); string fname2 = $"{fname}.{name}"; int coidx = _calculationOrder.IndexOf(fname2); if (coidx >= 0) { _calculationOrderRefs[coidx] = ind; } if (obj is Hashtable) { dic.Put(PdfName.Kids, BranchForm((Hashtable)obj, ind, fname2)); arr.Add(ind); AddToBody(dic, ind); } else { ArrayList list = (ArrayList)obj; dic.MergeDifferent((PdfDictionary)list[0]); if (list.Count == 3) { dic.MergeDifferent((PdfDictionary)list[2]); int page = (int)list[1]; PdfDictionary pageDic = (PdfDictionary)PageDics[page - 1]; PdfArray annots = pageDic.GetAsArray(PdfName.Annots); if (annots == null) { annots = new PdfArray(); pageDic.Put(PdfName.Annots, annots); } PdfNumber nn = (PdfNumber)dic.Get(_iTextTag); dic.Remove(_iTextTag); adjustTabOrder(annots, ind, nn); } else { PdfArray kids = new PdfArray(); for (int k = 1; k < list.Count; k += 2) { int page = (int)list[k]; PdfDictionary pageDic = (PdfDictionary)PageDics[page - 1]; PdfArray annots = pageDic.GetAsArray(PdfName.Annots); if (annots == null) { annots = new PdfArray(); pageDic.Put(PdfName.Annots, annots); } PdfDictionary widget = new PdfDictionary(); widget.Merge((PdfDictionary)list[k + 1]); widget.Put(PdfName.Parent, ind); PdfNumber nn = (PdfNumber)widget.Get(_iTextTag); widget.Remove(_iTextTag); PdfIndirectReference wref = AddToBody(widget).IndirectReference; adjustTabOrder(annots, wref, nn); kids.Add(wref); Propagate(widget, null, false); } dic.Put(PdfName.Kids, kids); } arr.Add(ind); AddToBody(dic, ind); Propagate(dic, null, false); } } return(arr); }
private void Init() { encoding = ""; fontSpecific = false; fontType = FONT_TYPE_DOCUMENT; PdfName baseFont = font.GetAsName(PdfName.BASEFONT); fontName = baseFont != null?PdfName.DecodeName(baseFont.ToString()) : "Unspecified Font Name"; PdfName subType = font.GetAsName(PdfName.SUBTYPE); if (PdfName.TYPE1.Equals(subType) || PdfName.TRUETYPE.Equals(subType)) { DoType1TT(); } else if (PdfName.TYPE3.Equals(subType)) { // In case of a Type3 font, we just show the characters as is. // Note that this doesn't always make sense: // Type 3 fonts are user defined fonts where arbitrary characters are mapped to custom glyphs // For instance: the character a could be mapped to an image of a dog, the character b to an image of a cat // When parsing a document that shows a cat and a dog, you shouldn't expect seeing a cat and a dog. Instead you'll get b and a. FillEncoding(null); FillDiffMap(font.GetAsDict(PdfName.ENCODING), null); FillWidths(); } else { PdfName encodingName = font.GetAsName(PdfName.ENCODING); if (encodingName != null) { String enc = PdfName.DecodeName(encodingName.ToString()); String ffontname = CJKFont.GetCompatibleFont(enc); if (ffontname != null) { cjkMirror = BaseFont.CreateFont(ffontname, enc, false); cjkEncoding = enc; uniMap = ((CJKFont)cjkMirror).UniMap; } if (PdfName.TYPE0.Equals(subType)) { isType0 = true; if (!enc.Equals("Identity-H") && cjkMirror != null) { PdfArray df = (PdfArray)PdfReader.GetPdfObjectRelease(font.Get(PdfName.DESCENDANTFONTS)); PdfDictionary cidft = (PdfDictionary)PdfReader.GetPdfObjectRelease(df[0]); PdfNumber dwo = (PdfNumber)PdfReader.GetPdfObjectRelease(cidft.Get(PdfName.DW)); if (dwo != null) { defaultWidth = dwo.IntValue; } hMetrics = ReadWidths((PdfArray)PdfReader.GetPdfObjectRelease(cidft.Get(PdfName.W))); PdfDictionary fontDesc = (PdfDictionary)PdfReader.GetPdfObjectRelease(cidft.Get(PdfName.FONTDESCRIPTOR)); FillFontDesc(fontDesc); } else { ProcessType0(font); } } } } }
private void doType1Tt() { PdfObject enc = PdfReader.GetPdfObject(_font.Get(PdfName.Encoding)); if (enc == null) { fillEncoding(null); } else { if (enc.IsName()) { fillEncoding((PdfName)enc); } else { PdfDictionary encDic = (PdfDictionary)enc; enc = PdfReader.GetPdfObject(encDic.Get(PdfName.Baseencoding)); if (enc == null) { fillEncoding(null); } else { fillEncoding((PdfName)enc); } PdfArray diffs = encDic.GetAsArray(PdfName.Differences); if (diffs != null) { _diffmap = new IntHashtable(); int currentNumber = 0; for (int k = 0; k < diffs.Size; ++k) { PdfObject obj = diffs[k]; if (obj.IsNumber()) { currentNumber = ((PdfNumber)obj).IntValue; } else { int[] c = GlyphList.NameToUnicode(PdfName.DecodeName(((PdfName)obj).ToString())); if (c != null && c.Length > 0) { Uni2Byte[c[0]] = currentNumber; _diffmap[c[0]] = currentNumber; } ++currentNumber; } } } } } PdfArray newWidths = _font.GetAsArray(PdfName.Widths); PdfNumber first = _font.GetAsNumber(PdfName.Firstchar); PdfNumber last = _font.GetAsNumber(PdfName.Lastchar); if (BuiltinFonts14.ContainsKey(_fontName)) { BaseFont bf; bf = CreateFont(_fontName, WINANSI, false); int[] e = Uni2Byte.ToOrderedKeys(); for (int k = 0; k < e.Length; ++k) { int n = Uni2Byte[e[k]]; widths[n] = bf.GetRawWidth(n, GlyphList.UnicodeToName(e[k])); } if (_diffmap != null) { //widths for differences must override existing ones e = _diffmap.ToOrderedKeys(); for (int k = 0; k < e.Length; ++k) { int n = _diffmap[e[k]]; widths[n] = bf.GetRawWidth(n, GlyphList.UnicodeToName(e[k])); } _diffmap = null; } _ascender = bf.GetFontDescriptor(ASCENT, 1000); _capHeight = bf.GetFontDescriptor(CAPHEIGHT, 1000); _descender = bf.GetFontDescriptor(DESCENT, 1000); _italicAngle = bf.GetFontDescriptor(ITALICANGLE, 1000); _llx = bf.GetFontDescriptor(BBOXLLX, 1000); _lly = bf.GetFontDescriptor(BBOXLLY, 1000); _urx = bf.GetFontDescriptor(BBOXURX, 1000); _ury = bf.GetFontDescriptor(BBOXURY, 1000); } if (first != null && last != null && newWidths != null) { int f = first.IntValue; for (int k = 0; k < newWidths.Size; ++k) { widths[f + k] = newWidths.GetAsNumber(k).IntValue; } } fillFontDesc(_font.GetAsDict(PdfName.Fontdescriptor)); }
/** * Adds a <CODE>PdfNumber</CODE> to the <CODE>PdfArray</CODE>. * * @param number displacement of the string */ virtual public void Add(PdfNumber number) { Add((float)number.DoubleValue); }
virtual public void PdfObjectCheckTest1() { string filename = OUT + "PdfObjectCheckTest1.pdf"; FileStream fos = new FileStream(filename, FileMode.Create); Document document = new Document(); PdfAWriter writer = PdfAWriter.GetInstance(document, fos, PdfAConformanceLevel.PDF_A_1B); writer.CreateXmpMetadata(); document.Open(); Font font = FontFactory.GetFont(RESOURCES + "FreeMonoBold.ttf", BaseFont.WINANSI, BaseFont.EMBEDDED, 12); document.Add(new Paragraph("Hello World", font)); FileStream iccProfileFileStream = File.Open(RESOURCES + "sRGB Color Space Profile.icm", FileMode.Open, FileAccess.Read, FileShare.Read); ICC_Profile icc = ICC_Profile.GetInstance(iccProfileFileStream); iccProfileFileStream.Close(); writer.SetOutputIntents("Custom", "", "http://www.color.org", "sRGB IEC61966-2.1", icc); ByteBuffer.HIGH_PRECISION = true; PdfNumber num = new PdfNumber(65535.12); writer.ExtraCatalog.Put(new PdfName("TestNumber"), num); bool exceptionThrown = false; try { document.Close(); } catch (PdfAConformanceException e) { if (e.GetObject().Equals(num)) exceptionThrown = true; } if (!exceptionThrown) Assert.Fail("PdfAConformanceException should be thrown."); }
/** * Adds a point to the Point Data dictionary. * @param value an XPTS value * @param identifier */ virtual public void AddXPTSValue(PdfNumber value, PtIdentifier identifier) { xpts.Add(value); names.Add(DecodeUnits.Decode(identifier)); }
virtual protected PdfArray BranchForm(Dictionary <string, object> level, PdfIndirectReference parent, String fname) { PdfArray arr = new PdfArray(); foreach (KeyValuePair <string, object> entry in level) { String name = entry.Key; Object obj = entry.Value; PdfIndirectReference ind = PdfIndirectReference; PdfDictionary dic = new PdfDictionary(); if (parent != null) { dic.Put(PdfName.PARENT, parent); } dic.Put(PdfName.T, new PdfString(name, PdfObject.TEXT_UNICODE)); String fname2 = fname + "." + name; int coidx = calculationOrder.IndexOf(fname2); if (coidx >= 0) { calculationOrderRefs[coidx] = ind; } if (obj is Dictionary <string, object> ) { dic.Put(PdfName.KIDS, BranchForm((Dictionary <string, object>)obj, ind, fname2)); arr.Add(ind); AddToBody(dic, ind); } else { List <object> list = (List <object>)obj; dic.MergeDifferent((PdfDictionary)list[0]); if (list.Count == 3) { dic.MergeDifferent((PdfDictionary)list[2]); int page = (int)list[1]; PdfDictionary pageDic = pageDics[page - 1]; PdfArray annots = pageDic.GetAsArray(PdfName.ANNOTS); if (annots == null) { annots = new PdfArray(); pageDic.Put(PdfName.ANNOTS, annots); } PdfNumber nn = (PdfNumber)dic.Get(iTextTag); dic.Remove(iTextTag); AdjustTabOrder(annots, ind, nn); } else { PdfDictionary field = (PdfDictionary)list[0]; PdfName v = field.GetAsName(PdfName.V); PdfArray kids = new PdfArray(); for (int k = 1; k < list.Count; k += 2) { int page = (int)list[k]; PdfDictionary pageDic = pageDics[page - 1]; PdfArray annots = pageDic.GetAsArray(PdfName.ANNOTS); if (annots == null) { annots = new PdfArray(); pageDic.Put(PdfName.ANNOTS, annots); } PdfDictionary widget = new PdfDictionary(); widget.Merge((PdfDictionary)list[k + 1]); widget.Put(PdfName.PARENT, ind); PdfNumber nn = (PdfNumber)widget.Get(iTextTag); widget.Remove(iTextTag); if (PdfCopy.IsCheckButton(field)) { PdfName _as = widget.GetAsName(PdfName.AS); if (v != null && _as != null) { widget.Put(PdfName.AS, v); } } else if (PdfCopy.IsRadioButton(field)) { PdfName _as = widget.GetAsName(PdfName.AS); if (v != null && _as != null && !_as.Equals(GetOffStateName(widget))) { if (!mergedRadioButtons.ContainsKey(list)) { mergedRadioButtons[list] = null; widget.Put(PdfName.AS, v); } else { widget.Put(PdfName.AS, GetOffStateName(widget)); } } } PdfIndirectReference wref = AddToBody(widget).IndirectReference; AdjustTabOrder(annots, wref, nn); kids.Add(wref); Propagate(widget, null, false); } dic.Put(PdfName.KIDS, kids); } arr.Add(ind); AddToBody(dic, ind); Propagate(dic, null, false); } } return(arr); }
virtual protected internal void ReadObjStm(PRStream stream, IntHashtable map) { if (stream == null) return; int first = stream.GetAsNumber(PdfName.FIRST).IntValue; int n = stream.GetAsNumber(PdfName.N).IntValue; byte[] b = GetStreamBytes(stream, tokens.File); PRTokeniser saveTokens = tokens; tokens = new PRTokeniser(new RandomAccessFileOrArray(new RandomAccessSourceFactory().CreateSource(b))); try { int[] address = new int[n]; int[] objNumber = new int[n]; bool ok = true; for (int k = 0; k < n; ++k) { ok = tokens.NextToken(); if (!ok) break; if (tokens.TokenType != PRTokeniser.TokType.NUMBER) { ok = false; break; } objNumber[k] = tokens.IntValue; ok = tokens.NextToken(); if (!ok) break; if (tokens.TokenType != PRTokeniser.TokType.NUMBER) { ok = false; break; } address[k] = tokens.IntValue + first; } if (!ok) throw new InvalidPdfException(MessageLocalization.GetComposedMessage("error.reading.objstm")); for (int k = 0; k < n; ++k) { if (map.ContainsKey(k)) { tokens.Seek(address[k]); tokens.NextToken(); PdfObject obj; if (tokens.TokenType == PRTokeniser.TokType.NUMBER) { obj = new PdfNumber(tokens.StringValue); } else { tokens.Seek(address[k]); obj = ReadPRObject(); } xrefObj[objNumber[k]] = obj; } } } finally { tokens = saveTokens; } }
private void AdjustTabOrder(PdfArray annots, PdfIndirectReference ind, PdfNumber nn) { int v = nn.IntValue; ArrayList t = (ArrayList)tabOrder[annots] ; if (t == null) { t = new ArrayList(); int size = annots.Size - 1; for (int k = 0; k < size; ++k) { t.Add(zero); } t.Add(v); tabOrder[annots] = t; annots.Add(ind); } else { int size = t.Count - 1; for (int k = size; k >= 0; --k) { if ((int)t[k] <= v) { t.Insert(k + 1, v); annots.ArrayList.Insert(k + 1, ind); size = -2; break; } } if (size != -2) { t.Insert(0, v); annots.ArrayList.Insert(0, ind); } } }
/** * Sets a field property. Valid property names are: * <p> * <ul> * <li>flags - a set of flags specifying various characteristics of the field�s widget annotation. * The value of this entry replaces that of the F entry in the form�s corresponding annotation dictionary.<br> * <li>setflags - a set of flags to be set (turned on) in the F entry of the form�s corresponding * widget annotation dictionary. Bits equal to 1 cause the corresponding bits in F to be set to 1.<br> * <li>clrflags - a set of flags to be cleared (turned off) in the F entry of the form�s corresponding * widget annotation dictionary. Bits equal to 1 cause the corresponding * bits in F to be set to 0.<br> * <li>fflags - a set of flags specifying various characteristics of the field. The value * of this entry replaces that of the Ff entry in the form�s corresponding field dictionary.<br> * <li>setfflags - a set of flags to be set (turned on) in the Ff entry of the form�s corresponding * field dictionary. Bits equal to 1 cause the corresponding bits in Ff to be set to 1.<br> * <li>clrfflags - a set of flags to be cleared (turned off) in the Ff entry of the form�s corresponding * field dictionary. Bits equal to 1 cause the corresponding bits in Ff * to be set to 0.<br> * </ul> * @param field the field name * @param name the property name * @param value the property value * @param inst an array of <CODE>int</CODE> indexing into <CODE>AcroField.Item.merged</CODE> elements to process. * Set to <CODE>null</CODE> to process all * @return <CODE>true</CODE> if the property exists, <CODE>false</CODE> otherwise */ public bool SetFieldProperty(String field, String name, int value, int[] inst) { if (writer == null) throw new Exception("This AcroFields instance is read-only."); Item item = (Item)fields[field]; if (item == null) return false; InstHit hit = new InstHit(inst); if (Util.EqualsIgnoreCase(name, "flags")) { PdfNumber num = new PdfNumber(value); for (int k = 0; k < item.Size; ++k) { if (hit.IsHit(k)) { item.GetMerged(k).Put(PdfName.F, num); item.GetWidget(k).Put(PdfName.F, num); MarkUsed(item.GetWidget(k)); } } } else if (Util.EqualsIgnoreCase(name, "setflags")) { for (int k = 0; k < item.Size; ++k) { if (hit.IsHit(k)) { PdfNumber num = item.GetWidget(k).GetAsNumber(PdfName.F); int val = 0; if (num != null) val = num.IntValue; num = new PdfNumber(val | value); item.GetMerged(k).Put(PdfName.F, num); item.GetWidget(k).Put(PdfName.F, num); MarkUsed(item.GetWidget(k)); } } } else if (Util.EqualsIgnoreCase(name, "clrflags")) { for (int k = 0; k < item.Size; ++k) { if (hit.IsHit(k)) { PdfDictionary widget = item.GetWidget( k ); PdfNumber num = widget.GetAsNumber(PdfName.F); int val = 0; if (num != null) val = num.IntValue; num = new PdfNumber(val & (~value)); item.GetMerged(k).Put(PdfName.F, num); widget.Put(PdfName.F, num); MarkUsed(widget); } } } else if (Util.EqualsIgnoreCase(name, "fflags")) { PdfNumber num = new PdfNumber(value); for (int k = 0; k < item.Size; ++k) { if (hit.IsHit(k)) { item.GetMerged(k).Put(PdfName.FF, num); item.GetValue(k).Put(PdfName.FF, num); MarkUsed(item.GetValue(k)); } } } else if (Util.EqualsIgnoreCase(name, "setfflags")) { for (int k = 0; k < item.Size; ++k) { if (hit.IsHit(k)) { PdfDictionary valDict = item.GetValue( k ); PdfNumber num = valDict.GetAsNumber( PdfName.FF ); int val = 0; if (num != null) val = num.IntValue; num = new PdfNumber(val | value); item.GetMerged(k).Put(PdfName.FF, num); valDict.Put(PdfName.FF, num); MarkUsed(valDict); } } } else if (Util.EqualsIgnoreCase(name, "clrfflags")) { for (int k = 0; k < item.Size; ++k) { if (hit.IsHit(k)) { PdfDictionary valDict = item.GetValue( k ); PdfNumber num = valDict.GetAsNumber(PdfName.FF); int val = 0; if (num != null) val = num.IntValue; num = new PdfNumber(val & (~value)); item.GetMerged(k).Put(PdfName.FF, num); valDict.Put(PdfName.FF, num); MarkUsed(valDict); } } } else return false; return true; }
/** * A factor that shall be used to convert the largest units along the y axis * to the largest units along the x axis. It shall be used for calculations * (distance, area, and angle) where the units are be equivalent; if not * specified, these calculations may not be performed (which would be the * case in situations such as x representing time and y representing * temperature). Other calculations (change in x, change in y, and slope) * shall not require this value. * * @param cyx */ public void SetCYX(PdfNumber cyx) { Put(PdfName.CYX, cyx); }
/** * The conversion factor used to multiply a value in partial units of the * previous number format array element to obtain a value in the units of * this dictionary. When this entry is in the first number format in the * array, its meaning (that is, what it shall be multiplied by) depends on * which entry in the RectilinearMeasure references the NumberFormat * array. * * @param n */ virtual public void SetConversionFactor(PdfNumber n) { base.Put(PdfName.C, n); }
private LockPermissions(int p) { number = new PdfNumber(p); }
/** * Adds a <CODE>PdfNumber</CODE> to the <CODE>PdfArray</CODE>. * * @param number displacement of the string */ public void Add(PdfNumber number) { Add((float)number.DoubleValue); }
private void DoType1TT() { PdfObject enc = PdfReader.GetPdfObject(font.Get(PdfName.ENCODING)); if (enc == null) { FillEncoding(null); } else { if (enc.IsName()) { FillEncoding((PdfName)enc); } else if (enc.IsDictionary()) { PdfDictionary encDic = (PdfDictionary)enc; enc = PdfReader.GetPdfObject(encDic.Get(PdfName.BASEENCODING)); if (enc == null) { FillEncoding(null); } else { FillEncoding((PdfName)enc); } PdfArray diffs = encDic.GetAsArray(PdfName.DIFFERENCES); if (diffs != null) { CMap toUnicode = null; diffmap = new IntHashtable(); int currentNumber = 0; for (int k = 0; k < diffs.Size; ++k) { PdfObject obj = diffs[k]; if (obj.IsNumber()) { currentNumber = ((PdfNumber)obj).IntValue; } else { int[] c = GlyphList.NameToUnicode(PdfName.DecodeName(((PdfName)obj).ToString())); if (c != null && c.Length > 0) { uni2byte[c[0]] = currentNumber; diffmap[c[0]] = currentNumber; } else { if (toUnicode == null) { toUnicode = ProcessToUnicode(); if (toUnicode == null) { toUnicode = new CMap(); } } string unicode = toUnicode.Lookup(new byte[] { (byte)currentNumber }, 0, 1); if ((unicode != null) && (unicode.Length == 1)) { this.uni2byte[unicode[0]] = currentNumber; this.diffmap[unicode[0]] = currentNumber; } } ++currentNumber; } } } } } PdfArray newWidths = font.GetAsArray(PdfName.WIDTHS); PdfNumber first = font.GetAsNumber(PdfName.FIRSTCHAR); PdfNumber last = font.GetAsNumber(PdfName.LASTCHAR); if (BuiltinFonts14.ContainsKey(fontName)) { BaseFont bf; bf = BaseFont.CreateFont(fontName, WINANSI, false); int[] e = uni2byte.ToOrderedKeys(); for (int k = 0; k < e.Length; ++k) { int n = uni2byte[e[k]]; widths[n] = bf.GetRawWidth(n, GlyphList.UnicodeToName(e[k])); } if (diffmap != null) //widths for differences must override existing ones { e = diffmap.ToOrderedKeys(); for (int k = 0; k < e.Length; ++k) { int n = diffmap[e[k]]; widths[n] = bf.GetRawWidth(n, GlyphList.UnicodeToName(e[k])); } diffmap = null; } Ascender = bf.GetFontDescriptor(ASCENT, 1000); CapHeight = bf.GetFontDescriptor(CAPHEIGHT, 1000); Descender = bf.GetFontDescriptor(DESCENT, 1000); ItalicAngle = bf.GetFontDescriptor(ITALICANGLE, 1000); llx = bf.GetFontDescriptor(BBOXLLX, 1000); lly = bf.GetFontDescriptor(BBOXLLY, 1000); urx = bf.GetFontDescriptor(BBOXURX, 1000); ury = bf.GetFontDescriptor(BBOXURY, 1000); } if (first != null && last != null && newWidths != null) { int f = first.IntValue; int nSize = f + newWidths.Size; if (widths.Length < nSize) { int[] tmp = new int[nSize]; System.Array.Copy(widths, 0, tmp, 0, f); widths = tmp; } for (int k = 0; k < newWidths.Size; ++k) { widths[f + k] = newWidths.GetAsNumber(k).IntValue; } } FillFontDesc(font.GetAsDict(PdfName.FONTDESCRIPTOR)); }
private void DrawOverlayText(PdfContentByte canvas, IList<Rectangle> textRectangles, PdfString overlayText, PdfString otDA, PdfNumber otQ, PdfBoolean otRepeat) { ColumnText ct = new ColumnText(canvas); ct.SetLeading(0, 1.2F); ct.UseAscender = true; String otStr = overlayText.ToUnicodeString(); canvas.SaveState(); IDictionary<string, IList<object>> parsedDA = ParseDAParam(otDA); Font font = null; if (parsedDA.ContainsKey(STROKE_COLOR)) { IList<object> strokeColorArgs = parsedDA[STROKE_COLOR]; SetStrokeColor(canvas, strokeColorArgs); } if (parsedDA.ContainsKey(FILL_COLOR)) { IList<object> fillColorArgs = parsedDA[FILL_COLOR]; SetFillColor(canvas, fillColorArgs); } if (parsedDA.ContainsKey("Tf")) { IList<object> tfArgs = parsedDA["Tf"]; font = RetrieveFontFromAcroForm((PdfName) tfArgs[0], (PdfNumber) tfArgs[1]); } foreach (Rectangle textRect in textRectangles) { ct.SetSimpleColumn(textRect); if (otQ != null) { ct.Alignment = otQ.IntValue; } Phrase otPhrase; if (font != null) { otPhrase = new Phrase(otStr, font); } else { otPhrase = new Phrase(otStr); } float y = ct.YLine; if (otRepeat != null && otRepeat.BooleanValue) { int status = ct.Go(true); while (!ColumnText.HasMoreText(status)) { otPhrase.Add(otStr); ct.SetText(otPhrase); ct.YLine = y; status = ct.Go(true); } } ct.SetText(otPhrase); ct.YLine = y; ct.Go(); } canvas.RestoreState(); }
private Font RetrieveFontFromAcroForm(PdfName fontName, PdfNumber size) { PdfIndirectReference fontIndirReference = pdfStamper.Reader.AcroForm.GetAsDict(PdfName.DR).GetAsDict(PdfName.FONT).GetAsIndirectObject(fontName); BaseFont bfont = BaseFont.CreateFont((PRIndirectReference) fontIndirReference); return new Font(bfont, size.FloatValue); }
private void AdjustTabOrder(PdfArray annots, PdfIndirectReference ind, PdfNumber nn) { int v = nn.IntValue; List<int> t; if (!tabOrder.TryGetValue(annots, out t)) { t = new List<int>(); int size = annots.Size - 1; for (int k = 0; k < size; ++k) { t.Add(zero); } t.Add(v); tabOrder[annots] = t; annots.Add(ind); } else { int size = t.Count - 1; for (int k = size; k >= 0; --k) { if (t[k] <= v) { t.Insert(k + 1, v); annots.Add(k + 1, ind); size = -2; break; } } if (size != -2) { t.Insert(0, v); annots.Add(0, ind); } } }
public byte[] Decode(byte[] b, PdfName filterName, PdfObject decodeParams, PdfDictionary streamDictionary) { PdfNumber wn = (PdfNumber)PdfReader.GetPdfObjectRelease(streamDictionary.Get(PdfName.WIDTH)); PdfNumber hn = (PdfNumber)PdfReader.GetPdfObjectRelease(streamDictionary.Get(PdfName.HEIGHT)); if (wn == null || hn == null) { throw new UnsupportedPdfException(MessageLocalization.GetComposedMessage("filter.ccittfaxdecode.is.only.supported.for.images")); } int width = wn.IntValue; int height = hn.IntValue; PdfDictionary param = decodeParams is PdfDictionary ? (PdfDictionary)decodeParams : null; int k = 0; bool blackIs1 = false; bool byteAlign = false; if (param != null) { PdfNumber kn = param.GetAsNumber(PdfName.K); if (kn != null) { k = kn.IntValue; } PdfBoolean bo = param.GetAsBoolean(PdfName.BLACKIS1); if (bo != null) { blackIs1 = bo.BooleanValue; } bo = param.GetAsBoolean(PdfName.ENCODEDBYTEALIGN); if (bo != null) { byteAlign = bo.BooleanValue; } } byte[] outBuf = new byte[(width + 7) / 8 * height]; TIFFFaxDecompressor decoder = new TIFFFaxDecompressor(); if (k == 0 || k > 0) { int tiffT4Options = k > 0 ? TIFFConstants.GROUP3OPT_2DENCODING : 0; tiffT4Options |= byteAlign ? TIFFConstants.GROUP3OPT_FILLBITS : 0; decoder.SetOptions(1, TIFFConstants.COMPRESSION_CCITTFAX3, tiffT4Options, 0); decoder.DecodeRaw(outBuf, b, width, height); if (decoder.fails > 0) { byte[] outBuf2 = new byte[(width + 7) / 8 * height]; int oldFails = decoder.fails; decoder.SetOptions(1, TIFFConstants.COMPRESSION_CCITTRLE, tiffT4Options, 0); decoder.DecodeRaw(outBuf2, b, width, height); if (decoder.fails < oldFails) { outBuf = outBuf2; } } } else { TIFFFaxDecoder deca = new TIFFFaxDecoder(1, width, height); deca.DecodeT6(outBuf, b, 0, height, 0); } if (!blackIs1) { int len = outBuf.Length; for (int t = 0; t < len; ++t) { outBuf[t] ^= 0xff; } } b = outBuf; return(b); }