use of com.itextpdf.io.image.ImageData in project i7js-highlevel by itext.
the class C03E19_PagedImages method createPdf.
public void createPdf(String dest) throws IOException {
PdfDocument pdf = new PdfDocument(new PdfWriter(dest));
Document document = new Document(pdf);
Image img;
// Animated GIF
URL url1 = UrlUtil.toURL(TEST1);
List<ImageData> list = ImageDataFactory.createGifFrames(url1);
for (ImageData data : list) {
img = new Image(data);
document.add(img);
}
// JBIG2
URL url2 = UrlUtil.toURL(TEST2);
IRandomAccessSource ras2 = new RandomAccessSourceFactory().createSource(url2);
RandomAccessFileOrArray raf2 = new RandomAccessFileOrArray(ras2);
int pages2 = Jbig2ImageData.getNumberOfPages(raf2);
for (int i = 1; i <= pages2; i++) {
img = new Image(ImageDataFactory.createJbig2(url2, i));
document.add(img);
}
// TIFF
URL url3 = UrlUtil.toURL(TEST3);
IRandomAccessSource ras3 = new RandomAccessSourceFactory().createSource(url3);
RandomAccessFileOrArray raf3 = new RandomAccessFileOrArray(ras3);
int pages3 = TiffImageData.getNumberOfPages(raf3);
for (int i = 1; i <= pages3; i++) {
img = new Image(ImageDataFactory.createTiff(url3, true, i, true));
document.add(img);
}
document.close();
}
use of com.itextpdf.io.image.ImageData in project pdf-editor by Pdf-Creator.
the class PDFDocument method addRectangleWithFormulaItem.
public void addRectangleWithFormulaItem(FormulaItem formulaItem) throws IOException {
PdfCanvas canvas = new PdfCanvas(currentPage);
Rectangle rect = new Rectangle(formulaItem.getX(), formulaItem.getY(), formulaItem.getW(), formulaItem.getW());
canvas.setStrokeColor(formulaItem.getRectangleStrokeColor()).setFillColor(formulaItem.getRectangleStrokeColor()).rectangle(rect).fill().stroke();
// very strange method
TeXFormula tf = new TeXFormula(formulaItem.getFormula());
TeXIcon ti = tf.createTeXIcon(TeXConstants.STYLE_DISPLAY, formulaItem.getFontSize());
BufferedImage bimg = new BufferedImage(ti.getIconWidth(), ti.getIconHeight(), BufferedImage.TYPE_4BYTE_ABGR);
// -- painting the formula --
Graphics2D g2d = bimg.createGraphics();
g2d.setColor(Color.white);
g2d.fillRect(0, 0, ti.getIconWidth(), ti.getIconHeight());
JLabel jl = new JLabel();
jl.setForeground(new Color(0, 0, 0));
ti.paintIcon(jl, g2d, 0, 0);
// --------------------------
// -- adding it to pdf --
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
ImageIO.write(bimg, "png", byteArrayOutputStream);
ImageData data = ImageDataFactory.create(byteArrayOutputStream.toByteArray());
Image image = new Image(data);
image.setFixedPosition(formulaItem.getX(), formulaItem.getY());
image.scaleAbsolute(formulaItem.getW(), formulaItem.getH());
new Canvas(canvas, rect).add(image);
}
use of com.itextpdf.io.image.ImageData in project i7j-pdfsweep by itext.
the class PdfCleanUpProcessor method cleanInlineImage.
private void cleanInlineImage() {
ImageRenderInfo encounteredImage = ((PdfCleanUpEventListener) getEventListener()).getEncounteredImage();
PdfCleanUpFilter.FilterResult<ImageData> imageFilterResult = filter.filterImage(encounteredImage);
ImageData filteredImage;
if (imageFilterResult.isModified()) {
filteredImage = imageFilterResult.getFilterResult();
} else {
filteredImage = ImageDataFactory.create(encounteredImage.getImage().getImageBytes());
}
if (filteredImage != null) {
Boolean imageMaskFlag = encounteredImage.getImage().getPdfObject().getAsBool(PdfName.ImageMask);
if (imageMaskFlag != null && (boolean) imageMaskFlag) {
filteredImage.makeMask();
}
float[] ctm = pollNotAppliedCtm();
writeNotAppliedGsParams(false, false);
openNotWrittenTags();
getCanvas().addImageWithTransformationMatrix(filteredImage, ctm[0], ctm[1], ctm[2], ctm[3], ctm[4], ctm[5], true);
}
// TODO
// PdfCanvas doesn't have a method that writes inline image using pdf stream, and only have method which
// accepts Image as parameter. That's why we can't write image just as it was in original file, we convert it to Image.
// IMPORTANT: If writing of pdf stream of not changed inline image will be implemented, don't forget to ensure that
// inline image color space is present in new resources if necessary.
}
use of com.itextpdf.io.image.ImageData in project MtgDesktopCompanion by nicho92.
the class PDFExport method createCell.
private Cell createCell(MagicCard card) throws IOException {
ImageData imageData = null;
try {
imageData = ImageDataFactory.create(getEnabledPlugin(MTGPictureProvider.class).getFullSizePicture(card), null);
} catch (Exception e) {
imageData = ImageDataFactory.create(getEnabledPlugin(MTGPictureProvider.class).getBackPicture(), null);
}
var image = new Image(imageData);
image.scaleAbsolute(2.49f * userPoint, 3.48f * userPoint);
var cell = new Cell();
if (getBoolean("PRINT_CUT_LINE")) {
cell.setBorder(new DottedBorder(0.5f));
} else
cell.setBorder(Border.NO_BORDER);
if (getInt(SPACE) != null)
cell.setPadding(getInt(SPACE));
cell.add(image);
return cell;
}
use of com.itextpdf.io.image.ImageData in project i7js-highlevel by itext.
the class C03E18_ImageTypes method createPdf.
public void createPdf(String dest) throws IOException {
PdfDocument pdf = new PdfDocument(new PdfWriter(dest));
Document document = new Document(pdf);
// raw
byte[] data = new byte[256 * 3];
for (int i = 0; i < 256; i++) {
data[i * 3] = (byte) (255 - i);
data[i * 3 + 1] = (byte) (255 - i);
data[i * 3 + 2] = (byte) i;
}
ImageData raw = ImageDataFactory.create(256, 1, 3, 8, data, null);
Image img = new Image(raw);
img.scaleAbsolute(256, 10);
document.add(img);
// JPEG2000
Image img1 = new Image(ImageDataFactory.create(TEST1));
document.add(img1);
document.add(new AreaBreak());
// BMP
Image img2 = new Image(ImageDataFactory.create(TEST2));
img2.setMarginBottom(10);
document.add(img2);
// PNG
Image img3 = new Image(ImageDataFactory.create(TEST3));
img3.setMarginBottom(10);
document.add(img3);
// Transparent PNG
Image img4 = new Image(ImageDataFactory.create(TEST4));
img4.setBorderLeft(new SolidBorder(6));
document.add(img4);
// GIF
Image img5 = new Image(ImageDataFactory.create(TEST5));
img5.setBackgroundColor(ColorConstants.LIGHT_GRAY);
document.add(img5);
// AWT
java.awt.Image awtImage = Toolkit.getDefaultToolkit().createImage(TEST5);
Image awt = new Image(ImageDataFactory.create(awtImage, java.awt.Color.yellow));
awt.setMarginTop(10);
document.add(awt);
// JBIG2
Image img6 = new Image(ImageDataFactory.create(TEST6));
document.add(img6);
// TIFF
Image img7 = new Image(ImageDataFactory.create(TEST7));
document.add(img7);
document.close();
}
Aggregations