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


Java PdfDictionary.getAsDict方法代码示例

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


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

示例1: extractAttachments

import com.itextpdf.text.pdf.PdfDictionary; //导入方法依赖的package包/类
/**
 * These two methods ({@link #extractAttachments(PdfReader, String)} and
 * {@link #extractAttachment(PdfReader, File, PdfString, PdfDictionary)})
 * essentially are the OP's original code posted in his question. They
 * extract files without the folder structure.
 */
public static void extractAttachments(PdfReader reader, String dir) throws IOException
{
    File folder = new File(dir);
    folder.mkdirs();

    PdfDictionary root = reader.getCatalog();

    PdfDictionary names = root.getAsDict(PdfName.NAMES);
    System.out.println("" + names.getKeys().toString());
    PdfDictionary embedded = names.getAsDict(PdfName.EMBEDDEDFILES);
    System.out.println("" + embedded.toString());

    PdfArray filespecs = embedded.getAsArray(PdfName.NAMES);

    //System.out.println(filespecs.getAsString(root1));
    for (int i = 0; i < filespecs.size();)
    {
        extractAttachment(reader, folder, filespecs.getAsString(i++), filespecs.getAsDict(i++));
    }
}
 
开发者ID:mkl-public,项目名称:testarea-itext5,代码行数:27,代码来源:PortfolioFileExtraction.java

示例2: extractAttachmentsWithFolders

import com.itextpdf.text.pdf.PdfDictionary; //导入方法依赖的package包/类
/**
 * <p>
 * These two methods ({@link #extractAttachmentsWithFolders(PdfReader, String)} and
 * {@link #extractAttachment(PdfReader, Map, PdfString, PdfDictionary)}) extend the
 * functionality of the OP's original code posted in his question. They extract files
 * with the folder structure.
 * </p>
 * <p>
 * The information concerning the portfolio folder structure is retrieved using
 * the method {@link #retrieveFolders(PdfReader, File)} and its helper method
 * {@link #collectFolders(Map, PdfDictionary, File)}.
 * </p>
 */
public static void extractAttachmentsWithFolders(PdfReader reader, String dir) throws IOException, DocumentException
{
    File folder = new File(dir);
    folder.mkdirs();

    Map<Integer, File> folders = retrieveFolders(reader, folder);

    PdfDictionary root = reader.getCatalog();

    PdfDictionary names = root.getAsDict(PdfName.NAMES);
    System.out.println("" + names.getKeys().toString());
    PdfDictionary embedded = names.getAsDict(PdfName.EMBEDDEDFILES);
    System.out.println("" + embedded.toString());

    PdfArray filespecs = embedded.getAsArray(PdfName.NAMES);

    for (int i = 0; i < filespecs.size();)
    {
        extractAttachment(reader, folders, folder, filespecs.getAsString(i++), filespecs.getAsDict(i++));
    }
}
 
开发者ID:mkl-public,项目名称:testarea-itext5,代码行数:35,代码来源:PortfolioFileExtraction.java

示例3: retrieveFolders

import com.itextpdf.text.pdf.PdfDictionary; //导入方法依赖的package包/类
static Map<Integer, File> retrieveFolders(PdfReader reader, File baseDir) throws DocumentException
{
    Map<Integer, File> result = new HashMap<Integer, File>();

    PdfDictionary root = reader.getCatalog();
    PdfDictionary collection = root.getAsDict(PdfName.COLLECTION);
    if (collection == null)
        throw new DocumentException("Document has no Collection dictionary");
    PdfDictionary folders = collection.getAsDict(FOLDERS);
    if (folders == null)
        throw new DocumentException("Document collection has no folders dictionary");
    
    collectFolders(result, folders, baseDir);

    return result;
}
 
开发者ID:mkl-public,项目名称:testarea-itext5,代码行数:17,代码来源:PortfolioFileExtraction.java

示例4: 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

示例5: extractText

import com.itextpdf.text.pdf.PdfDictionary; //导入方法依赖的package包/类
/**
 * Extracts text from a PDF document.
 *
 * @param src the original PDF document
 * @throws java.io.IOException
 */
public List<Page> extractText(InputStream src) throws IOException {
    List<Page> pages = Lists.newArrayList();

    PdfReader reader = new PdfReader(src);
    RenderListener listener = new InternalListener();
    PdfContentStreamProcessor processor = new PdfContentStreamProcessor(listener);

    for (int i = 1; i <= reader.getNumberOfPages(); i++) {
        pages.add(currentPage = new Page());
        PdfDictionary pageDic = reader.getPageN(i);
        PdfDictionary resourcesDic = pageDic.getAsDict(PdfName.RESOURCES);
        processor.processContent(ContentByteUtils.getContentBytesForPage(reader, i), resourcesDic);
    }
    reader.close();

    return pages;
}
 
开发者ID:Arnauld,项目名称:gutenberg,代码行数:24,代码来源:TextStripper.java

示例6: convertToXml

import com.itextpdf.text.pdf.PdfDictionary; //导入方法依赖的package包/类
@Override
public void convertToXml(PdfReader reader, OutputStream os, String charset)
        throws IOException {
    this.reader = reader;
    OutputStreamWriter outs = new OutputStreamWriter(os, charset);
    out = new PrintWriter(outs);
    out.println("<Document>");
    // get the StructTreeRoot from the root object
    PdfDictionary catalog = reader.getCatalog();
    PdfDictionary struct = catalog.getAsDict(PdfName.STRUCTTREEROOT);
    roleMap = struct.getAsDict(PdfName.ROLEMAP);
    if (struct == null)
        throw new IOException(MessageLocalization.getComposedMessage("no.structtreeroot.found"));
    // Inspect the child or children of the StructTreeRoot
    inspectChild(struct.getDirectObject(PdfName.K));
    out.println("</Document>");
    out.flush();
    out.close();
}
 
开发者ID:mrniket,项目名称:pdftagger,代码行数:20,代码来源:MyTaggedPdfReaderTool.java

示例7: renderText

import com.itextpdf.text.pdf.PdfDictionary; //导入方法依赖的package包/类
@Override
public void renderText(TextRenderInfo renderInfo)
{
    DocumentFont font =renderInfo.getFont();
    PdfDictionary dict = font.getFontDictionary();
    PdfDictionary encoding = dict.getAsDict(PdfName.ENCODING);
    PdfArray diffs = encoding.getAsArray(PdfName.DIFFERENCES);

    ;
    StringBuilder builder = new StringBuilder();
    for (byte b : renderInfo.getPdfString().getBytes())
    {
        PdfName name = diffs.getAsName((char)b);
        String s = name.toString().substring(2);
        int i = Integer.parseUnsignedInt(s, 16);
        builder.append((char)i);
    }

    try
    {
        stringField.set(renderInfo, builder.toString());
    }
    catch (IllegalArgumentException | IllegalAccessException e)
    {
        e.printStackTrace();
    }
    strategy.renderText(renderInfo);
}
 
开发者ID:mkl-public,项目名称:testarea-itext5,代码行数:29,代码来源:RemappingExtractionFilter.java

示例8: 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

示例9: show

import com.itextpdf.text.pdf.PdfDictionary; //导入方法依赖的package包/类
void show(FdfReader fdfReader)
{
    PdfDictionary catalog = fdfReader.getCatalog();
    catalog = catalog.getAsDict(PdfName.FDF);
    Assert.assertNotNull("FDF catalogue is null", catalog);
    PdfArray annots = catalog.getAsArray(PdfName.ANNOTS);
    Assert.assertNotNull("FDF annotations are null", annots);
    System.out.println(annots);
}
 
开发者ID:mkl-public,项目名称:testarea-itext5,代码行数:10,代码来源:ReadFdf.java

示例10: testPbNoToUnicode

import com.itextpdf.text.pdf.PdfDictionary; //导入方法依赖的package包/类
/**
 * <a href="http://stackoverflow.com/questions/37748346/extract-text-with-itext-not-works-encoding-or-crypted-text">
 * Extract text with iText not works: encoding or crypted text?
 * </a>
 * <br/>
 * <a href="https://dl.dropboxusercontent.com/u/6413030/pb.pdf">
 * pb.pdf
 * </a>
 * <p>
 * The document has not been provided by the OP but by
 * <a href="http://stackoverflow.com/users/1127485/sschuberth">sschuberth</a>
 * in a comment.
 * </p>
 * <p>
 * In contrast to {@link #testPb()}, we here first remove the <b>ToUnicode</b>
 * tables of the fonts. And indeed, now extraction succeeds.
 * </p>
 */
@Test
public void testPbNoToUnicode() throws Exception
{
    InputStream resourceStream = getClass().getResourceAsStream("pb.pdf");
    try
    {
        PdfReader reader = new PdfReader(resourceStream);
        for (int i = 1; i <= reader.getNumberOfPages(); i++)
        {
            PdfDictionary pageResources = reader.getPageResources(i);
            if (pageResources == null)
                continue;
            PdfDictionary pageFonts = pageResources.getAsDict(PdfName.FONT); 
            if (pageFonts == null)
                continue;
            for (PdfName key : pageFonts.getKeys())
            {
                PdfDictionary fontDictionary = pageFonts.getAsDict(key);
                fontDictionary.put(PdfName.TOUNICODE, null);
            }
        }

        String content = extractAndStore(reader, new File(RESULT_FOLDER, "pb-noToUnicode.%s.txt").toString());

        System.out.println("\nText pb.pdf without ToUnicode\n************************");
        System.out.println(content);
        System.out.println("************************");
    }
    finally
    {
        if (resourceStream != null)
            resourceStream.close();
    }
}
 
开发者ID:mkl-public,项目名称:testarea-itext5,代码行数:53,代码来源:TextExtraction.java

示例11: collectFolders

import com.itextpdf.text.pdf.PdfDictionary; //导入方法依赖的package包/类
static void collectFolders(Map<Integer, File> collection, PdfDictionary folder, File baseDir)
{
    PdfString name = folder.getAsString(PdfName.NAME);
    File folderDir = new File(baseDir, name.toString());
    folderDir.mkdirs();
    PdfNumber id = folder.getAsNumber(PdfName.ID);
    collection.put(id.intValue(), folderDir);

    PdfDictionary next = folder.getAsDict(PdfName.NEXT);
    if (next != null)
        collectFolders(collection, next, baseDir);
    PdfDictionary child = folder.getAsDict(CHILD);
    if (child != null)
        collectFolders(collection, child, folderDir);
}
 
开发者ID:mkl-public,项目名称:testarea-itext5,代码行数:16,代码来源:PortfolioFileExtraction.java

示例12: getEmbeddedFilesDictionaries

import com.itextpdf.text.pdf.PdfDictionary; //导入方法依赖的package包/类
private Set<PdfDictionary> getEmbeddedFilesDictionaries(PdfReader reader) {
    Set<PdfDictionary> retSet = new NullSafeSet<PdfDictionary>();
    PdfDictionary catalog = reader.getCatalog();
    PdfDictionary names = catalog.getAsDict(PdfName.NAMES);
    if (names != null) {
        PdfDictionary embFiles = names.getAsDict(PdfName.EMBEDDEDFILES);
        if (embFiles != null) {
            HashMap<String, PdfObject> embMap = PdfNameTree.readTree(embFiles);
            for (PdfObject value : embMap.values()) {
                retSet.add((PdfDictionary) PdfReader.getPdfObject(value));
            }
        }
    }
    return retSet;
}
 
开发者ID:torakiki,项目名称:sejda-itext5,代码行数:16,代码来源:PdfUnpacker.java

示例13: getGraphicsStateDictionary

import com.itextpdf.text.pdf.PdfDictionary; //导入方法依赖的package包/类
PdfDictionary getGraphicsStateDictionary(PdfName gsName)
{
    PdfDictionary extGStates = resources.getAsDict(PdfName.EXTGSTATE);
    return extGStates.getAsDict(gsName);
}
 
开发者ID:mkl-public,项目名称:testarea-itext5,代码行数:6,代码来源:TransparentGraphicsRemover.java

示例14: testInsertTitlePage

import com.itextpdf.text.pdf.PdfDictionary; //导入方法依赖的package包/类
/**
 * <a href="http://stackoverflow.com/questions/28911509/how-to-retain-page-labels-when-concatenating-an-existing-pdf-with-a-pdf-created">
 * How to retain page labels when concatenating an existing pdf with a pdf created from scratch?
 * </a>
 * <p>
 * A proposal how to implement the task using a {@link PdfStamper}.
 */
@Test
public void testInsertTitlePage() throws IOException, DocumentException
{
    try (   InputStream documentStream = getClass().getResourceAsStream("Labels.pdf");
            InputStream titleStream = getClass().getResourceAsStream("Cover.pdf");
            OutputStream outputStream = new FileOutputStream(new File(RESULT_FOLDER, "labels-with-cover-page.pdf"))    )
    {
        PdfReader titleReader = new PdfReader(titleStream);
        PdfReader reader = new PdfReader(documentStream);
        PdfStamper stamper = new PdfStamper(reader, outputStream);

        PdfImportedPage page = stamper.getImportedPage(titleReader, 1);
        stamper.insertPage(1, titleReader.getPageSize(1));
        PdfContentByte content = stamper.getUnderContent(1);
        content.addTemplate(page, 0, 0);
        copyLinks(stamper, 1, titleReader, 1);

        PdfDictionary root = reader.getCatalog();
        PdfDictionary labels = root.getAsDict(PdfName.PAGELABELS);
        if (labels != null)
        {
            PdfArray newNums = new PdfArray();
            
            newNums.add(new PdfNumber(0));
            PdfDictionary coverDict = new PdfDictionary();
            coverDict.put(PdfName.P, new PdfString("Cover Page"));
            newNums.add(coverDict);

            PdfArray nums = labels.getAsArray(PdfName.NUMS);
            if (nums != null)
            {
                for (int i = 0; i < nums.size() - 1; )
                {
                    int n = nums.getAsNumber(i++).intValue();
                    newNums.add(new PdfNumber(n+1));
                    newNums.add(nums.getPdfObject(i++));
                }
            }

            labels.put(PdfName.NUMS, newNums);
            stamper.markUsed(labels);
        }

        stamper.close();
    }
}
 
开发者ID:mkl-public,项目名称:testarea-itext5,代码行数:54,代码来源:InsertPage.java

示例15: 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.getAsDict方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。