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


Java PDStream.createOutputStream方法代码示例

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


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

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


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