日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程语言 > java >内容正文

java

创建面板对象Java,从PNG图像或Java面板创建PDF

發布時間:2025/3/19 java 32 豆豆
生活随笔 收集整理的這篇文章主要介紹了 创建面板对象Java,从PNG图像或Java面板创建PDF 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

I'm looking for a Java library that will can take a Image (PNG) and create a PDF.

Or Create the PDF directly from a java panel that has been drawn.

解決方案

You can achieve this using Gnostice PDFOne for Java (http://www.gnostice.com/PDFOne_Java.asp).

Find below the code snippet that creates a PDF document from a PNG image.

PdfDocument doc = new PdfDocument();

// Read the image as BufferedImage object

BufferedImage bufImg = ImageIO.read(new File(

"SampleImage.PNG"));

// Create PdfImage object using the above BufferedImage object

PdfImage img = PdfImage.create(bufImg);

// Create a PdfPage of image size (image width x image Height)

PdfPage page1 = new PdfPage(img.width(), img.height());

// draw the image at 0, 0

page1.drawImage(img, 0, 0);

// add the page to the document object

doc.add(page1);

// save the document to the output file

doc.save("PNGImageToPDF.pdf");

doc.close();

To create a BufferedImage from a JPanel you can use the below code snippet.

int w = jpanel.getWidth();

int h = jpanel.getHeight();

BufferedImage bi = new BufferedImage(w, h,

BufferedImage.TYPE_INT_RGB);

Graphics2D g2 = bi.createGraphics();

jpanel.paint(g2);

g2.dispose();

After creating BuffereImage from JPanel you can use the first code snippet to create PDF.

I hope you will find this useful.

Disclaimer: I work for Gnostice.

總結

以上是生活随笔為你收集整理的创建面板对象Java,从PNG图像或Java面板创建PDF的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。