当前位置: 首页>>代码示例>>Java>>正文


Java PdfDictionary.getAsName方法代码示例

本文整理汇总了Java中com.itextpdf.text.pdf.PdfDictionary.getAsName方法的典型用法代码示例。如果您正苦于以下问题:Java PdfDictionary.getAsName方法的具体用法?Java PdfDictionary.getAsName怎么用?Java PdfDictionary.getAsName使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.itextpdf.text.pdf.PdfDictionary的用法示例。


在下文中一共展示了PdfDictionary.getAsName方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: unpack

import com.itextpdf.text.pdf.PdfDictionary; //导入方法依赖的package包/类
private void unpack(Set<PdfDictionary> dictionaries) throws TaskIOException {
    for (PdfDictionary dictionary : dictionaries) {
        PdfName type = dictionary.getAsName(PdfName.TYPE);
        if (PdfName.F.equals(type) || PdfName.FILESPEC.equals(type)) {
            PdfDictionary ef = dictionary.getAsDict(PdfName.EF);
            PdfString fn = dictionary.getAsString(PdfName.F);
            if (fn != null && ef != null) {
                PRStream prs = (PRStream) PdfReader.getPdfObject(ef.get(PdfName.F));
                if (prs != null) {
                    File tmpFile = copyToTemporaryFile(prs);
                    outputWriter.addOutput(file(tmpFile).name(fn.toUnicodeString()));
                }
            }
        }
    }
}
 
开发者ID:torakiki,项目名称:sejda-itext5,代码行数:17,代码来源:PdfUnpacker.java

示例2: copyLinks

import com.itextpdf.text.pdf.PdfDictionary; //导入方法依赖的package包/类
/**
 * <p>
 * A primitive attempt at copying links from page <code>sourcePage</code>
 * of <code>PdfReader reader</code> to page <code>targetPage</code> of
 * <code>PdfStamper stamper</code>.
 * </p>
 * <p>
 * This method is meant only for the use case at hand, i.e. copying a link
 * to an external URI without expecting any advanced features.
 * </p>
 */
void copyLinks(PdfStamper stamper, int targetPage, PdfReader reader, int sourcePage)
{
    PdfDictionary sourcePageDict = reader.getPageNRelease(sourcePage);
    PdfArray annotations = sourcePageDict.getAsArray(PdfName.ANNOTS);
    if (annotations != null && annotations.size() > 0)
    {
        for (PdfObject annotationObject : annotations)
        {
            annotationObject = PdfReader.getPdfObject(annotationObject);
            if (!annotationObject.isDictionary())
                continue;
            PdfDictionary annotation = (PdfDictionary) annotationObject;
            if (!PdfName.LINK.equals(annotation.getAsName(PdfName.SUBTYPE)))
                continue;

            PdfArray rectArray = annotation.getAsArray(PdfName.RECT);
            if (rectArray == null || rectArray.size() < 4)
                continue;
            Rectangle rectangle = PdfReader.getNormalizedRectangle(rectArray);

            PdfName hightLight = annotation.getAsName(PdfName.H);
            if (hightLight == null)
                hightLight = PdfAnnotation.HIGHLIGHT_INVERT;

            PdfDictionary actionDict = annotation.getAsDict(PdfName.A);
            if (actionDict == null || !PdfName.URI.equals(actionDict.getAsName(PdfName.S)))
                continue;
            PdfString urlPdfString = actionDict.getAsString(PdfName.URI);
            if (urlPdfString == null)
                continue;
            PdfAction action = new PdfAction(urlPdfString.toString());

            PdfAnnotation link = PdfAnnotation.createLink(stamper.getWriter(), rectangle, hightLight, action);
            stamper.addAnnotation(link, targetPage);
        }
    }
}
 
开发者ID:mkl-public,项目名称:testarea-itext5,代码行数:49,代码来源:InsertPage.java

示例3: extractSignatures

import com.itextpdf.text.pdf.PdfDictionary; //导入方法依赖的package包/类
/**
 * This method extracts integrated signature information from the PDF
 * this class is instantiated with.
 * @return
 */
//@SuppressWarnings("unchecked")
public Map<String, SignatureData> extractSignatures()
{
    final Map<String, SignatureData> result = new HashMap<String, SignatureData>();
    final AcroFields fields = reader.getAcroFields();
    for (String name: fields.getSignatureNames())
    {
        PdfDictionary sigDict = fields.getSignatureDictionary(name); 
        PdfString contents = sigDict.getAsString(PdfName.CONTENTS);
        PdfName subFilter = sigDict.getAsName(PdfName.SUBFILTER);
        if (contents != null)
        {
            byte[] contentBytes = contents.getOriginalBytes();
            byte[] containerBytes = null;
            /*
            ContentInfo contentInfo = null;
            try {
                contentInfo = new ContentInfoImpl(contentBytes);
                byte[] bytes = contentInfo.getEncoded();
                if (bytes.length <= contentBytes.length)
                {
                    boolean equal = true;
                    for (int i = 0; i < bytes.length; i++)
                    {
                        if (bytes[i] != contentBytes[i])
                        {
                            System.err.println("Re-encoded differs at " + i);
                            equal = false;
                            break;
                        }
                    }
                    if (equal)
                        containerBytes = bytes;
                }
                else
                {
                    System.err.println("Re-encoded data too long");
                }
            }
            catch (GeneralSecurityException e)
            {
                System.err.println("Failure decoding content as container.");
                e.printStackTrace();
            }
            */

            Date signingTime = null;
            Object pdfDateEntry = sigDict.get(PdfName.M);
            if (pdfDateEntry != null)
            {
                Calendar cal = PdfDate.decode(pdfDateEntry.toString());
                if (cal != null)
                {
                    signingTime = cal.getTime();
                }
            }

            result.put(name, new SignatureData(/*contentInfo,*/ containerBytes, contentBytes, subFilter, signingTime));
        }
    }
    return result;
}
 
开发者ID:mkl-public,项目名称:testarea-itext5,代码行数:68,代码来源:SignatureExtractor.java

示例4: inspectChildDictionary

import com.itextpdf.text.pdf.PdfDictionary; //导入方法依赖的package包/类
/**
 * 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
 */
@Override
public void inspectChildDictionary(PdfDictionary k, boolean inspectAttributes) throws IOException {
    if (k == null)
        return;
    PdfName s = k.getAsName(PdfName.S);
    if (s != null) {
        String tagN = PdfName.decodeName(s.toString());
        String tag;
        if (roleMap != null && roleMap.get(new PdfName(tagN)) != null) {
            tag = roleMap.get(new PdfName(tagN)).toString().substring(1);
        } else {
            tag = fixTagName(tagN);
        }
        out.print("<");
        out.print(tag);
        if (inspectAttributes) {
            PdfDictionary a = k.getAsDict(PdfName.A);
            if (a != null) {
                Set<PdfName> keys =  a.getKeys();
                for (PdfName key : keys) {
                    out.print(' ');
                    PdfObject value = a.get(key);
                    value = PdfReader.getPdfObject(value);
                    out.print(xmlName(key));
                    out.print("=\"");
                    out.print(XMLUtil.escapeXML(value.toString(), false));
                    out.print("\"");
                }
            }
        }
        out.println(">");
        PdfObject alt = k.get(PdfName.ALT);
        if (alt != null && alt.toString() != null) {
            out.print("<alt><![CDATA[");
            out.print(alt.toString().replaceAll("[\\000]*", ""));
            out.print("]]></alt>");
        }
        PdfDictionary dict = k.getAsDict(PdfName.PG);
        if (dict != null)
            parseTag(tagN, k.getDirectObject(PdfName.K), dict);
        inspectChild(k.getDirectObject(PdfName.K));
        out.print("</");
        out.print(tag);
        out.println(">");
    } else
        inspectChild(k.getDirectObject(PdfName.K));
}
 
开发者ID:mrniket,项目名称:pdftagger,代码行数:55,代码来源:MyTaggedPdfReaderTool.java


注:本文中的com.itextpdf.text.pdf.PdfDictionary.getAsName方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。