use of com.itextpdf.kernel.pdf.PdfStream in project i7j-pdfsweep by itext.
the class PdfCleanUpProcessor method checkIfImageAndClean.
private void checkIfImageAndClean(List<PdfObject> operands) {
PdfStream imageStream = getXObjectStream((PdfName) operands.get(0));
if (PdfName.Image.equals(imageStream.getAsName(PdfName.Subtype))) {
ImageRenderInfo encounteredImage = ((PdfCleanUpEventListener) getEventListener()).getEncounteredImage();
FilteredImagesCache.FilteredImageKey key = filter.createFilteredImageKey(encounteredImage.getImage(), encounteredImage.getImageCtm(), document);
PdfImageXObject imageToWrite = getFilteredImage(key, encounteredImage.getImageCtm());
if (imageToWrite != null) {
float[] ctm = pollNotAppliedCtm();
writeNotAppliedGsParams(false, false);
openNotWrittenTags();
getCanvas().addXObjectWithTransformationMatrix(imageToWrite, ctm[0], ctm[1], ctm[2], ctm[3], ctm[4], ctm[5]);
}
}
}
use of com.itextpdf.kernel.pdf.PdfStream in project i7j-pdfsweep by itext.
the class PdfCleanUpProcessor method filterImageMask.
private void filterImageMask(PdfImageXObject originalImage, PdfName maskKey, Matrix ctmForMasksFiltering, PdfImageXObject imageToWrite) {
PdfStream maskStream = originalImage.getPdfObject().getAsStream(maskKey);
if (maskStream == null || ctmForMasksFiltering == null) {
return;
}
PdfImageXObject maskImageXObject = new PdfImageXObject(maskStream);
if (!PdfCleanUpFilter.imageSupportsDirectCleanup(maskImageXObject)) {
Logger logger = LoggerFactory.getLogger(PdfCleanUpProcessor.class);
logger.error(CleanUpLogMessageConstant.IMAGE_MASK_CLEAN_UP_NOT_SUPPORTED);
return;
}
FilteredImagesCache.FilteredImageKey k = filter.createFilteredImageKey(maskImageXObject, ctmForMasksFiltering, document);
PdfImageXObject maskToWrite = getFilteredImage(k, null);
if (maskToWrite != null) {
imageToWrite.getPdfObject().put(maskKey, maskToWrite.getPdfObject());
}
}
use of com.itextpdf.kernel.pdf.PdfStream in project i7j-pdfsweep by itext.
the class PdfCleanUpProcessor method popCanvasIfFormXObject.
private void popCanvasIfFormXObject(String operator, List<PdfObject> operands) {
if ("Do".equals(operator)) {
PdfStream formStream = getXObjectStream((PdfName) operands.get(0));
if (PdfName.Form.equals(formStream.getAsName(PdfName.Subtype))) {
PdfCanvas cleanedCanvas = popCleanedCanvas();
PdfFormXObject newFormXObject = new PdfFormXObject((Rectangle) null);
newFormXObject.getPdfObject().putAll(formStream);
if (formStream.containsKey(PdfName.Resources)) {
newFormXObject.put(PdfName.Resources, cleanedCanvas.getResources().getPdfObject());
}
newFormXObject.getPdfObject().setData(cleanedCanvas.getContentStream().getBytes());
PdfName name = getCanvas().getResources().addForm(newFormXObject);
getCanvas().getContentStream().getOutputStream().write(name).writeSpace().writeBytes(ByteUtils.getIsoBytes("Do\n"));
}
}
}
use of com.itextpdf.kernel.pdf.PdfStream in project i7j-pdfsweep by itext.
the class PdfCleanUpTool method removeRedactAnnots.
/**
* Remove the redaction annotations.
* This method is called after the annotations are processed.
*
* @throws IOException
*/
private void removeRedactAnnots() throws IOException {
for (PdfRedactAnnotation annotation : redactAnnotations.keySet()) {
PdfPage page = annotation.getPage();
if (page != null) {
page.removeAnnotation(annotation);
PdfPopupAnnotation popup = annotation.getPopup();
if (popup != null) {
page.removeAnnotation(popup);
}
}
PdfCanvas canvas = new PdfCanvas(page);
PdfStream redactRolloverAppearance = annotation.getRedactRolloverAppearance();
PdfString overlayText = annotation.getOverlayText();
Rectangle annotRect = annotation.getRectangle().toRectangle();
if (redactRolloverAppearance != null) {
drawRolloverAppearance(canvas, redactRolloverAppearance, annotRect, redactAnnotations.get(annotation));
} else if (overlayText != null && !overlayText.toUnicodeString().isEmpty()) {
drawOverlayText(canvas, overlayText.toUnicodeString(), annotRect, annotation.getRepeat(), annotation.getDefaultAppearance(), annotation.getJustification());
}
}
}
Aggregations