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


Java PdfDictionary类代码示例

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


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

示例1: testSwitchOrientation

import com.itextpdf.text.pdf.PdfDictionary; //导入依赖的package包/类
/**
 * <a href="http://stackoverflow.com/questions/34394199/i-cant-rotate-my-page-from-existing-pdf">
 * I can't rotate my page from existing PDF
 * </a>
 * <p>
 * Switching between portrait and landscape like this obviously will cut off some parts of the page.
 * </p>
 */
@Test
public void testSwitchOrientation() throws DocumentException, IOException
{
    try (InputStream resourceStream = getClass().getResourceAsStream("/mkl/testarea/itext5/extract/n2013.00849449.pdf"))
    {
        PdfReader reader = new PdfReader(resourceStream);
        int n = reader.getNumberOfPages();
        PdfDictionary pageDict;
        for (int i = 1; i <= n; i++) {
            Rectangle rect = reader.getPageSize(i);
            Rectangle crop = reader.getCropBox(i);
            pageDict = reader.getPageN(i);
            pageDict.put(PdfName.MEDIABOX, new PdfArray(new float[] {rect.getBottom(), rect.getLeft(), rect.getTop(), rect.getRight()}));
            pageDict.put(PdfName.CROPBOX, new PdfArray(new float[] {crop.getBottom(), crop.getLeft(), crop.getTop(), crop.getRight()}));
        }
        PdfStamper stamper = new PdfStamper(reader, new FileOutputStream(new File(RESULT_FOLDER, "n2013.00849449-switch.pdf")));
        stamper.close();
        reader.close();
    }
}
 
开发者ID:mkl-public,项目名称:testarea-itext5,代码行数:29,代码来源:SwitchPageCanvas.java

示例2: buildSignedPDF

import com.itextpdf.text.pdf.PdfDictionary; //导入依赖的package包/类
public byte[] buildSignedPDF(String digestOID, byte[] signature, byte[] hash) throws Exception {
    byte[] hashTmp = null;
    if (dateTime != null)
        hashTmp = hash;

    byte[] pkcs7enc = PKCS7Manager.buildPDFPKCS7(digestOID, x509Certificate, signature, hashTmp, dateTime);

    PdfDictionary dic = new PdfDictionary();
    PdfString contents = new PdfString(pkcs7enc).setHexWriting(true);

    contentsSize = contents.length();

    dic.put(PdfName.CONTENTS, contents);
    sap.close(dic);

    return bout.toByteArray();
}
 
开发者ID:damianofalcioni,项目名称:Websocket-Smart-Card-Signer,代码行数:18,代码来源:PDFManager.java

示例3: numberOfVisibleSignatureFieldsOnSignaturePage

import com.itextpdf.text.pdf.PdfDictionary; //导入依赖的package包/类
private int numberOfVisibleSignatureFieldsOnSignaturePage(AcroFields readerFields, ArrayList<String> signatureFieldsNames, int signaturePage) {
	int count = 0;
	for (String signatureFieldName : signatureFieldsNames) {
		Item i = readerFields.getFieldItem(signatureFieldName);
		int page = i.getPage(0);
		if(page == signaturePage){
			PdfDictionary pdct = i.getMerged(0); 
			PdfNumber flags = pdct.getAsNumber(PdfName.F); 
			if ((flags.intValue() & PdfAnnotation.FLAGS_HIDDEN) == 0) {
				count = count + 1;
			} 
		}
	}
	return count;
}
 
开发者ID:MatheusArleson,项目名称:PdfUtil,代码行数:16,代码来源:PdfSignerV4.java

示例4: testRemoveContent

import com.itextpdf.text.pdf.PdfDictionary; //导入依赖的package包/类
/**
 * <a href="http://stackoverflow.com/questions/43870545/filling-a-pdf-with-itextsharp-and-then-hiding-the-base-layer">
 * Filling a PDF with iTextsharp and then hiding the base layer
 * </a>
 * <p>
 * This test shows how to remove all content.
 * </p>
 */
@Test
public void testRemoveContent() throws IOException, DocumentException
{
    try (   InputStream resource = getClass().getResourceAsStream("document.pdf");
            OutputStream result = new FileOutputStream(new File(RESULT_FOLDER, "document-removedContent.pdf")))
    {
        PdfReader pdfReader = new PdfReader(resource);
        for (int page = 1; page <= pdfReader.getNumberOfPages(); page++)
        {
            PdfDictionary pageDictionary = pdfReader.getPageN(page);
            pageDictionary.remove(PdfName.CONTENTS);
        }
        new PdfStamper(pdfReader, result).close();
    }
}
 
开发者ID:mkl-public,项目名称:testarea-itext5,代码行数:24,代码来源:HideContent.java

示例5: FindImages

import com.itextpdf.text.pdf.PdfDictionary; //导入依赖的package包/类
/**
 * @see #testExtractImageLikeSteveB()
 */
private static List<BufferedImage> FindImages(PdfReader reader, PdfDictionary pdfPage) throws IOException
{
    List<BufferedImage> result = new ArrayList<>(); 
    Iterable<PdfObject> imgPdfObject = FindImageInPDFDictionary(pdfPage);
    for (PdfObject image : imgPdfObject)
    {
        int xrefIndex = ((PRIndirectReference)image).getNumber();
        PdfObject stream = reader.getPdfObject(xrefIndex);
        // Exception occurs here :
        PdfImageObject pdfImage = new PdfImageObject((PRStream)stream);
        BufferedImage img = pdfImage.getBufferedImage();

        // Do something with the image
        result.add(img);
    }
    return result;
}
 
开发者ID:mkl-public,项目名称:testarea-itext5,代码行数:21,代码来源:ImageExtraction.java

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

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

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

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

示例10: doExecute

import com.itextpdf.text.pdf.PdfDictionary; //导入依赖的package包/类
private void doExecute() throws TaskException, IOException {
    when(context.getTask(parameters)).thenReturn((Task) victimTask);
    victim.execute(parameters);
    PdfReader reader = getReaderFromResultStream("test_file.pdf");
    assertCreator(reader);
    assertEquals(PdfVersion.VERSION_1_7.getVersionAsCharacter(), reader.getPdfVersion());
    PdfDictionary catalog = PdfViewerPreferencesImp.getViewerPreferences(reader.getCatalog())
            .getViewerPreferences();
    assertEquals(PdfName.SIMPLEX, catalog.getAsName(PdfName.DUPLEX));
    assertEquals(PdfName.L2R, catalog.getAsName(PdfName.DIRECTION));
    assertEquals(PdfName.APPDEFAULT, catalog.getAsName(PdfName.PRINTSCALING));
    assertEquals(PdfName.USETHUMBS, catalog.getAsName(PdfName.NONFULLSCREENPAGEMODE));
    assertEquals(PdfBoolean.PDFTRUE, catalog.getAsBoolean(PdfName.CENTERWINDOW));
    assertEquals(PdfBoolean.PDFTRUE, catalog.getAsBoolean(PdfName.HIDEMENUBAR));
    assertEquals(PdfBoolean.PDFFALSE, catalog.getAsBoolean(PdfName.HIDETOOLBAR));
    reader.close();
}
 
开发者ID:torakiki,项目名称:sejda-itext5,代码行数:18,代码来源:ViewerPreferencesIText5TaskTest.java

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

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

示例13: tiff2Pdf

import com.itextpdf.text.pdf.PdfDictionary; //导入依赖的package包/类
public void tiff2Pdf(File singleTifFile, File pdfFile) {

		// based on tiff2pdf from itext toolbox 0.0.2
		// (cfr.http://itexttoolbox.sourceforge.net/doku.php?id=download&DokuWiki=
		// ecde1bfec0b8cca87dd8c6c042183992)
		try {
			RandomAccessFileOrArray ra = new RandomAccessFileOrArray(
					singleTifFile.getAbsolutePath());
			// RandomAccessFileOrArray ra = new
			// RandomAccessFileOrArray(tempByteArray);
			int comps = TiffImage.getNumberOfPages(ra);

			Document document = new Document(PageSize.A4);
			float width = PageSize.A4.getWidth();
			float height = PageSize.A4.getHeight();
			Image img = TiffImage.getTiffImage(ra, 1);

			document.setPageSize(PageSize.A4);

			PdfWriter writer = PdfWriter.getInstance(document,
					new FileOutputStream(pdfFile));

			// pdf/a
			// from
			// http://www.opensubscriber.com/message/[email protected]
			// .net/7593470.html

			// check that it is really pdf/a:
			// http://www.intarsys.de/produkte/pdf-a-live/pdf-a-check-1
			// => 2 warnings
			// Keine eindeutige ID gefunden
			// Kein History-Eintrag vorhanden
			writer.setPDFXConformance(PdfWriter.PDFA1B);
			document.open();

			PdfDictionary outi = new PdfDictionary(PdfName.OUTPUTINTENT);
			outi.put(PdfName.OUTPUTCONDITIONIDENTIFIER, new PdfString(
					"sRGB IEC61966-2.1"));
			outi.put(PdfName.INFO, new PdfString("sRGB IEC61966-2.1"));
			outi.put(PdfName.S, PdfName.GTS_PDFA1);
			ICC_Profile icc = ICC_Profile.getInstance(Thread.currentThread()
					.getContextClassLoader().getResourceAsStream(
							"/srgb.profile"));
			PdfICCBased ib = new PdfICCBased(icc);
			ib.remove(PdfName.ALTERNATE);
			outi.put(PdfName.DESTOUTPUTPROFILE, writer.addToBody(ib)
					.getIndirectReference());
			writer.getExtraCatalog().put(PdfName.OUTPUTINTENTS,
					new PdfArray(outi));

			PdfContentByte cb = writer.getDirectContent();
			for (int c = 0; c < comps; ++c) {
				img = TiffImage.getTiffImage(ra, c + 1);
				if (img != null) {
						document.setPageSize(PageSize.A4);
						document.newPage();
						img.setAbsolutePosition(0, 0);
						img.scaleToFit(width, height);
				
					cb.addImage(img);
					logger.debug("Finished page " + (c + 1));
				}
			}
			ra.close();

			writer.createXmpMetadata();// pdfa
			document.close();
		} catch (Throwable e) {
			// catch Throwable because we encountere a java.lang.InternalError
			// cfr. http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6503430
			// probably better to move to later java version for poller
			logger.error("Pdf not created", e);
		}
	}
 
开发者ID:xenit-eu,项目名称:move2alf,代码行数:75,代码来源:Tiff2Pdf.java

示例14: updateTransparencyFrom

import com.itextpdf.text.pdf.PdfDictionary; //导入依赖的package包/类
void updateTransparencyFrom(PdfName gsName)
{
    PdfDictionary extGState = getGraphicsStateDictionary(gsName);
    if (extGState != null)
    {
        PdfNumber number = extGState.getAsNumber(PdfName.ca);
        if (number != null)
            nonStrokingAlpha = number.floatValue();
        number = extGState.getAsNumber(PdfName.CA);
        if (number != null)
            strokingAlpha = number.floatValue();
    }
}
 
开发者ID:mkl-public,项目名称:testarea-itext5,代码行数:14,代码来源:TransparentGraphicsRemover.java

示例15: editPage

import com.itextpdf.text.pdf.PdfDictionary; //导入依赖的package包/类
/**
 * This method edits the immediate contents of a page, i.e. its content stream.
 * It explicitly does not descent into form xobjects, patterns, or annotations.
 */
public void editPage(PdfStamper pdfStamper, int pageNum) throws IOException
{
    PdfReader pdfReader = pdfStamper.getReader();
    PdfDictionary page = pdfReader.getPageN(pageNum);
    byte[] pageContentInput = ContentByteUtils.getContentBytesForPage(pdfReader, pageNum);
    page.remove(PdfName.CONTENTS);
    editContent(pageContentInput, page.getAsDict(PdfName.RESOURCES), pdfStamper.getUnderContent(pageNum));
}
 
开发者ID:mkl-public,项目名称:testarea-itext5,代码行数:13,代码来源:PdfContentStreamEditor.java


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