Java Code Examples for org.apache.pdfbox.contentstream.operator.Operator#getName()
The following examples show how to use
org.apache.pdfbox.contentstream.operator.Operator#getName() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: PDDefaultAppearanceString.java From gcs with Mozilla Public License 2.0 | 6 votes |
/** * This is used to handle an operation. * * @param operator The operation to perform. * @param operands The list of arguments. * @throws IOException If there is an error processing the operation. */ private void processOperator(Operator operator, List<COSBase> operands) throws IOException { String name = operator.getName(); if (OperatorName.SET_FONT_AND_SIZE.equals(name)) { processSetFont(operands); } else if (OperatorName.NON_STROKING_GRAY.equals(name)) { processSetFontColor(operands); } else if (OperatorName.NON_STROKING_RGB.equals(name)) { processSetFontColor(operands); } else if (OperatorName.NON_STROKING_CMYK.equals(name)) { processSetFontColor(operands); } }
Example 2
Source File: PDFStreamEngine.java From gcs with Mozilla Public License 2.0 | 6 votes |
/** * This is used to handle an operation. * * @param operator The operation to perform. * @param operands The list of arguments. * @throws IOException If there is an error processing the operation. */ protected void processOperator(Operator operator, List<COSBase> operands) throws IOException { String name = operator.getName(); OperatorProcessor processor = operators.get(name); if (processor != null) { processor.setContext(this); try { processor.process(operator, operands); } catch (IOException e) { operatorException(operator, operands, e); } } else { unsupportedOperator(operator, operands); } }
Example 3
Source File: ImageExtractor.java From inception with Apache License 2.0 | 5 votes |
@Override protected void processOperator(Operator operator, List<COSBase> operands) throws IOException { String operation = operator.getName(); if ("Do".equals(operation)) { COSName objectName = (COSName) operands.get(0); PDXObject xobject = getResources().getXObject(objectName); if (xobject instanceof PDImageXObject) { PDImageXObject image = (PDImageXObject) xobject; Matrix ctmNew = getGraphicsState().getCurrentTransformationMatrix(); PDRectangle pageRect = this.getCurrentPage().getCropBox(); float w = ctmNew.getScalingFactorX(); float h = ctmNew.getScalingFactorY(); float x = ctmNew.getTranslateX(); float y = pageRect.getHeight() - ctmNew.getTranslateY() - h; buffer.add(new ImageOperator(x, y, w, h)); } else if (xobject instanceof PDFormXObject) { PDFormXObject form = (PDFormXObject) xobject; showForm(form); } } else { super.processOperator(operator, operands); } }
Example 4
Source File: EditPageContent.java From testarea-pdfbox2 with Apache License 2.0 | 5 votes |
/** * <a href="http://stackoverflow.com/questions/38498431/how-to-remove-filtered-content-from-a-pdf-with-itext"> * How to remove filtered content from a PDF with iText * </a> * <br/> * <a href="https://1drv.ms/b/s!AmNST-TRoPSemi2k0UnGFsjQM1Yt"> * document.pdf * </a> * <p> * This test shows how to remove text filtered by actual font size. * </p> */ @Test public void testRemoveBigTextDocument() throws IOException { try ( InputStream resource = getClass().getResourceAsStream("document.pdf"); PDDocument document = Loader.loadPDF(resource)) { for (PDPage page : document.getDocumentCatalog().getPages()) { PdfContentStreamEditor identity = new PdfContentStreamEditor(document, page) { @Override protected void write(ContentStreamWriter contentStreamWriter, Operator operator, List<COSBase> operands) throws IOException { String operatorString = operator.getName(); if (TEXT_SHOWING_OPERATORS.contains(operatorString)) { float fs = getGraphicsState().getTextState().getFontSize(); Matrix matrix = getTextMatrix().multiply(getGraphicsState().getCurrentTransformationMatrix()); Point2D.Float transformedFsVector = matrix.transformPoint(0, fs); Point2D.Float transformedOrigin = matrix.transformPoint(0, 0); double transformedFs = transformedFsVector.distance(transformedOrigin); if (transformedFs > 100) return; } super.write(contentStreamWriter, operator, operands); } final List<String> TEXT_SHOWING_OPERATORS = Arrays.asList("Tj", "'", "\"", "TJ"); }; identity.processPage(page); } document.save(new File(RESULT_FOLDER, "document-noBigText.pdf")); } }
Example 5
Source File: EditPageContent.java From testarea-pdfbox2 with Apache License 2.0 | 5 votes |
/** * <a href="https://stackoverflow.com/questions/61202822/remove-large-tokens-from-pdf-using-pdfbox-or-equivalent-library"> * Remove Large Tokens from PDF using PDFBox or equivalent library * </a> * <br/> * <a href="https://drive.google.com/file/d/184waC6PjjDi8yolIZN5R-6vgWGR5SvKl/view?usp=sharing"> * kommers_annons_elite.pdf * </a> * <p> * This test shows how to remove text filtered by actual font size. * </p> */ @Test public void testRemoveBigTextKommersAnnonsElite() throws IOException { try ( InputStream resource = getClass().getResourceAsStream("kommers_annons_elite.pdf"); PDDocument document = Loader.loadPDF(resource)) { PDPage page = document.getPage(0); PdfContentStreamEditor editor = new PdfContentStreamEditor(document, page) { @Override protected void write(ContentStreamWriter contentStreamWriter, Operator operator, List<COSBase> operands) throws IOException { String operatorString = operator.getName(); if (TEXT_SHOWING_OPERATORS.contains(operatorString)) { float fs = getGraphicsState().getTextState().getFontSize(); Matrix matrix = getTextMatrix().multiply(getGraphicsState().getCurrentTransformationMatrix()); Point2D.Float transformedFsVector = matrix.transformPoint(0, fs); Point2D.Float transformedOrigin = matrix.transformPoint(0, 0); double transformedFs = transformedFsVector.distance(transformedOrigin); if (transformedFs > 50) return; } super.write(contentStreamWriter, operator, operands); } final List<String> TEXT_SHOWING_OPERATORS = Arrays.asList("Tj", "'", "\"", "TJ"); }; editor.processPage(page); document.save(new File(RESULT_FOLDER, "kommers_annons_elite-noBigText.pdf")); } }
Example 6
Source File: ExtractImageLocations.java From testarea-pdfbox2 with Apache License 2.0 | 5 votes |
@Override protected void processOperator(Operator operator, List<COSBase> operands) throws IOException { String operation = operator.getName(); if (fillOperations.contains(operation)) { PDColor color = getGraphicsState().getNonStrokingColor(); PDAbstractPattern pattern = getResources().getPattern(color.getPatternName()); if (pattern instanceof PDTilingPattern) { processTilingPattern((PDTilingPattern) pattern, null, null); } } super.processOperator(operator, operands); }