本文整理汇总了Java中org.apache.pdfbox.cos.COSBase类的典型用法代码示例。如果您正苦于以下问题:Java COSBase类的具体用法?Java COSBase怎么用?Java COSBase使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
COSBase类属于org.apache.pdfbox.cos包,在下文中一共展示了COSBase类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testRemoveLikeStephanImproved
import org.apache.pdfbox.cos.COSBase; //导入依赖的package包/类
/**
* <a href="https://stackoverflow.com/questions/45812696/pdfbox-delete-comment-maintain-strikethrough">
* PDFBox delete comment maintain strikethrough
* </a>
* <br/>
* <a href="https://expirebox.com/files/3d955e6df4ca5874c38dbf92fc43b5af.pdf">
* only_fields.pdf
* </a>
* <a href="https://file.io/DTvqhC">
* (alternative download)
* </a>
* <p>
* The OP only wanted the comment removed, not the strike-through. Thus, we must
* not remove the annotation but merely the comment building attributes.
* </p>
*/
@Test
public void testRemoveLikeStephanImproved() throws IOException {
final COSName POPUP = COSName.getPDFName("Popup");
try (InputStream resource = getClass().getResourceAsStream("only_fields.pdf")) {
PDDocument document = PDDocument.load(resource);
List<PDAnnotation> annotations = new ArrayList<>();
PDPageTree allPages = document.getDocumentCatalog().getPages();
List<COSObjectable> objectsToRemove = new ArrayList<>();
for (int i = 0; i < allPages.getCount(); i++) {
PDPage page = allPages.get(i);
annotations = page.getAnnotations();
for (PDAnnotation annotation : annotations) {
if ("StrikeOut".equals(annotation.getSubtype()))
{
COSDictionary annotationDict = annotation.getCOSObject();
COSBase popup = annotationDict.getItem(POPUP);
annotationDict.removeItem(POPUP);
annotationDict.removeItem(COSName.CONTENTS); // plain text comment
annotationDict.removeItem(COSName.RC); // rich text comment
annotationDict.removeItem(COSName.T); // author
if (popup != null)
objectsToRemove.add(popup);
}
}
annotations.removeAll(objectsToRemove);
}
document.save(new File(RESULT_FOLDER, "only_fields-removeImproved.pdf"));
}
}
示例2: process
import org.apache.pdfbox.cos.COSBase; //导入依赖的package包/类
@Override
public void process(Operator operator, List<COSBase> arguments)
throws IOException {
// set parameters from graphics state parameter dictionary
COSName dictName = (COSName) arguments.get(0);
PDExtendedGraphicsState gs = context.getResources().getExtGState(dictName);
gs.copyIntoGraphicsState(context.getGraphicsState());
}
示例3: process
import org.apache.pdfbox.cos.COSBase; //导入依赖的package包/类
@Override
public void process(Operator operator, List<COSBase> arguments)
throws IOException {
if (arguments.size() < 6) {
throw new MissingOperandException(operator, arguments);
}
// concatenate matrix to current transformation matrix
COSNumber a = (COSNumber) arguments.get(0);
COSNumber b = (COSNumber) arguments.get(1);
COSNumber c = (COSNumber) arguments.get(2);
COSNumber d = (COSNumber) arguments.get(3);
COSNumber e = (COSNumber) arguments.get(4);
COSNumber f = (COSNumber) arguments.get(5);
Matrix matrix = new Matrix(a.floatValue(), b.floatValue(), c.floatValue(),
d.floatValue(), e.floatValue(), f.floatValue());
context.getCurrentTransformationMatrix().concatenate(matrix);
}
示例4: process
import org.apache.pdfbox.cos.COSBase; //导入依赖的package包/类
@Override
public void process(Operator operator, List<COSBase> operands)
throws IOException {
COSNumber x = (COSNumber) operands.get(0);
COSNumber y = (COSNumber) operands.get(1);
COSNumber w = (COSNumber) operands.get(2);
COSNumber h = (COSNumber) operands.get(3);
Point lowerLeft = new SimplePoint(x.floatValue(), y.floatValue());
Point upperRight = new SimplePoint(w.floatValue() + lowerLeft.getX(),
h.floatValue() + lowerLeft.getY());
context.transform(lowerLeft);
context.transform(upperRight);
// To ensure that the path is created in the right direction,
// we have to create it by combining single lines instead of
// creating a simple rectangle
GeneralPath path = context.getLinePath();
path.moveTo(lowerLeft.getX(), lowerLeft.getY());
path.lineTo(upperRight.getX(), lowerLeft.getY());
path.lineTo(upperRight.getX(), upperRight.getY());
path.lineTo(lowerLeft.getX(), upperRight.getY());
path.lineTo(lowerLeft.getX(), lowerLeft.getY());
}
示例5: process
import org.apache.pdfbox.cos.COSBase; //导入依赖的package包/类
@Override
public void process(Operator operator, List<COSBase> operands)
throws IOException {
COSNumber x2 = (COSNumber) operands.get(0);
COSNumber y2 = (COSNumber) operands.get(1);
COSNumber x3 = (COSNumber) operands.get(2);
COSNumber y3 = (COSNumber) operands.get(3);
Point2D currentPoint = context.getLinePath().getCurrentPoint();
Point point2 = new SimplePoint(x2.floatValue(), y2.floatValue());
Point point3 = new SimplePoint(x3.floatValue(), y3.floatValue());
context.transform(point2);
context.transform(point3);
if (currentPoint == null) {
context.getLinePath().moveTo(point3.getX(), point3.getY());
} else {
context.getLinePath().curveTo(
(float) currentPoint.getX(), (float) currentPoint.getY(),
point2.getX(), point2.getY(), point3.getX(), point3.getY());
}
}
示例6: process
import org.apache.pdfbox.cos.COSBase; //导入依赖的package包/类
@Override
public void process(Operator operator, List<COSBase> operands)
throws IOException {
COSNumber x1 = (COSNumber) operands.get(0);
COSNumber y1 = (COSNumber) operands.get(1);
COSNumber x3 = (COSNumber) operands.get(2);
COSNumber y3 = (COSNumber) operands.get(3);
Point point1 = new SimplePoint(x1.floatValue(), y1.floatValue());
Point point3 = new SimplePoint(x3.floatValue(), y3.floatValue());
context.transform(point1);
context.transform(point3);
context.getLinePath().curveTo(point1.getX(), point1.getY(),
point3.getX(), point3.getY(), point3.getX(), point3.getY());
}
示例7: process
import org.apache.pdfbox.cos.COSBase; //导入依赖的package包/类
@Override
public void process(Operator operator, List<COSBase> operands)
throws IOException {
COSNumber x1 = (COSNumber) operands.get(0);
COSNumber y1 = (COSNumber) operands.get(1);
COSNumber x2 = (COSNumber) operands.get(2);
COSNumber y2 = (COSNumber) operands.get(3);
COSNumber x3 = (COSNumber) operands.get(4);
COSNumber y3 = (COSNumber) operands.get(5);
Point point1 = new SimplePoint(x1.floatValue(), y1.floatValue());
Point point2 = new SimplePoint(x2.floatValue(), y2.floatValue());
Point point3 = new SimplePoint(x3.floatValue(), y3.floatValue());
context.transform(point1);
context.transform(point2);
context.transform(point3);
if (context.getLinePath().getCurrentPoint() == null) {
context.getLinePath().moveTo(point3.getX(), point3.getY());
} else {
context.getLinePath().curveTo(point1.getX(), point1.getY(),
point2.getX(), point2.getY(), point3.getX(), point3.getY());
}
}
示例8: process
import org.apache.pdfbox.cos.COSBase; //导入依赖的package包/类
@Override
public void process(Operator operator, List<COSBase> arguments)
throws MissingOperandException {
if (arguments.size() < 6) {
throw new MissingOperandException(operator, arguments);
}
COSNumber a = (COSNumber) arguments.get(0);
COSNumber b = (COSNumber) arguments.get(1);
COSNumber c = (COSNumber) arguments.get(2);
COSNumber d = (COSNumber) arguments.get(3);
COSNumber e = (COSNumber) arguments.get(4);
COSNumber f = (COSNumber) arguments.get(5);
// Set both matrices to
// [ a b 0
// c d 0
// e f 1 ]
Matrix matrix = new Matrix(a.floatValue(), b.floatValue(),
c.floatValue(), d.floatValue(), e.floatValue(), f.floatValue());
context.setTextMatrix(matrix);
context.setTextLineMatrix(matrix.clone());
}
示例9: process
import org.apache.pdfbox.cos.COSBase; //导入依赖的package包/类
@Override
public void process(Operator operator, List<COSBase> arguments)
throws MissingOperandException {
if (arguments.size() < 2) {
throw new MissingOperandException(operator, arguments);
}
Matrix tlm = context.getTextLineMatrix();
if (tlm == null) {
return;
}
COSNumber tx = (COSNumber) arguments.get(0);
COSNumber ty = (COSNumber) arguments.get(1);
Matrix matrix = new Matrix(1, 0, 0, 1, tx.floatValue(), ty.floatValue());
tlm.concatenate(matrix);
context.setTextMatrix(tlm.clone());
}
示例10: process
import org.apache.pdfbox.cos.COSBase; //导入依赖的package包/类
@Override
public void process(Operator operator, List<COSBase> arguments)
throws IOException {
PDColorSpace cs = context.getResources().getColorSpace(COSName.DEVICERGB);
context.getGraphicsState().setNonStrokingColorSpace(cs);
super.process(operator, arguments);
}
示例11: PdfImageCounter
import org.apache.pdfbox.cos.COSBase; //导入依赖的package包/类
public PdfImageCounter() {
addOperator(new OperatorProcessor() {
@Override
public void process(Operator operator, List<COSBase> arguments) throws IOException {
if (arguments.size() < 1) {
throw new org.apache.pdfbox.contentstream.operator.MissingOperandException(operator, arguments);
}
if (isImage(arguments.get(0))) {
documentImageCount++;
}
}
protected Boolean isImage(COSBase base) {
return (base instanceof COSName) &&
context.getResources().isImageXObject((COSName)base);
}
@Override
public String getName() {
return "Do";
}
});
}
示例12: processOperator
import org.apache.pdfbox.cos.COSBase; //导入依赖的package包/类
@Override
protected void processOperator(Operator operator, List<COSBase> operands) throws IOException
{
String currentFormName = formName;
if (operator != null && "Do".equals(operator.getName()) && operands != null && operands.size() > 0)
{
COSBase base0 = operands.get(0);
if (base0 instanceof COSName)
{
formName = ((COSName)base0).getName();
if (currentFormName == null)
lastFormName = formName;
}
}
try
{
super.processOperator(operator, operands);
}
finally
{
formName = currentFormName;
}
}
示例13: processOperator
import org.apache.pdfbox.cos.COSBase; //导入依赖的package包/类
@Override
protected void processOperator(Operator operator, List<COSBase> operands) throws IOException
{
if (replacement != null)
{
boolean copy = true;
if (TjTJ.contains(operator.getName()))
{
Matrix transformation = getTextMatrix().multiply(getGraphicsState().getCurrentTransformationMatrix());
float xPos = transformation.getTranslateX();
float yPos = transformation.getTranslateY();
for (HelloSignField field : fields)
{
if (field.inField(xPos, yPos))
{
copy = false;
}
}
}
if (copy)
{
replacement.writeTokens(operands);
replacement.writeToken(operator);
}
}
super.processOperator(operator, operands);
}
示例14: process
import org.apache.pdfbox.cos.COSBase; //导入依赖的package包/类
@Override
public void process(Operator operator, List<COSBase> operands) throws IOException {
if (operands.size() < 4) {
throw new MissingOperandException(operator, operands);
}
if (!checkArrayTypesClass(operands, COSNumber.class)) {
return;
}
COSNumber x = (COSNumber) operands.get(0);
COSNumber y = (COSNumber) operands.get(1);
COSNumber w = (COSNumber) operands.get(2);
COSNumber h = (COSNumber) operands.get(3);
float x1 = x.floatValue();
float y1 = y.floatValue();
// create a pair of coordinates for the transformation
float x2 = w.floatValue() + x1;
float y2 = h.floatValue() + y1;
Point2D p0 = context.transformedPoint(x1, y1);
Point2D p1 = context.transformedPoint(x2, y1);
Point2D p2 = context.transformedPoint(x2, y2);
Point2D p3 = context.transformedPoint(x1, y2);
// to ensure that the path is created in the right direction, we have to create
// it by combining single lines instead of creating a simple rectangle
linePath.moveTo((float) p0.getX(), (float) p0.getY());
linePath.lineTo((float) p1.getX(), (float) p1.getY());
linePath.lineTo((float) p2.getX(), (float) p2.getY());
linePath.lineTo((float) p3.getX(), (float) p3.getY());
// close the subpath instead of adding the last line so that a possible set line
// cap style isn't taken into account at the "beginning" of the rectangle
linePath.closePath();
}
示例15: process
import org.apache.pdfbox.cos.COSBase; //导入依赖的package包/类
/**
* process : BI : begin inline image.
*
* @param operator
* The operator that is being executed.
* @param arguments
* List
* @throws IOException
* If there is an error displaying the inline image.
*/
public void process(Operator operator, List<COSBase> arguments)
throws IOException {
Matrix ctm = context.getCurrentTransformationMatrix();
COSDictionary params = operator.getImageParameters();
int width = params.getInt(COSName.W, COSName.WIDTH, -1);
int height = params.getInt(COSName.H, COSName.HEIGHT, -1);
// TODO: use transform().
float minX = ctm.getTranslateX();
float maxX = minX + (width * ctm.getScaleX());
float minY = ctm.getTranslateY();
float maxY = minY + (height * ctm.getScaleY());
// Type3 streams may contain BI operands, but we don't wan't to consider
// those.
if (!context.isType3Stream()) {
// Rectangle boundBox = new SimpleRectangle(minX, minY, maxX, maxY);
Rectangle boundBox = SimpleRectangle.from2Vertices(
new SimplePoint(minX, minY),
new SimplePoint(maxX, maxY));
PDImage image = new PDInlineImage(operator.getImageParameters(),
operator.getImageData(), context.getResources());
PdfBoxColor exclusiveColor = getExclusiveColor(image.getImage());
if (exclusiveColor != null) {
PdfBoxShape shape = new PdfBoxShape(context.getCurrentPage());
shape.setRectangle(boundBox);
shape.setColor(exclusiveColor);
context.showShape(shape);
} else {
PdfBoxFigure figure = new PdfBoxFigure(context.getCurrentPage());
figure.setRectangle(boundBox);
context.showFigure(figure);
}
}
}