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


Java PDStream类代码示例

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


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

示例1: removeText

import org.apache.pdfbox.pdmodel.common.PDStream; //导入依赖的package包/类
private PDDocument removeText(PDPage page) throws IOException {

        PDFStreamParser parser = new PDFStreamParser(page);
        parser.parse();
        List<Object> tokens = parser.getTokens();
        List<Object> newTokens = new ArrayList<>();
        for (Object token : tokens) {
            if (token instanceof Operator) {
                Operator op = (Operator) token;
                if (op.getName().equals("TJ") || op.getName().equals("Tj")) {
                    //remove the one argument to this operator
                    newTokens.remove(newTokens.size() - 1);
                    continue;
                }
            }
            newTokens.add(token);
        }

        PDDocument document = new PDDocument();
        document.addPage(page);

        PDStream newContents = new PDStream(document);
        OutputStream out = newContents.createOutputStream(COSName.FLATE_DECODE);
        ContentStreamWriter writer = new ContentStreamWriter(out);
        writer.writeTokens(newTokens);
        out.close();
        page.setContents(newContents);

        return document;

    }
 
开发者ID:redmyers,项目名称:484_P7_1-Java,代码行数:32,代码来源:NurminenDetectionAlgorithm.java

示例2: createAppearanceStream

import org.apache.pdfbox.pdmodel.common.PDStream; //导入依赖的package包/类
PDAppearanceStream createAppearanceStream(PDDocument document, float width, PDFont font, String backColorSettingOperation) throws IOException
{
    PDResources pdResources = new PDResources();
    String fontName = pdResources.addFont(font);
    PDStream pdStream = new PDStream(document);
    OutputStream os = pdStream.createOutputStream();
    String streamToBe = backColorSettingOperation + " 0 -5 " + width + " 25 re f /" + fontName + " 18 Tf 0 g BT (PDFBox) Tj ET";
    os.write(streamToBe.getBytes());
    os.close();
    
    PDXObjectForm xobject = new PDXObjectForm(pdStream);
    xobject.setResources(pdResources);
    xobject.setBBox(new PDRectangle(new BoundingBox(0, -5, width, 20)));
    xobject.setFormType(1);
    PDAppearanceStream normal = new PDAppearanceStream(xobject.getCOSStream());
    return normal;
}
 
开发者ID:mkl-public,项目名称:testarea-pdfbox1,代码行数:18,代码来源:RolloverAnnotation.java

示例3: buildImgKeyToPolNameMapping

import org.apache.pdfbox.pdmodel.common.PDStream; //导入依赖的package包/类
private static void buildImgKeyToPolNameMapping(PDPage page) throws IOException {
    PDStream contents = page.getContents();
    PDFStreamParser parser = new PDFStreamParser(contents.getStream());
    parser.parse();
    List tokens = parser.getTokens();

    boolean concatStringPhase = false;
    String polName = "";
    String lastText = "";

    for (int index = 0; index < tokens.size(); index++) {
        Object obj = tokens.get(index);

        if (obj instanceof PDFOperator) {
            PDFOperator op = (PDFOperator) obj;
            if (op.getOperation().equals("BT")) {
                concatStringPhase = true;
                polName = lastText;
                lastText = "";
            }
            else if (op.getOperation().equals("ET")) {
                concatStringPhase = false;
            }
        }
        else if (concatStringPhase && obj instanceof COSString) {
            COSString cosString = (COSString) obj;
            lastText += " " + cosString.getString();
            lastText = lastText.trim();
        }
        else if (!concatStringPhase && obj instanceof COSName) {
            COSName cosName = (COSName) obj;
            if (cosName.getName().startsWith("img")) {
                mapImgKeyToPolName.put(cosName.getName(), polName);
            }
        }
    }
}
 
开发者ID:TekkLabs,项目名称:memoria-politica,代码行数:38,代码来源:FedDepPhotosUtility.java

示例4: init

import org.apache.pdfbox.pdmodel.common.PDStream; //导入依赖的package包/类
@Override
public void init(RunConfig config) throws InvalidTestFormatException {
	super.init(config);
	File file = new File(GR.getGoldenDir(), goldenFileName);
	try {
		PDDocument doc = PDDocument.load(MTTestResourceManager.goldenFileToByteArray(file.getPath()));
		Iterator<PDPage> pageIt = doc.getPages().iterator();
		content = new ArrayList<byte[]>();
		while (pageIt.hasNext()) {
			PDPage page = (PDPage) pageIt.next();
			Iterator<PDStream> streamIt = page.getContentStreams();
			while (streamIt.hasNext()) {
			    PDStream stream = (PDStream) streamIt.next();
			    content.add(stream.toByteArray());
			}
		}
		doc.close();
	} catch (IOException e) {
		throw new InvalidTestFormatException ("file not found " + e.getMessage() + " " + file.getAbsolutePath(), this.getClass());
	}
}
 
开发者ID:android-workloads,项目名称:JACWfA,代码行数:22,代码来源:Parser.java

示例5: processPages

import org.apache.pdfbox.pdmodel.common.PDStream; //导入依赖的package包/类
/**
 * This will process all of the pages and the text that is in them.
 *
 * @param pages The pages object in the document.
 *
 * @throws IOException If there is an error parsing the text.
 */
protected void processPages( List<COSObjectable> pages ) throws IOException
{
    if( startBookmark != null )
    {
        startBookmarkPageNumber = getPageNumber( startBookmark, pages );
    }
    if( endBookmark != null )
    {
        endBookmarkPageNumber = getPageNumber( endBookmark, pages );
    }

    if( startBookmarkPageNumber == -1 && startBookmark != null &&
            endBookmarkPageNumber == -1 && endBookmark != null &&
            startBookmark.getCOSObject() == endBookmark.getCOSObject() )
    {
        //this is a special case where both the start and end bookmark
        //are the same but point to nothing.  In this case
        //we will not extract any text.
        startBookmarkPageNumber = 0;
        endBookmarkPageNumber = 0;
    }
    Iterator<COSObjectable> pageIter = pages.iterator();
    while( pageIter.hasNext() )
    {
        PDPage nextPage = (PDPage)pageIter.next();
        PDStream contentStream = nextPage.getContents();
        currentPageNo++;
        if( contentStream != null )
        {
            COSStream contents = contentStream.getStream();
            processPage( nextPage, contents );
        }
    }
}
 
开发者ID:hemangandhi,项目名称:my-cv-site,代码行数:42,代码来源:FormattedReader.java

示例6: clipPage

import org.apache.pdfbox.pdmodel.common.PDStream; //导入依赖的package包/类
void clipPage(PDDocument document, PDPage page, BoundingBox clipBox) throws IOException
{
	PDPageContentStream pageContentStream = new PDPageContentStream(document, page, true, false);
	pageContentStream.addRect(clipBox.getLowerLeftX(), clipBox.getLowerLeftY(), clipBox.getWidth(), clipBox.getHeight());
	pageContentStream.clipPath(PathIterator.WIND_NON_ZERO);
	pageContentStream.close();

	COSArray newContents = new COSArray();
	COSStreamArray contents = (COSStreamArray) page.getContents().getStream();
	newContents.add(contents.get(contents.getStreamCount()-1));
	for (int i = 0; i < contents.getStreamCount()-1; i++)
	{
		newContents.add(contents.get(i));
	}
	page.setContents(new PDStream(new COSStreamArray(newContents)));
}
 
开发者ID:mkl-public,项目名称:testarea-pdfbox1,代码行数:17,代码来源:ClipPage.java

示例7: testPrintPathsEmpsit8

import org.apache.pdfbox.pdmodel.common.PDStream; //导入依赖的package包/类
/**
 * <a href="http://stackoverflow.com/questions/35409283/how-to-find-table-border-lines-in-pdf-using-pdfbox">
 * How to find table border lines in pdf using PDFBox?
 * </a>
 * <br/>
 * <a href="http://stats.bls.gov/news.release/pdf/empsit.pdf">empsit.pdf</a>
 * <p>
 * This test uses the {@link PrintPaths} class to print the lines from page 8
 * of the sample document.
 * </p>
 */
@Test
public void testPrintPathsEmpsit8() throws IOException
{
    System.out.println("*\n*\n* File empsit.pdf\n*\n*");
    try (   InputStream resource = getClass().getResourceAsStream("empsit.pdf") )
    {
        PDDocument document = PDDocument.load(resource);
        List<?> allPages = document.getDocumentCatalog().getAllPages();
        int i = 7; // page 8

        System.out.println("\n\nPage " + (i+1));
        PrintPaths printPaths = new PrintPaths();

        PDPage page = (PDPage) allPages.get(i);
        PDStream contents = page.getContents();
        if (contents != null)
        {
            printPaths.processStream(page, page.findResources(), page.getContents().getStream());
        }
    }
}
 
开发者ID:mkl-public,项目名称:testarea-pdfbox1,代码行数:33,代码来源:ExtractPaths.java

示例8: testPrintPathsh81

import org.apache.pdfbox.pdmodel.common.PDStream; //导入依赖的package包/类
/**
 * <a href="http://stackoverflow.com/questions/35409283/how-to-find-table-border-lines-in-pdf-using-pdfbox">
 * How to find table border lines in pdf using PDFBox?
 * </a>
 * <br/>
 * <a href="https://drive.google.com/file/d/0B9q9YK3qNDvxX0lzcGVuejRRbHc/view?usp=sharing">h8.pdf</a>
 * <p>
 * This test uses the {@link PrintPaths} class to print the lines from page 1
 * of the new sample document referenced in a comment.
 * </p>
 */
@Test
public void testPrintPathsh81() throws IOException
{
    System.out.println("*\n*\n* File h8.pdf\n*\n*");
    try (   InputStream resource = getClass().getResourceAsStream("h8.pdf") )
    {
        PDDocument document = PDDocument.load(resource);
        List<?> allPages = document.getDocumentCatalog().getAllPages();
        int i = 0; // page 1

        System.out.println("\n\nPage " + (i+1));
        PrintPaths printPaths = new PrintPaths();

        PDPage page = (PDPage) allPages.get(i);
        PDStream contents = page.getContents();
        if (contents != null)
        {
            printPaths.processStream(page, page.findResources(), page.getContents().getStream());
        }
    }
}
 
开发者ID:mkl-public,项目名称:testarea-pdfbox1,代码行数:33,代码来源:ExtractPaths.java

示例9: loadOtherTypeFont

import org.apache.pdfbox.pdmodel.common.PDStream; //导入依赖的package包/类
private byte[] loadOtherTypeFont(PDStream fontFile) throws IOException
{
    // Likley Bare CFF which needs to be converted to a font supported by browsers, can be
    // other font types which are not yet supported.
    try
    {
        FVFont font = FontVerter.convertFont(fontFile.toByteArray(), FontVerter.FontFormat.WOFF1);
        mimeType = "application/x-font-woff";
        fileEnding = font.getProperties().getFileEnding();

        return font.getData();
    } catch (Exception ex) {
        log.error("Issue converting Bare CFF font or the font type is not supportedby Pdf2Dom, " +
                "Font: {} Exception: {} {}", fontName, ex.getMessage(), ex.getClass());

        // don't barf completley for font conversion issue, html will still be useable without.
        return new byte[0];
    }
}
 
开发者ID:radkovo,项目名称:Pdf2Dom,代码行数:20,代码来源:FontTable.java

示例10: processPages

import org.apache.pdfbox.pdmodel.common.PDStream; //导入依赖的package包/类
protected void processPages(List<COSObjectable> pages) throws IOException
{
    if (startBookmark != null)
    {
        startBookmarkPageNumber = getPageNumber(startBookmark, pages);
    }

    if (endBookmark != null)
    {
        endBookmarkPageNumber = getPageNumber(endBookmark, pages);
    }

    if (startBookmarkPageNumber == -1 && startBookmark != null &&
            endBookmarkPageNumber == -1 && endBookmark != null &&
            startBookmark.getCOSObject() == endBookmark.getCOSObject())
    {
        //this is a special case where both the start and end bookmark
        //are the same but point to nothing.  In this case
        //we will not extract any getText.
        startBookmarkPageNumber = 0;
        endBookmarkPageNumber = 0;
    }

    for (COSObjectable page : pages)
    {
        PDPage nextPage = (PDPage) page;
        PDStream contentStream = nextPage.getContents();
        currentPageNo++;
        if (contentStream != null)
        {
            COSStream contents = contentStream.getStream();
            processPage(nextPage, contents);
        }
    }
}
 
开发者ID:nemausus,项目名称:research-paper-parser,代码行数:36,代码来源:PDFParser.java

示例11: hasText

import org.apache.pdfbox.pdmodel.common.PDStream; //导入依赖的package包/类
private static boolean hasText(PDPage page) throws IOException {

        PDStream contents = page.getContents();
        PDFStreamParser parser = new PDFStreamParser(contents.getStream());
        parser.parse();
        List tokens = parser.getTokens();

        for (Object next : tokens) {
            if (next instanceof PDFOperator) {
                PDFOperator op = (PDFOperator) next;

                if (op.getOperation().equalsIgnoreCase(Consts.PDFMetadata.TEXT_OPERATOR)) {
                    return true;
                }
            }
        }
        return false;
    }
 
开发者ID:nandosola,项目名称:trantor-pdf-converter,代码行数:19,代码来源:PdfDoc.java

示例12: removeBlueRectangles

import org.apache.pdfbox.pdmodel.common.PDStream; //导入依赖的package包/类
/**
 * This document removes all blue filled rectangles. As the sample document
 * only uses RGB colors, actually only uses "rg" to set the blue fill color,
 * the code could be somewhat simplified.
 */
void removeBlueRectangles(PDDocument document) throws IOException
{
    List<?> pages = document.getDocumentCatalog().getAllPages();
    for (int i = 0; i < pages.size(); i++)
    {
        PDPage page = (PDPage) pages.get(i);
        PDStream contents = page.getContents();

        PDFStreamParser parser = new PDFStreamParser(contents.getStream()); 
        parser.parse();
        List<Object> tokens = parser.getTokens();  

        Stack<Boolean> blueState = new Stack<Boolean>();
        blueState.push(false);

        for (int j = 0; j < tokens.size(); j++)  
        {  
            Object next = tokens.get(j);
            if (next instanceof PDFOperator)
            {
                PDFOperator op = (PDFOperator) next;  
                if (op.getOperation().equals("q"))
                {
                    blueState.push(blueState.peek());
                }
                else if (op.getOperation().equals("Q"))
                {
                    blueState.pop();
                }
                else if (op.getOperation().equals("rg"))
                {
                    if (j > 2)
                    {
                        Object r = tokens.get(j-3);
                        Object g = tokens.get(j-2);
                        Object b = tokens.get(j-1);
                        if (r instanceof COSNumber && g instanceof COSNumber && b instanceof COSNumber)
                        {
                            blueState.pop();
                            blueState.push((
                                    Math.abs(((COSNumber)r).floatValue() - 0) < 0.001 &&
                                    Math.abs(((COSNumber)g).floatValue() - 0) < 0.001 &&
                                    Math.abs(((COSNumber)b).floatValue() - 1) < 0.001));
                        }
                    }
                }
                else if (op.getOperation().equals("f"))
                {
                    if (blueState.peek() && j > 0)
                    {
                        Object re = tokens.get(j-1);
                        if (re instanceof PDFOperator && ((PDFOperator)re).getOperation().equals("re"))
                        {
                            tokens.set(j, PDFOperator.getOperator("n"));
                        }
                    }
                }
            }
        }

        PDStream updatedStream = new PDStream(document);  
        OutputStream out = updatedStream.createOutputStream();  
        ContentStreamWriter tokenWriter = new ContentStreamWriter(out);  
        tokenWriter.writeTokens(tokens);  
        page.setContents(updatedStream);
    }
}
 
开发者ID:mkl-public,项目名称:testarea-pdfbox1,代码行数:73,代码来源:RemoveUnderlines.java

示例13: importAsXObject

import org.apache.pdfbox.pdmodel.common.PDStream; //导入依赖的package包/类
public static PDXObjectForm importAsXObject(PDDocument target, PDPage page) throws IOException
{
    final PDStream xobjectStream = new PDStream(target, page.getContents().createInputStream(), false);
    final PDXObjectForm xobject = new PDXObjectForm(xobjectStream);

    xobject.setResources(page.findResources());
    xobject.setBBox(page.findCropBox());

    COSDictionary group = new COSDictionary();
    group.setName("S", "Transparency");
    group.setBoolean(COSName.getPDFName("K"), true);
    xobject.getCOSStream().setItem(COSName.getPDFName("Group"), group);

    return xobject;
}
 
开发者ID:mkl-public,项目名称:testarea-pdfbox1,代码行数:16,代码来源:OverlayWithEffect.java

示例14: testDrunkenfistOriginal

import org.apache.pdfbox.pdmodel.common.PDStream; //导入依赖的package包/类
/**
 * <a href="http://stackoverflow.com/questions/29220165/editing-content-in-pdf-using-pdfbox-removes-last-line-from-pdf">
 * Editing content in pdf using PDFBox removes last line from pdf
 * </a>
 * 
 * Reproducing the issue.
 */
@Test
public void testDrunkenfistOriginal() throws IOException, COSVisitorException
{
    try (   InputStream originalStream = getClass().getResourceAsStream("Original.pdf") )
    {
        PDDocument doc = PDDocument.load(originalStream);
        PDPage page = (PDPage) doc.getDocumentCatalog().getAllPages().get(0);
        PDStream contents = page.getContents();
        PDFStreamParser parser = new PDFStreamParser(contents.getStream());
        parser.parse();
        List<Object> tokens = parser.getTokens();
        for (int j = 0; j < tokens.size(); j++) {
            Object next = tokens.get(j);
            if (next instanceof PDFOperator) {
                PDFOperator op = (PDFOperator) next;
                if (op.getOperation().equals("Tj")) {
                    COSString previous = (COSString) tokens.get(j - 1);
                    String string = previous.getString();

                    string = string.replace("@ordnum&", "-ORDERNR-");
                    string = string.replace("@shipid&", "-SHIPMENTID-");
                    string = string.replace("@customer&", "-CUSTOMERNR-");
                    string = string.replace("@fromname&", "-FROMNAME-");

                    tokens.set(j - 1, new COSString(string.trim()));
                }
            }
        }

        PDStream updatedStream = new PDStream(doc);  
        OutputStream out = updatedStream.createOutputStream();  
        ContentStreamWriter tokenWriter = new ContentStreamWriter(out);  
        tokenWriter.writeTokens(tokens);  
        page.setContents(updatedStream);
        
        doc.save(new File(RESULT_FOLDER, "Original-edited.pdf"));
        doc.close();
    }
}
 
开发者ID:mkl-public,项目名称:testarea-pdfbox1,代码行数:47,代码来源:NaiveContentEdit.java

示例15: importAsXObject

import org.apache.pdfbox.pdmodel.common.PDStream; //导入依赖的package包/类
PDXObjectForm importAsXObject(PDDocument target, PDPage page) throws IOException
{
    final PDStream xobjectStream = new PDStream(target, page.getContents().createInputStream(), false);
    final PDXObjectForm xobject = new PDXObjectForm(xobjectStream);

    xobject.setResources(page.findResources());
    xobject.setBBox(page.findCropBox());

    COSDictionary group = new COSDictionary();
    group.setName("S", "Transparency");
    group.setBoolean(COSName.getPDFName("K"), true);
    xobject.getCOSStream().setItem(COSName.getPDFName("Group"), group);

    return xobject;
}
 
开发者ID:mkl-public,项目名称:testarea-pdfbox1,代码行数:16,代码来源:OverlayWithEffect.java


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