本文整理匯總了C#中iTextSharp.text.pdf.PdfDictionary.GetAsNumber方法的典型用法代碼示例。如果您正苦於以下問題:C# PdfDictionary.GetAsNumber方法的具體用法?C# PdfDictionary.GetAsNumber怎麽用?C# PdfDictionary.GetAsNumber使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類iTextSharp.text.pdf.PdfDictionary
的用法示例。
在下文中一共展示了PdfDictionary.GetAsNumber方法的9個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。
示例1: DecodeGenericDictionary
public void DecodeGenericDictionary(PdfDictionary merged, BaseField tx)
{
int flags = 0;
// the text size and color
PdfString da = merged.GetAsString(PdfName.DA);
if (da != null) {
Object[] dab = SplitDAelements(da.ToUnicodeString());
if (dab[DA_SIZE] != null)
tx.FontSize = (float)dab[DA_SIZE];
if (dab[DA_COLOR] != null)
tx.TextColor = (Color)dab[DA_COLOR];
if (dab[DA_FONT] != null) {
PdfDictionary font = merged.GetAsDict(PdfName.DR);
if (font != null) {
font = font.GetAsDict(PdfName.FONT);
if (font != null) {
PdfObject po = font.Get(new PdfName((String)dab[DA_FONT]));
if (po != null && po.Type == PdfObject.INDIRECT) {
PRIndirectReference por = (PRIndirectReference)po;
BaseFont bp = new DocumentFont((PRIndirectReference)po);
tx.Font = bp;
int porkey = por.Number;
BaseFont porf = (BaseFont)extensionFonts[porkey];
if (porf == null) {
if (!extensionFonts.ContainsKey(porkey)) {
PdfDictionary fo = (PdfDictionary)PdfReader.GetPdfObject(po);
PdfDictionary fd = fo.GetAsDict(PdfName.FONTDESCRIPTOR);
if (fd != null) {
PRStream prs = (PRStream)PdfReader.GetPdfObject(fd.Get(PdfName.FONTFILE2));
if (prs == null)
prs = (PRStream)PdfReader.GetPdfObject(fd.Get(PdfName.FONTFILE3));
if (prs == null) {
extensionFonts[porkey] = null;
}
else {
try {
porf = BaseFont.CreateFont("font.ttf", BaseFont.IDENTITY_H, true, false, PdfReader.GetStreamBytes(prs), null);
}
catch {
}
extensionFonts[porkey] = porf;
}
}
}
}
if (tx is TextField)
((TextField)tx).ExtensionFont = porf;
}
else {
BaseFont bf = (BaseFont)localFonts[dab[DA_FONT]];
if (bf == null) {
String[] fn = (String[])stdFieldFontNames[dab[DA_FONT]];
if (fn != null) {
try {
String enc = "winansi";
if (fn.Length > 1)
enc = fn[1];
bf = BaseFont.CreateFont(fn[0], enc, false);
tx.Font = bf;
}
catch {
// empty
}
}
}
else
tx.Font = bf;
}
}
}
}
}
//rotation, border and backgound color
PdfDictionary mk = merged.GetAsDict(PdfName.MK);
if (mk != null) {
PdfArray ar = mk.GetAsArray(PdfName.BC);
Color border = GetMKColor(ar);
tx.BorderColor = border;
if (border != null)
tx.BorderWidth = 1;
ar = mk.GetAsArray(PdfName.BG);
tx.BackgroundColor = GetMKColor(ar);
PdfNumber rotation = mk.GetAsNumber(PdfName.R);
if (rotation != null)
tx.Rotation = rotation.IntValue;
}
//flags
PdfNumber nfl = merged.GetAsNumber(PdfName.F);
flags = 0;
tx.Visibility = BaseField.VISIBLE_BUT_DOES_NOT_PRINT;
if (nfl != null) {
flags = nfl.IntValue;
if ((flags & PdfFormField.FLAGS_PRINT) != 0 && (flags & PdfFormField.FLAGS_HIDDEN) != 0)
tx.Visibility = BaseField.HIDDEN;
else if ((flags & PdfFormField.FLAGS_PRINT) != 0 && (flags & PdfFormField.FLAGS_NOVIEW) != 0)
tx.Visibility = BaseField.HIDDEN_BUT_PRINTABLE;
else if ((flags & PdfFormField.FLAGS_PRINT) != 0)
tx.Visibility = BaseField.VISIBLE;
}
//multiline
//.........這裏部分代碼省略.........
示例2: FillFontDesc
private void FillFontDesc(PdfDictionary fontDesc) {
if (fontDesc == null)
return;
PdfNumber v = fontDesc.GetAsNumber(PdfName.ASCENT);
if (v != null)
Ascender = v.FloatValue;
v = fontDesc.GetAsNumber(PdfName.CAPHEIGHT);
if (v != null)
CapHeight = v.FloatValue;
v = fontDesc.GetAsNumber(PdfName.DESCENT);
if (v != null)
Descender = v.FloatValue;
v = fontDesc.GetAsNumber(PdfName.ITALICANGLE);
if (v != null)
ItalicAngle = v.FloatValue;
PdfArray bbox = fontDesc.GetAsArray(PdfName.FONTBBOX);
if (bbox != null) {
llx = bbox.GetAsNumber(0).FloatValue;
lly = bbox.GetAsNumber(1).FloatValue;
urx = bbox.GetAsNumber(2).FloatValue;
ury = bbox.GetAsNumber(3).FloatValue;
if (llx > urx) {
float t = llx;
llx = urx;
urx = t;
}
if (lly > ury) {
float t = lly;
lly = ury;
ury = t;
}
}
}
示例3: GetPageRotation
internal int GetPageRotation(PdfDictionary page) {
PdfNumber rotate = page.GetAsNumber(PdfName.ROTATE);
if (rotate == null)
return 0;
else {
int n = rotate.IntValue;
n %= 360;
return n < 0 ? n + 360 : n;
}
}
示例4: GetAppearance
internal PdfAppearance GetAppearance(PdfDictionary merged, String text, String fieldName)
{
topFirst = 0;
TextField tx = null;
if (fieldCache == null || !fieldCache.ContainsKey(fieldName)) {
tx = new TextField(writer, null, null);
tx.SetExtraMargin(extraMarginLeft, extraMarginTop);
tx.BorderWidth = 0;
tx.SubstitutionFonts = substitutionFonts;
DecodeGenericDictionary(merged, tx);
//rect
PdfArray rect = merged.GetAsArray(PdfName.RECT);
Rectangle box = PdfReader.GetNormalizedRectangle(rect);
if (tx.Rotation == 90 || tx.Rotation == 270)
box = box.Rotate();
tx.Box = box;
if (fieldCache != null)
fieldCache[fieldName] = tx;
}
else {
tx = (TextField)fieldCache[fieldName];
tx.Writer = writer;
}
PdfName fieldType = merged.GetAsName(PdfName.FT);
if (PdfName.TX.Equals(fieldType)) {
tx.Text = text;
return tx.GetAppearance();
}
if (!PdfName.CH.Equals(fieldType))
throw new DocumentException("An appearance was requested without a variable text field.");
PdfArray opt = merged.GetAsArray(PdfName.OPT);
int flags = 0;
PdfNumber nfl = merged.GetAsNumber(PdfName.FF);
if (nfl != null)
flags = nfl.IntValue;
if ((flags & PdfFormField.FF_COMBO) != 0 && opt == null) {
tx.Text = text;
return tx.GetAppearance();
}
if (opt != null) {
String[] choices = new String[opt.Size];
String[] choicesExp = new String[opt.Size];
for (int k = 0; k < opt.Size; ++k) {
PdfObject obj = opt[k];
if (obj.IsString()) {
choices[k] = choicesExp[k] = ((PdfString)obj).ToUnicodeString();
}
else {
PdfArray a = (PdfArray) obj;
choicesExp[k] = a.GetAsString(0).ToUnicodeString();
choices[k] = a.GetAsString(1).ToUnicodeString();
}
}
if ((flags & PdfFormField.FF_COMBO) != 0) {
for (int k = 0; k < choices.Length; ++k) {
if (text.Equals(choicesExp[k])) {
text = choices[k];
break;
}
}
tx.Text = text;
return tx.GetAppearance();
}
int idx = 0;
for (int k = 0; k < choicesExp.Length; ++k) {
if (text.Equals(choicesExp[k])) {
idx = k;
break;
}
}
tx.Choices = choices;
tx.ChoiceExports = choicesExp;
tx.ChoiceSelection = idx;
}
PdfAppearance app = tx.GetListAppearance();
topFirst = tx.TopFirst;
return app;
}
示例5: FillFontDesc
private void FillFontDesc(PdfDictionary fontDesc) {
if (fontDesc == null)
return;
PdfNumber v = fontDesc.GetAsNumber(PdfName.ASCENT);
if (v != null)
Ascender = v.FloatValue;
v = fontDesc.GetAsNumber(PdfName.CAPHEIGHT);
if (v != null)
CapHeight = v.FloatValue;
v = fontDesc.GetAsNumber(PdfName.DESCENT);
if (v != null)
Descender = v.FloatValue;
v = fontDesc.GetAsNumber(PdfName.ITALICANGLE);
if (v != null)
ItalicAngle = v.FloatValue;
v = fontDesc.GetAsNumber(PdfName.FONTWEIGHT);
if (v != null) {
fontWeight = v.FloatValue;
}
PdfArray bbox = fontDesc.GetAsArray(PdfName.FONTBBOX);
if (bbox != null) {
llx = bbox.GetAsNumber(0).FloatValue;
lly = bbox.GetAsNumber(1).FloatValue;
urx = bbox.GetAsNumber(2).FloatValue;
ury = bbox.GetAsNumber(3).FloatValue;
if (llx > urx) {
float t = llx;
llx = urx;
urx = t;
}
if (lly > ury) {
float t = lly;
lly = ury;
ury = t;
}
}
float maxAscent = Math.Max(ury, Ascender);
float minDescent = Math.Min(lly, Descender);
Ascender = maxAscent * 1000 / (maxAscent - minDescent);
Descender = minDescent * 1000 / (maxAscent - minDescent);
}
示例6: ParseUnfilteredSamples
/**
* Parses the samples of the image from the underlying content parser, ignoring all filters.
* The parser must be positioned immediately after the ID operator that ends the inline image's dictionary.
* The parser will be left positioned immediately following the EI operator.
* This is primarily useful if no filters have been applied.
* @param imageDictionary the dictionary of the inline image
* @param ps the content parser
* @return the samples of the image
* @throws IOException if anything bad happens during parsing
*/
private static byte[] ParseUnfilteredSamples(PdfDictionary imageDictionary, PdfDictionary colorSpaceDic, PdfContentParser ps)
{
// special case: when no filter is specified, we just read the number of bits
// per component, multiplied by the width and height.
if (imageDictionary.Contains(PdfName.FILTER))
throw new ArgumentException("Dictionary contains filters");
PdfNumber h = imageDictionary.GetAsNumber(PdfName.HEIGHT);
int bytesToRead = ComputeBytesPerRow(imageDictionary, colorSpaceDic) * h.IntValue;
byte[] bytes = new byte[bytesToRead];
PRTokeniser tokeniser = ps.GetTokeniser();
int shouldBeWhiteSpace = tokeniser.Read(); // skip next character (which better be a whitespace character - I suppose we could check for this)
// from the PDF spec: Unless the image uses ASCIIHexDecode or ASCII85Decode as one of its filters, the ID operator shall be followed by a single white-space character, and the next character shall be interpreted as the first byte of image data.
// unfortunately, we've seen some PDFs where there is no space following the ID, so we have to capture this case and handle it
int startIndex = 0;
if (!PRTokeniser.IsWhitespace(shouldBeWhiteSpace) || shouldBeWhiteSpace == 0){ // tokeniser treats 0 as whitespace, but for our purposes, we shouldn't)
bytes[0] = (byte)shouldBeWhiteSpace;
startIndex++;
}
for (int i = startIndex; i < bytesToRead; i++){
int ch = tokeniser.Read();
if (ch == -1)
throw new InlineImageParseException("End of content stream reached before end of image data");
bytes[i] = (byte)ch;
}
PdfObject ei = ps.ReadPRObject();
if (!ei.ToString().Equals("EI"))
throw new InlineImageParseException("EI not found after end of image data");
return bytes;
}
示例7: ComputeBytesPerRow
/**
* Computes the number of unfiltered bytes that each row of the image will contain.
* If the number of bytes results in a partial terminating byte, this number is rounded up
* per the PDF specification
* @param imageDictionary the dictionary of the inline image
* @return the number of bytes per row of the image
*/
private static int ComputeBytesPerRow(PdfDictionary imageDictionary, PdfDictionary colorSpaceDic)
{
PdfNumber wObj = imageDictionary.GetAsNumber(PdfName.WIDTH);
PdfNumber bpcObj = imageDictionary.GetAsNumber(PdfName.BITSPERCOMPONENT);
int cpp = GetComponentsPerPixel(imageDictionary.GetAsName(PdfName.COLORSPACE), colorSpaceDic);
int w = wObj.IntValue;
int bpc = bpcObj != null ? bpcObj.IntValue : 1;
int bytesPerRow = (w * bpc * cpp + 7) / 8;
return bytesPerRow;
}
示例8: GetFlags
internal static int? GetFlags(PdfDictionary field) {
PdfName type = field.GetAsName(PdfName.FT);
if (!PdfName.BTN.Equals(type))
return null;
PdfNumber flags = field.GetAsNumber(PdfName.FF);
if (flags == null)
return null;
return flags.IntValue;
}
示例9: ParseUnfilteredSamples
/**
* Parses the samples of the image from the underlying content parser, ignoring all filters.
* The parser must be positioned immediately after the ID operator that ends the inline image's dictionary.
* The parser will be left positioned immediately following the EI operator.
* This is primarily useful if no filters have been applied.
* @param imageDictionary the dictionary of the inline image
* @param ps the content parser
* @return the samples of the image
* @throws IOException if anything bad happens during parsing
*/
private static byte[] ParseUnfilteredSamples(PdfDictionary imageDictionary, PdfContentParser ps) {
// special case: when no filter is specified, we just read the number of bits
// per component, multiplied by the width and height.
if (imageDictionary.Contains(PdfName.FILTER))
throw new ArgumentException("Dictionary contains filters");
PdfNumber h = imageDictionary.GetAsNumber(PdfName.HEIGHT);
int bytesToRead = ComputeBytesPerRow(imageDictionary) * h.IntValue;
byte[] bytes = new byte[bytesToRead];
PRTokeniser tokeniser = ps.GetTokeniser();
tokeniser.Read(); // skip next character (which better be a whitespace character - I suppose we could check for this)
for (int i = 0; i < bytesToRead; i++){
int ch = tokeniser.Read();
if (ch == -1)
throw new InlineImageParseException("End of content stream reached before end of image data");
bytes[i] = (byte)ch;
}
PdfObject ei = ps.ReadPRObject();
if (!ei.ToString().Equals("EI"))
throw new InlineImageParseException("EI not found after end of image data");
return bytes;
}