本文整理汇总了C#中iTextSharp.text.pdf.PdfDictionary.GetAsDict方法的典型用法代码示例。如果您正苦于以下问题:C# PdfDictionary.GetAsDict方法的具体用法?C# PdfDictionary.GetAsDict怎么用?C# PdfDictionary.GetAsDict使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类iTextSharp.text.pdf.PdfDictionary
的用法示例。
在下文中一共展示了PdfDictionary.GetAsDict方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: UnembedTTF
/**
* Processes a dictionary.
* In case of font dictionaries, the dictionary is processed.
*/
public void UnembedTTF(PdfDictionary dict)
{
// we ignore all dictionaries that aren't font dictionaries
if (!dict.IsFont())
return;
// we only remove TTF fonts
if (dict.GetAsDict(PdfName.FONTFILE2) != null)
{
return;
}
// check if a subset was used (in which case we remove the prefix)
PdfName baseFont = dict.GetAsName(PdfName.BASEFONT);
if (baseFont.GetBytes()[7] == '+')
{
baseFont = new PdfName(baseFont.ToString().Substring(8));
dict.Put(PdfName.BASEFONT, baseFont);
}
// we check if there's a font descriptor
PdfDictionary fontDescriptor = dict.GetAsDict(PdfName.FONTDESCRIPTOR);
if (fontDescriptor == null)
return;
// is there is, we replace the fontname and remove the font file
fontDescriptor.Put(PdfName.FONTNAME, baseFont);
fontDescriptor.Remove(PdfName.FONTFILE2);
}
示例2: ProcessResource
// ---------------------------------------------------------------------------
/**
* Extracts the font names from page or XObject resources.
* @param set the HashSet with the font names
* @param resources the resources dictionary
*/
public void ProcessResource(HashSet<String> set, PdfDictionary resource)
{
if (resource == null) return;
PdfDictionary xobjects = resource.GetAsDict(PdfName.XOBJECT);
if (xobjects != null) {
foreach (PdfName key in xobjects.Keys) {
ProcessResource(set, xobjects.GetAsDict(key));
}
}
PdfDictionary fonts = resource.GetAsDict(PdfName.FONT);
if (fonts == null) return;
PdfDictionary font;
foreach (PdfName key in fonts.Keys) {
font = fonts.GetAsDict(key);
String name = font.GetAsName(PdfName.BASEFONT).ToString();
if (name.Length > 8 && name.Substring(7, 1) == "+") {
name = String.Format(
"{0} subset ({1})",
name.Substring(8), name.Substring(1, 7)
);
}
else {
name = name.Substring(1);
PdfDictionary desc = font.GetAsDict(PdfName.FONTDESCRIPTOR);
if (desc == null) {
name += " nofontdescriptor";
}
else if (desc.Get(PdfName.FONTFILE) != null) {
name += " (Type 1) embedded";
}
else if (desc.Get(PdfName.FONTFILE2) != null) {
name += " (TrueType) embedded";
}
else if (desc.Get(PdfName.FONTFILE3) != null) {
name += " (" + font.GetAsName(PdfName.SUBTYPE).ToString().Substring(1) + ") embedded";
}
}
set.Add(name);
}
}
示例3: ReadPages
virtual protected internal void ReadPages() {
catalog = trailer.GetAsDict(PdfName.ROOT);
if(catalog == null)
throw new InvalidPdfException(MessageLocalization.GetComposedMessage("the.document.has.no.catalog.object"));
rootPages = catalog.GetAsDict(PdfName.PAGES);
if(rootPages == null)
throw new InvalidPdfException(MessageLocalization.GetComposedMessage("the.document.has.no.page.root"));
pageRefs = new PageRefs(this);
}
示例4: InspectChildDictionary
/**
* If the child of a structured element is a dictionary, we inspect the
* child; we may also draw a tag.
*
* @param k
* the child dictionary to inspect
*/
public void InspectChildDictionary(PdfDictionary k, bool inspectAttributes) {
if (k == null)
return;
PdfName s = k.GetAsName(PdfName.S);
if (s != null) {
String tagN = PdfName.DecodeName(s.ToString());
String tag = FixTagName(tagN);
outp.Write("<");
outp.Write(tag);
if (inspectAttributes) {
PdfDictionary a = k.GetAsDict(PdfName.A);
if (a != null) {
Dictionary<PdfName, PdfObject>.KeyCollection keys = a.Keys;
foreach (PdfName key in keys) {
outp.Write(' ');
PdfObject value = a.Get(key);
value = PdfReader.GetPdfObject(value);
outp.Write(XmlName(key));
outp.Write("=\"");
outp.Write(value.ToString());
outp.Write("\"");
}
}
}
outp.Write(">");
PdfDictionary dict = k.GetAsDict(PdfName.PG);
if (dict != null)
ParseTag(tagN, k.GetDirectObject(PdfName.K), dict);
InspectChild(k.GetDirectObject(PdfName.K));
outp.Write("</");
outp.Write(tag);
outp.WriteLine(">");
} else
InspectChild(k.GetDirectObject(PdfName.K));
}
示例5: ParseTag
public override void ParseTag(String tag, PdfObject obj, PdfDictionary page) {
if (obj is PdfNumber) {
PdfNumber mcid = (PdfNumber) obj;
RenderFilter filter = new MyMarkedContentRenderFilter(mcid.IntValue);
ITextExtractionStrategy strategy = new SimpleTextExtractionStrategy();
FilteredTextRenderListener listener = new FilteredTextRenderListener(
strategy, filter);
PdfContentStreamProcessor processor = new PdfContentStreamProcessor(
listener);
processor.ProcessContent(PdfReader.GetPageContent(page), page
.GetAsDict(PdfName.RESOURCES));
outp.Write(XMLUtil.EscapeXML(listener.GetResultantText(), true));
}
else {
base.ParseTag(tag, obj, page);
}
}
示例6: GetXObjectDetail
/**
* Displays a summary of the entries in the XObject dictionary for the stream
* @param resourceDic the resource dictionary for the stream
* @return a string with the summary of the entries
* @throws IOException
* @since 5.0.2
*/
public static String GetXObjectDetail(PdfDictionary resourceDic) {
StringBuilder sb = new StringBuilder();
PdfDictionary xobjects = resourceDic.GetAsDict(PdfName.XOBJECT);
if (xobjects == null)
return "No XObjects";
foreach (PdfName entryName in xobjects.Keys) {
PdfStream xobjectStream = xobjects.GetAsStream(entryName);
sb.Append("------ " + entryName + " - subtype = " + xobjectStream.Get(PdfName.SUBTYPE) + " = " + xobjectStream.GetAsNumber(PdfName.LENGTH) + " bytes ------\n");
if (!xobjectStream.Get(PdfName.SUBTYPE).Equals(PdfName.IMAGE)){
byte[] contentBytes = ContentByteUtils.GetContentBytesFromContentObject(xobjectStream);
foreach (byte b in contentBytes) {
sb.Append((char)b);
}
sb.Append("------ " + entryName + " - subtype = " + xobjectStream.Get(PdfName.SUBTYPE) + "End of Content" + "------\n");
}
}
return sb.ToString();
}
示例7: AddFieldResources
private void AddFieldResources(PdfDictionary catalog)
{
if (fieldArray == null)
return;
PdfDictionary acroForm = new PdfDictionary();
catalog.Put(PdfName.ACROFORM, acroForm);
acroForm.Put(PdfName.FIELDS, fieldArray);
acroForm.Put(PdfName.DA, new PdfString("/Helv 0 Tf 0 g "));
if (fieldTemplates.Count == 0)
return;
PdfDictionary dr = new PdfDictionary();
acroForm.Put(PdfName.DR, dr);
foreach (PdfTemplate template in fieldTemplates.Keys) {
PdfFormField.MergeResources(dr, (PdfDictionary)template.Resources);
}
PdfDictionary fonts = dr.GetAsDict(PdfName.FONT);
if (fonts == null) {
fonts = new PdfDictionary();
dr.Put(PdfName.FONT, fonts);
}
if (!fonts.Contains(PdfName.HELV)) {
PdfDictionary dic = new PdfDictionary(PdfName.FONT);
dic.Put(PdfName.BASEFONT, PdfName.HELVETICA);
dic.Put(PdfName.ENCODING, PdfName.WIN_ANSI_ENCODING);
dic.Put(PdfName.NAME, PdfName.HELV);
dic.Put(PdfName.SUBTYPE, PdfName.TYPE1);
fonts.Put(PdfName.HELV, AddToBody(dic).IndirectReference);
}
if (!fonts.Contains(PdfName.ZADB)) {
PdfDictionary dic = new PdfDictionary(PdfName.FONT);
dic.Put(PdfName.BASEFONT, PdfName.ZAPFDINGBATS);
dic.Put(PdfName.NAME, PdfName.ZADB);
dic.Put(PdfName.SUBTYPE, PdfName.TYPE1);
fonts.Put(PdfName.ZADB, AddToBody(dic).IndirectReference);
}
}
示例8: MergeResources
internal static void MergeResources(PdfDictionary result, PdfDictionary source, PdfStamperImp writer) {
PdfDictionary dic = null;
PdfDictionary res = null;
PdfName target = null;
for (int k = 0; k < mergeTarget.Length; ++k) {
target = mergeTarget[k];
PdfDictionary pdfDict = source.GetAsDict(target);
if ((dic = pdfDict) != null) {
if ((res = (PdfDictionary)PdfReader.GetPdfObject(result.Get(target), result)) == null) {
res = new PdfDictionary();
}
res.MergeDifferent(dic);
result.Put(target, res);
if (writer != null)
writer.MarkUsed(res);
}
}
}
示例9: IsInAP
internal bool IsInAP(PdfDictionary dic, PdfName check)
{
PdfDictionary appDic = dic.GetAsDict(PdfName.AP);
if (appDic == null)
return false;
PdfDictionary NDic = appDic.GetAsDict(PdfName.N);
return (NDic != null && NDic.Get(check) != null);
}
示例10: Parse
/// <summary>
/// Uses the OCGParser on a page </summary>
/// <param name="parser"> the OCGParser </param>
/// <param name="page"> the page dictionary of the page that needs to be parsed. </param>
/// <exception cref="IOException"> </exception>
private void Parse(OCGParser parser, PdfDictionary page)
{
PRStream stream = (PRStream)page.GetAsStream(PdfName.CONTENTS);
PdfDictionary resources = page.GetAsDict(PdfName.RESOURCES);
parser.Parse(stream, resources);
}
示例11: RemoveProperties
/// <summary>
/// Removes ocgs from a page resources </summary>
/// <param name="page"> a page dictionary </param>
/// <param name="ocgs"> a set of names of OCG layers </param>
private void RemoveProperties(PdfDictionary page, ICollection<string> ocgs)
{
PdfDictionary resources = page.GetAsDict(PdfName.RESOURCES);
if (resources == null)
{
return;
}
PdfDictionary properties = resources.GetAsDict(PdfName.PROPERTIES);
if (properties == null)
{
return;
}
ICollection<PdfName> names = properties.Keys;
IList<PdfName> remove = new List<PdfName>();
foreach (PdfName name in names)
{
PdfDictionary dict = properties.GetAsDict(name);
if (IsToBeRemoved(dict, ocgs))
{
remove.Add(name);
}
else
{
RemoveOCGsFromArray(dict, PdfName.OCGS, ocgs);
}
}
foreach (PdfName name in remove)
{
properties.Remove(name);
}
}
示例12: ProcessContent
/**
* Processes PDF syntax.
* <b>Note:</b> If you re-use a given {@link PdfContentStreamProcessor}, you must call {@link PdfContentStreamProcessor#reset()}
* @param contentBytes the bytes of a content stream
* @param resources the resources that come with the content stream
*/
public void ProcessContent(byte[] contentBytes, PdfDictionary resources){
this.resources.Push(resources);
PRTokeniser tokeniser = new PRTokeniser(new RandomAccessFileOrArray(new RandomAccessSourceFactory().CreateSource(contentBytes)));
PdfContentParser ps = new PdfContentParser(tokeniser);
List<PdfObject> operands = new List<PdfObject>();
while (ps.Parse(operands).Count > 0){
PdfLiteral oper = (PdfLiteral)operands[operands.Count-1];
if ("BI".Equals(oper.ToString())){
// we don't call invokeOperator for embedded images - this is one area of the PDF spec that is particularly nasty and inconsistent
PdfDictionary colorSpaceDic = resources != null ? resources.GetAsDict(PdfName.COLORSPACE) : null;
ImageRenderInfo renderInfo = ImageRenderInfo.CreateForEmbeddedImage(Gs().ctm, InlineImageUtils.ParseInlineImage(ps, colorSpaceDic), colorSpaceDic);
renderListener.RenderImage(renderInfo);
} else {
InvokeOperator(oper, operands);
}
}
this.resources.Pop();
}
示例13: RecourseFonts
private static void RecourseFonts(PdfDictionary page, IntHashtable hits, List<object[]> fonts, int level, HashSet2<PdfDictionary> visitedResources)
{
++level;
if (level > 50) // in case we have an endless loop
return;
if (page == null)
return;
PdfDictionary resources = page.GetAsDict(PdfName.RESOURCES);
if (resources == null)
return;
PdfDictionary font = resources.GetAsDict(PdfName.FONT);
if (font != null) {
foreach (PdfName key in font.Keys) {
PdfObject ft = font.Get(key);
if (ft == null || !ft.IsIndirect())
continue;
int hit = ((PRIndirectReference)ft).Number;
if (hits.ContainsKey(hit))
continue;
AddFont((PRIndirectReference)ft, hits, fonts);
}
}
PdfDictionary xobj = resources.GetAsDict(PdfName.XOBJECT);
if(xobj != null){
if (visitedResources.AddAndCheck(xobj)){
foreach (PdfName key in xobj.Keys) {
PdfObject po = xobj.GetDirectObject(key);
if (po is PdfDictionary)
RecourseFonts((PdfDictionary)po, hits, fonts, level, visitedResources);
}
visitedResources.Remove(xobj);
} else
throw new InvalidPdfException(MessageLocalization.GetComposedMessage("illegal.resources.tree"));
}
}
示例14: GetPageResources
/**
* Retrieve the given page's resource dictionary
* @param pageDict the given page
* @return The page's resources, or 'null' if the page has none.
* @since 5.1
*/
virtual public PdfDictionary GetPageResources(PdfDictionary pageDict) {
return pageDict.GetAsDict(PdfName.RESOURCES);
}
示例15: GenerateNameForXObj
private PdfName GenerateNameForXObj(PdfDictionary pageDict) {
PdfDictionary resourcesDict = pageDict.GetAsDict(PdfName.RESOURCES);
PdfDictionary xobjDict = resourcesDict.GetAsDict(PdfName.XOBJECT);
if (xobjDict != null) {
foreach (PdfName xobjName in xobjDict.Keys) {
int xobjNum = GetXObjNum(xobjName);
if (currentXObjNum <= xobjNum) {
currentXObjNum = xobjNum + 1;
}
}
}
return new PdfName(XOBJ_NAME_PREFIX + currentXObjNum++);
}