本文整理汇总了Java中org.apache.pdfbox.pdmodel.graphics.xobject.PDPixelMap类的典型用法代码示例。如果您正苦于以下问题:Java PDPixelMap类的具体用法?Java PDPixelMap怎么用?Java PDPixelMap使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
PDPixelMap类属于org.apache.pdfbox.pdmodel.graphics.xobject包,在下文中一共展示了PDPixelMap类的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: drawImageWithScale
import org.apache.pdfbox.pdmodel.graphics.xobject.PDPixelMap; //导入依赖的package包/类
private static void drawImageWithScale(PDDocument doc, PDPageContentStream content, String imgPath,
int bufferedImageType, float scale) throws IOException {
BufferedImage bufferedImage = ImageIO.read(new File(imgPath));
BufferedImage image = new BufferedImage(bufferedImage.getWidth(), bufferedImage.getHeight(), bufferedImageType);
image.createGraphics().drawRenderedImage(bufferedImage, null);
PDXObjectImage xImage = new PDPixelMap(doc, image);
content.drawXObject(xImage, 100, 100, xImage.getWidth() * scale, xImage.getHeight() * scale);
}
示例2: addImageToPage
import org.apache.pdfbox.pdmodel.graphics.xobject.PDPixelMap; //导入依赖的package包/类
public void addImageToPage(PDDocument document, int pdfpage, int x, int y, float scale, BufferedImage tmp_image)
throws IOException {
// Convert the image to TYPE_4BYTE_ABGR so PDFBox won't throw exceptions
// (e.g. for transparent png's).
BufferedImage image = new BufferedImage(tmp_image.getWidth(), tmp_image.getHeight(),
BufferedImage.TYPE_4BYTE_ABGR);
image.createGraphics().drawRenderedImage(tmp_image, null);
PDXObjectImage ximage = new PDPixelMap(document, image);
PDPage page = (PDPage) document.getDocumentCatalog().getAllPages().get(pdfpage);
PDPageContentStream contentStream = new PDPageContentStream(document, page, true, true);
contentStream.drawXObject(ximage, x, y, ximage.getWidth() * scale, ximage.getHeight() * scale);
contentStream.close();
}
示例3: init
import org.apache.pdfbox.pdmodel.graphics.xobject.PDPixelMap; //导入依赖的package包/类
private void init() throws IOException {
// Erstelle das Dokument
pdDocument = new PDDocument();
// Erstelle die Seite
pdPage = new PDPage(PDPage.PAGE_SIZE_A4);
// Füge die Seite zum Dokument hinzu
pdDocument.addPage(pdPage);
// Erstelle Font Objekt
pdFont = PDTrueTypeFont.loadTTF(pdDocument, fontFile);
// Erstelle Barcode Bild
pdfBarcodeFile = new File("/tmp/" + reservation.getUuid() + ".png");
new CreateBarcode(pdfBarcodeFile, reservation.getUuid());
BufferedImage pdfBarcodeAwtImage = ImageIO.read(pdfBarcodeFile);
pdfBarcodeImage = new PDPixelMap(pdDocument, pdfBarcodeAwtImage);
// Erstelle Event Bild
BufferedImage titleAwtImage = ImageIO.read(new File(HTDOCS
+ reservation.getEvent().getPicture().getPictureUrl("NORMAL")));
titleImage = new PDPixelMap(pdDocument, titleAwtImage);
// Erstelle Location Bild
BufferedImage locationAwtImage = ImageIO.read(new File(HTDOCS
+ reservation.getEvent().getLocation().getPicture()
.getPictureUrl("NORMAL")));
locationImage = new PDPixelMap(pdDocument, locationAwtImage);
// Erstelle Bild
BufferedImage logoAwtImage = ImageIO.read(logoFile);
logoImage = new PDPixelMap(pdDocument, logoAwtImage);
// Erstelle Bild
BufferedImage adAwtImage = ImageIO.read(adFile);
adImage = new PDPixelMap(pdDocument, adAwtImage);
// Erstelle das ContentStream Objekt
pdPageContentStream = new PDPageContentStream(pdDocument, pdPage);
}
示例4: createPDF
import org.apache.pdfbox.pdmodel.graphics.xobject.PDPixelMap; //导入依赖的package包/类
private void createPDF(Patient patient, Image image) throws IOException, COSVisitorException{
PDDocumentInformation pdi = new PDDocumentInformation();
Mandant mandant = (Mandant) ElexisEventDispatcher.getSelected(Mandant.class);
pdi.setAuthor(mandant.getName() + " " + mandant.getVorname());
pdi.setCreationDate(new GregorianCalendar());
pdi.setTitle("Impfausweis " + patient.getLabel());
PDDocument document = new PDDocument();
document.setDocumentInformation(pdi);
PDPage page = new PDPage();
page.setMediaBox(PDPage.PAGE_SIZE_A4);
document.addPage(page);
PDRectangle pageSize = page.findMediaBox();
PDFont font = PDType1Font.HELVETICA_BOLD;
PDFont subFont = PDType1Font.HELVETICA;
PDPageContentStream contentStream = new PDPageContentStream(document, page);
contentStream.beginText();
contentStream.setFont(font, 14);
contentStream.moveTextPositionByAmount(40, pageSize.getUpperRightY() - 40);
contentStream.drawString(patient.getLabel());
contentStream.endText();
String dateLabel = sdf.format(Calendar.getInstance().getTime());
String title = Person.load(mandant.getId()).get(Person.TITLE);
String mandantLabel = title + " " + mandant.getName() + " " + mandant.getVorname();
contentStream.beginText();
contentStream.setFont(subFont, 10);
contentStream.moveTextPositionByAmount(40, pageSize.getUpperRightY() - 55);
contentStream.drawString("Ausstellung " + dateLabel + ", " + mandantLabel);
contentStream.endText();
BufferedImage imageAwt = convertToAWT(image.getImageData());
PDXObjectImage pdPixelMap = new PDPixelMap(document, imageAwt);
contentStream.drawXObject(pdPixelMap, 40, 30, pageSize.getWidth() - 80,
pageSize.getHeight() - 100);
contentStream.close();
String outputPath =
CoreHub.userCfg.get(PreferencePage.VAC_PDF_OUTPUTDIR, CoreHub.getWritableUserDir()
.getAbsolutePath());
if (outputPath.equals(CoreHub.getWritableUserDir().getAbsolutePath())) {
SWTHelper
.showInfo(
"Kein Ausgabeverzeichnis definiert",
"Ausgabe erfolgt in: "
+ outputPath
+ "\nDas Ausgabeverzeichnis kann unter Einstellungen\\Klinische Hilfsmittel\\Impfplan definiert werden.");
}
File outputDir = new File(outputPath);
File pdf = new File(outputDir, "impfplan_" + patient.getPatCode() + ".pdf");
document.save(pdf);
document.close();
Desktop.getDesktop().open(pdf);
}