本文整理汇总了Java中org.apache.pdfbox.pdmodel.graphics.xobject.PDJpeg类的典型用法代码示例。如果您正苦于以下问题:Java PDJpeg类的具体用法?Java PDJpeg怎么用?Java PDJpeg使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
PDJpeg类属于org.apache.pdfbox.pdmodel.graphics.xobject包,在下文中一共展示了PDJpeg类的16个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: writeImageToPDF
import org.apache.pdfbox.pdmodel.graphics.xobject.PDJpeg; //导入依赖的package包/类
private void writeImageToPDF(PDJpeg img, int c, int size) throws IOException {
PDPageContentStream cs = new PDPageContentStream(document, page, true, false);
float x = getLeftX();
float y = page.getYCursor()-img.getHeight();
if (c>0&&(c%2==0)) {
x+=350;
}
if (size > 0) {
y = page.getYCursor()-400;
}
if (isFullPage())
y = page.getLowY();
cs.drawImage(img, x, y);
cs.close();
}
开发者ID:purbon,项目名称:pdfwriter,代码行数:19,代码来源:PDFChart.java
示例2: testDrunkenFistSample
import org.apache.pdfbox.pdmodel.graphics.xobject.PDJpeg; //导入依赖的package包/类
/**
* Applying the code to the OP's sample file from a former question.
*
* @throws IOException
* @throws CryptographyException
* @throws COSVisitorException
*/
@Test
public void testDrunkenFistSample() throws IOException, CryptographyException, COSVisitorException
{
try ( InputStream resource = getClass().getResourceAsStream("sample.pdf");
InputStream left = getClass().getResourceAsStream("left.png");
InputStream right = getClass().getResourceAsStream("right.png");
PDDocument document = PDDocument.load(resource) )
{
if (document.isEncrypted())
{
document.decrypt("");
}
PDJpeg leftImage = new PDJpeg(document, ImageIO.read(left));
PDJpeg rightImage = new PDJpeg(document, ImageIO.read(right));
ImageLocator locator = new ImageLocator();
List<?> allPages = document.getDocumentCatalog().getAllPages();
for (int i = 0; i < allPages.size(); i++)
{
PDPage page = (PDPage) allPages.get(i);
locator.processStream(page, page.findResources(), page.getContents().getStream());
}
for (ImageLocation location : locator.getLocations())
{
PDRectangle cropBox = location.getPage().findCropBox();
float center = (cropBox.getLowerLeftX() + cropBox.getUpperRightX()) / 2.0f;
PDJpeg image = location.getMatrix().getXPosition() < center ? leftImage : rightImage;
AffineTransform transform = location.getMatrix().createAffineTransform();
PDPageContentStream content = new PDPageContentStream(document, location.getPage(), true, false, true);
content.drawXObject(image, transform);
content.close();
}
document.save(new File(RESULT_FOLDER, "sample-changed.pdf"));
}
}
开发者ID:mkl-public,项目名称:testarea-pdfbox1,代码行数:47,代码来源:OverwriteImage.java
示例3: getImageDimensions
import org.apache.pdfbox.pdmodel.graphics.xobject.PDJpeg; //导入依赖的package包/类
private Dimension getImageDimensions(PDJpeg img) {
float maxWidth = 200;
float maxHeight = 80;
float width = img.getWidth();
float height = img.getHeight();
System.out.println("Image of size "+width+"x"+height+"px was resized to:");
while (width > maxWidth) {
height = (maxWidth / width) * height;
width = maxWidth;
}
while (height > maxHeight) {
width = (maxHeight / height) * width;
height = maxHeight;
}
System.out.println(width+"x"+height+"px.");
return new Dimension((int) width,(int) height);
}
开发者ID:nyholmniklas,项目名称:vaadinInvoiceGenerator,代码行数:19,代码来源:Invoice2PdfBoxImpl.java
示例4: create
import org.apache.pdfbox.pdmodel.graphics.xobject.PDJpeg; //导入依赖的package包/类
public void create(TableCache cache, ArrayReducer reducer, int c, int size, String title) throws IOException {
if (chart == null)
return;
configureChart(chart, cache);
if (cache != null) {
for(String key : cache.keySet()) {
chart.insertData(key, reducer.reduce(cache.get(key)));
}
}
if (reducer.headers().length > 0)
chart.setHeaders(reducer.headers());
int width = (int)getWidth();
int height = 400;
if (size > 0) {
width = (width/2)-10;
}
if (isFullPage()) {
height = (int)getHeight();
}
PDJpeg img = build(chart, title, document, width, height);
writeImageToPDF(img, c, size);
if (c>0&&(c%2==0))
scrolldown();
}
开发者ID:purbon,项目名称:pdfwriter,代码行数:27,代码来源:PDFChart.java
示例5: build
import org.apache.pdfbox.pdmodel.graphics.xobject.PDJpeg; //导入依赖的package包/类
private PDJpeg build(Chart<Float> chart, String title, PDFDocument document, int width, int height) throws IOException {
JFreeChart obj = null;
try {
obj = chart.createChart(title);
} catch (Exception ex) {
ex.printStackTrace();
throw new IOException(ex);
}
// output as file
File outputFile = File.createTempFile("img", "jpg");
ChartUtilities.saveChartAsJPEG(outputFile, obj, width, height);
PDJpeg img = new PDJpeg(document, new FileInputStream(outputFile) );
outputFile.delete();
return img;
}
开发者ID:purbon,项目名称:pdfwriter,代码行数:20,代码来源:PDFChart.java
示例6: PdfRenderingEndorsementAlternative
import org.apache.pdfbox.pdmodel.graphics.xobject.PDJpeg; //导入依赖的package包/类
public PdfRenderingEndorsementAlternative(PDDocument doc, InputStream logo,
String[] header) throws IOException
{
this.doc = doc;
this.header = header;
logoImg = new PDJpeg(doc, logo);
}
开发者ID:mkl-public,项目名称:testarea-pdfbox1,代码行数:8,代码来源:PdfRenderingEndorsementAlternative.java
示例7: doSignOneStep
import org.apache.pdfbox.pdmodel.graphics.xobject.PDJpeg; //导入依赖的package包/类
/**
* {@link #doSignOriginal(InputStream, InputStream, File)} changed to add the image and sign at the same time.
*/
public void doSignOneStep(InputStream inputStream, InputStream logoStream, File outputDocument) throws Exception
{
byte inputBytes[] = IOUtils.toByteArray(inputStream);
PDDocument pdDocument = PDDocument.load(new ByteArrayInputStream(inputBytes));
PDJpeg ximage = new PDJpeg(pdDocument, ImageIO.read(logoStream));
PDPage page = (PDPage) pdDocument.getDocumentCatalog().getAllPages().get(0);
PDPageContentStream contentStream = new PDPageContentStream(pdDocument, page, true, true);
contentStream.drawXObject(ximage, 50, 50, 356, 40);
contentStream.close();
page.getResources().getCOSObject().setNeedToBeUpdate(true);
page.getResources().getCOSDictionary().getDictionaryObject(COSName.XOBJECT).setNeedToBeUpdate(true);
ximage.getCOSObject().setNeedToBeUpdate(true);
PDSignature signature = new PDSignature();
signature.setFilter(PDSignature.FILTER_ADOBE_PPKLITE);
signature.setSubFilter(PDSignature.SUBFILTER_ADBE_PKCS7_DETACHED);
signature.setName("signer name");
signature.setLocation("signer location");
signature.setReason("reason for signature");
signature.setSignDate(Calendar.getInstance());
pdDocument.addSignature(signature, new TC3());
FileOutputStream fos = new FileOutputStream(outputDocument);
fos.write(inputBytes);
FileInputStream is = new FileInputStream(outputDocument);
pdDocument.saveIncremental(is, fos);
}
开发者ID:mkl-public,项目名称:testarea-pdfbox1,代码行数:35,代码来源:SignLikeUnOriginalToo.java
示例8: genReport
import org.apache.pdfbox.pdmodel.graphics.xobject.PDJpeg; //导入依赖的package包/类
public static void genReport(JSONArray pObjAry) throws IOException, COSVisitorException {
String imagePath = "C:\\Users\\Bryden\\Desktop\\pie-sample.png";
List<List<String>> lstContents = new ArrayList<>();
List<String> aryLst = new ArrayList<>();
aryLst.add("Incident Type");
aryLst.add("");
lstContents.add(aryLst);
for (Object obj : pObjAry) {
JSONObject objJson = (JSONObject) obj;
Iterator<?> keys = objJson.keySet().iterator();
while (keys.hasNext()) {
String key = (String) keys.next();
// loop to get the dynamic key
String value = (String) objJson.get(key);
List<String> aryValues = new ArrayList<>();
aryValues.add(key);
aryValues.add(value);
lstContents.add(aryValues);
}
}
try (// Create a document and add a page to it
PDDocument document = new PDDocument()) {
PDPage page = new PDPage(PDPage.PAGE_SIZE_A4);
document.addPage(page);
// Create a new font object selecting one of the PDF base fonts
PDFont font = PDType1Font.HELVETICA_BOLD;
InputStream in = Files.newInputStream(Paths.get(imagePath));
PDJpeg img = new PDJpeg(document, in);
// Define a text content stream using the selected font, moving the cursor and drawing the text "Hello World"
try (// Start a new content stream which will "hold" the to be created content
PDPageContentStream contentStream = new PDPageContentStream(document, page)) {
// Define a text content stream using the selected font, moving the cursor and drawing the text "Hello World"
contentStream.beginText();
contentStream.setFont(font, 20);
contentStream.moveTextPositionByAmount(70, 720);
contentStream.drawString("Incident Summary " + new Date());
contentStream.endText();
contentStream.beginText();
contentStream.setFont(font, 20);
contentStream.moveTextPositionByAmount(100, 670);
contentStream.drawString("Statistics");
contentStream.endText();
contentStream.drawImage(img, 10, 10);
drawTable(page, contentStream, 650, 100, lstContents);
// Make sure that the content stream is closed:
}
img.clear();
// Save the results and ensure that the document is properly closed:
document.save("Hello World.pdf");
}
}
开发者ID:bcdy23,项目名称:CZ3003_Backend,代码行数:74,代码来源:CReport.java
示例9: create
import org.apache.pdfbox.pdmodel.graphics.xobject.PDJpeg; //导入依赖的package包/类
@Override
public void create() throws IOException {
int offset = 0;
if (options.get(COVERT_FILE_KEY) != null) {
String file = options.get(COVERT_FILE_KEY);
PDJpeg img = new PDJpeg(document, new FileInputStream(file) );
addCovertImage(img);
options.remove(COVERT_FILE_KEY);
options.remove(PDFCOVERT_FILE_KEY);
}
addTitleAndSubtitle(offset);
addFooterReferences();
}
开发者ID:purbon,项目名称:pdfwriter,代码行数:14,代码来源:PDFTitlePage.java
示例10: addCovertImage
import org.apache.pdfbox.pdmodel.graphics.xobject.PDJpeg; //导入依赖的package包/类
private void addCovertImage(PDJpeg file) throws IOException {
PDPageContentStream cs = new PDPageContentStream(document, this, true, false);
float xPosition = getLeftX()-(borders/2);
float yPosition = (this.getTopY()/2) - borders - 10;
cs.drawImage(file, xPosition, yPosition);
cs.close();
}
开发者ID:purbon,项目名称:pdfwriter,代码行数:8,代码来源:PDFTitlePage.java
示例11: scanResources
import org.apache.pdfbox.pdmodel.graphics.xobject.PDJpeg; //导入依赖的package包/类
private void scanResources(final PDResources rList, final PDDocument doc)
throws FileNotFoundException, IOException {
Map<String, PDXObject> xObs = rList.getXObjects();
for(String k : xObs.keySet()) {
final PDXObject xObj = xObs.get(k);
if(xObj instanceof PDXObjectForm)
scanResources(((PDXObjectForm) xObj).getResources(), doc);
if(!(xObj instanceof PDXObjectImage))
continue;
PDXObjectImage img = (PDXObjectImage) xObj;
System.out.println("Compressing image: " + k);
final Iterator<ImageWriter> jpgWriters =
ImageIO.getImageWritersByFormatName("jpeg");
final ImageWriter jpgWriter = jpgWriters.next();
final ImageWriteParam iwp = jpgWriter.getDefaultWriteParam();
iwp.setCompressionMode(ImageWriteParam.MODE_EXPLICIT);
iwp.setCompressionQuality(compQual);
ByteArrayOutputStream baos = new ByteArrayOutputStream();
jpgWriter.setOutput(ImageIO.createImageOutputStream(baos));
jpgWriter.write(null,
new IIOImage(img.getRGBImage(), null, null), iwp);
ByteArrayInputStream bais =
new ByteArrayInputStream(baos.toByteArray());
PDJpeg jpg = new PDJpeg(doc, bais);
xObs.put(k, jpg);
}
rList.setXObjects(xObs);
}
开发者ID:bnanes,项目名称:shrink-pdf,代码行数:29,代码来源:ShrinkPDF.java
示例12: getImage
import org.apache.pdfbox.pdmodel.graphics.xobject.PDJpeg; //导入依赖的package包/类
@Override
public PDXObjectImage getImage() throws IOException {
BufferedImage image;
if (fileName != null) {
image = ImageIO.read(new File(fileName));
} else if (url != null) {
image = ImageIO.read(url);
} else if (bytes != null) {
image = ImageIO.read(new ByteArrayInputStream(bytes));
} else {
throw new IllegalStateException();
}
return new PDJpeg(new PDDocument(), image, 1.0f);
}
开发者ID:brightgenerous,项目名称:brigen-base,代码行数:15,代码来源:ImageResource.java
示例13: doSign
import org.apache.pdfbox.pdmodel.graphics.xobject.PDJpeg; //导入依赖的package包/类
public void doSign() throws Exception
{
byte inputBytes[] = IOUtils.toByteArray(new FileInputStream("resources/rooster.pdf"));
PDDocument pdDocument = PDDocument.load(new ByteArrayInputStream(inputBytes));
PDJpeg ximage = new PDJpeg(pdDocument, ImageIO.read(new File("resources/logo.jpg")));
PDPage page = (PDPage) pdDocument.getDocumentCatalog().getAllPages().get(0);
PDPageContentStream contentStream = new PDPageContentStream(pdDocument, page, true, true);
contentStream.drawXObject(ximage, 50, 50, 356, 40);
contentStream.close();
ByteArrayOutputStream os = new ByteArrayOutputStream();
pdDocument.save(os);
os.flush();
pdDocument.close();
inputBytes = os.toByteArray();
pdDocument = PDDocument.load(new ByteArrayInputStream(inputBytes));
PDSignature signature = new PDSignature();
signature.setFilter(PDSignature.FILTER_ADOBE_PPKLITE);
signature.setSubFilter(PDSignature.SUBFILTER_ADBE_PKCS7_DETACHED);
signature.setName("signer name");
signature.setLocation("signer location");
signature.setReason("reason for signature");
signature.setSignDate(Calendar.getInstance());
pdDocument.addSignature(signature, this);
File outputDocument = new File("resources/signed.pdf");
ByteArrayInputStream fis = new ByteArrayInputStream(inputBytes);
FileOutputStream fos = new FileOutputStream(outputDocument);
byte[] buffer = new byte[8 * 1024];
int c;
while ((c = fis.read(buffer)) != -1)
{
fos.write(buffer, 0, c);
}
fis.close();
FileInputStream is = new FileInputStream(outputDocument);
pdDocument.saveIncremental(is, fos);
pdDocument.close();
}
开发者ID:mkl-public,项目名称:testarea-pdfbox1,代码行数:43,代码来源:TC3.java
示例14: doSignOriginal
import org.apache.pdfbox.pdmodel.graphics.xobject.PDJpeg; //导入依赖的package包/类
/**
* Essentially the original code from {@link TC3#doSign()} with dynamic input streams and output file.
*/
public void doSignOriginal(InputStream inputStream, InputStream logoStream, File outputDocument) throws Exception
{
byte inputBytes[] = IOUtils.toByteArray(inputStream);
PDDocument pdDocument = PDDocument.load(new ByteArrayInputStream(inputBytes));
PDJpeg ximage = new PDJpeg(pdDocument, ImageIO.read(logoStream));
PDPage page = (PDPage) pdDocument.getDocumentCatalog().getAllPages().get(0);
PDPageContentStream contentStream = new PDPageContentStream(pdDocument, page, true, true);
contentStream.drawXObject(ximage, 50, 50, 356, 40);
contentStream.close();
ByteArrayOutputStream os = new ByteArrayOutputStream();
pdDocument.save(os);
os.flush();
pdDocument.close();
inputBytes = os.toByteArray();
pdDocument = PDDocument.load(new ByteArrayInputStream(inputBytes));
PDSignature signature = new PDSignature();
signature.setFilter(PDSignature.FILTER_ADOBE_PPKLITE);
signature.setSubFilter(PDSignature.SUBFILTER_ADBE_PKCS7_DETACHED);
signature.setName("signer name");
signature.setLocation("signer location");
signature.setReason("reason for signature");
signature.setSignDate(Calendar.getInstance());
pdDocument.addSignature(signature, new TC3());
ByteArrayInputStream fis = new ByteArrayInputStream(inputBytes);
FileOutputStream fos = new FileOutputStream(outputDocument);
byte[] buffer = new byte[8 * 1024];
int c;
while ((c = fis.read(buffer)) != -1)
{
fos.write(buffer, 0, c);
}
fis.close();
FileInputStream is = new FileInputStream(outputDocument);
pdDocument.saveIncremental(is, fos);
pdDocument.close();
}
开发者ID:mkl-public,项目名称:testarea-pdfbox1,代码行数:45,代码来源:SignLikeUnOriginalToo.java
示例15: doSignRemoveType
import org.apache.pdfbox.pdmodel.graphics.xobject.PDJpeg; //导入依赖的package包/类
/**
* {@link #doSignOriginal(InputStream, InputStream, File)} changed to remove the Type entry from the trailer.
*/
public void doSignRemoveType(InputStream inputStream, InputStream logoStream, File outputDocument) throws Exception
{
byte inputBytes[] = IOUtils.toByteArray(inputStream);
PDDocument pdDocument = PDDocument.load(new ByteArrayInputStream(inputBytes));
PDJpeg ximage = new PDJpeg(pdDocument, ImageIO.read(logoStream));
PDPage page = (PDPage) pdDocument.getDocumentCatalog().getAllPages().get(0);
PDPageContentStream contentStream = new PDPageContentStream(pdDocument, page, true, true);
contentStream.drawXObject(ximage, 50, 50, 356, 40);
contentStream.close();
ByteArrayOutputStream os = new ByteArrayOutputStream();
pdDocument.save(os);
os.flush();
pdDocument.close();
inputBytes = os.toByteArray();
pdDocument = PDDocument.load(new ByteArrayInputStream(inputBytes));
pdDocument.getDocument().getTrailer().removeItem(COSName.TYPE);
PDSignature signature = new PDSignature();
signature.setFilter(PDSignature.FILTER_ADOBE_PPKLITE);
signature.setSubFilter(PDSignature.SUBFILTER_ADBE_PKCS7_DETACHED);
signature.setName("signer name");
signature.setLocation("signer location");
signature.setReason("reason for signature");
signature.setSignDate(Calendar.getInstance());
pdDocument.addSignature(signature, new TC3());
ByteArrayInputStream fis = new ByteArrayInputStream(inputBytes);
FileOutputStream fos = new FileOutputStream(outputDocument);
byte[] buffer = new byte[8 * 1024];
int c;
while ((c = fis.read(buffer)) != -1)
{
fos.write(buffer, 0, c);
}
fis.close();
FileInputStream is = new FileInputStream(outputDocument);
pdDocument.saveIncremental(is, fos);
pdDocument.close();
}
开发者ID:mkl-public,项目名称:testarea-pdfbox1,代码行数:46,代码来源:SignLikeUnOriginalToo.java
示例16: doSignTwoRevisions
import org.apache.pdfbox.pdmodel.graphics.xobject.PDJpeg; //导入依赖的package包/类
/**
* {@link #doSignOriginal(InputStream, InputStream, File)} changed to also save the first change as new revision.
*/
public void doSignTwoRevisions(InputStream inputStream, InputStream logoStream, File intermediateDocument, File outputDocument) throws Exception
{
FileOutputStream fos = new FileOutputStream(intermediateDocument);
FileInputStream fis = new FileInputStream(intermediateDocument);
byte inputBytes[] = IOUtils.toByteArray(inputStream);
PDDocument pdDocument = PDDocument.load(new ByteArrayInputStream(inputBytes));
PDJpeg ximage = new PDJpeg(pdDocument, ImageIO.read(logoStream));
PDPage page = (PDPage) pdDocument.getDocumentCatalog().getAllPages().get(0);
PDPageContentStream contentStream = new PDPageContentStream(pdDocument, page, true, true);
contentStream.drawXObject(ximage, 50, 50, 356, 40);
contentStream.close();
pdDocument.getDocumentCatalog().getCOSObject().setNeedToBeUpdate(true);
pdDocument.getDocumentCatalog().getPages().getCOSObject().setNeedToBeUpdate(true);
page.getCOSObject().setNeedToBeUpdate(true);
page.getResources().getCOSObject().setNeedToBeUpdate(true);
page.getResources().getCOSDictionary().getDictionaryObject(COSName.XOBJECT).setNeedToBeUpdate(true);
ximage.getCOSObject().setNeedToBeUpdate(true);
fos.write(inputBytes);
pdDocument.saveIncremental(fis, fos);
pdDocument.close();
pdDocument = PDDocument.load(intermediateDocument);
PDSignature signature = new PDSignature();
signature.setFilter(PDSignature.FILTER_ADOBE_PPKLITE);
signature.setSubFilter(PDSignature.SUBFILTER_ADBE_PKCS7_DETACHED);
signature.setName("signer name");
signature.setLocation("signer location");
signature.setReason("reason for signature");
signature.setSignDate(Calendar.getInstance());
pdDocument.addSignature(signature, new TC3());
fos = new FileOutputStream(outputDocument);
fis = new FileInputStream(outputDocument);
inputBytes = IOUtils.toByteArray(new FileInputStream(intermediateDocument));
fos.write(inputBytes);
pdDocument.saveIncremental(fis, fos);
pdDocument.close();
}
开发者ID:mkl-public,项目名称:testarea-pdfbox1,代码行数:49,代码来源:SignLikeUnOriginalToo.java
注:本文中的org.apache.pdfbox.pdmodel.graphics.xobject.PDJpeg类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论