bmp转换tiff c++代码_如何用Java语言将图像转换为PDF?Spire.PDF for Java轻松搞定
生活随笔
收集整理的這篇文章主要介紹了
bmp转换tiff c++代码_如何用Java语言将图像转换为PDF?Spire.PDF for Java轻松搞定
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
對于開發人員,在日常工作中經常也會處理許多文檔格式,將圖像轉換為PDF也是常有的事。那么,在Java語言開發中,如何將圖像轉換為PDF呢?
Spire.PDF for Java支持將多種圖像格式(例如BMP,JPEG,GIF,PNG,TIFF和ICO)轉換為PDF。以下示例將展示如何使用Spire.PDF for Java將圖像轉換為PDF。
(點擊文末“了解更多”可下載最新版)
????導入com.spire.pdf.PdfDocument;???????導入com.spire.pdf.PdfPageBase;????????導入com.spire.pdf.graphics.PdfImage;????????????????公共課程ImageToPDF?{????????????公共靜態void?main(String?[]?args){????????????????//創建一個PdfDocument實例???????????????PdfDocument?pdf?=新的PdfDocument();????????????????//添加頁面???????????????PdfPageBase頁面=?pdf.getPages()。add();????????????????????????//加載圖片????????????????PdfImage圖片=?PdfImage.fromFile(“?Hydrangeas.jpg”);???????????????????????//將圖像繪制到頁面的特定矩形區域?????????????????double?widthFitRate?=?image.getPhysicalDimension()。getWidth()/?page.getCanvas()。getClientSize()。getWidth();???????????????double?heightFitRate?=?image.getPhysicalDimension()。getHeight()/?page.getCanvas()。getClientSize()。getHeight();????????????????double?fitRate?=?Math.max(widthFitRate,heightFitRate);???????????????double?fitWidth?=?image.getPhysicalDimension()。getWidth()/?fitRate;????????????????double?fitHeight?=?image.getPhysicalDimension()。getHeight()/?fitRate;????????????????page.getCanvas()。drawImage(image,new?Rectangle2D.Double(0,0,fitWidth,fitHeight));???????????????????????//保存結果文件??????????????pdf.saveToFile(“?ConvertImageToPDF.pdf”);???????????}????????}總結
以上是生活随笔為你收集整理的bmp转换tiff c++代码_如何用Java语言将图像转换为PDF?Spire.PDF for Java轻松搞定的全部內容,希望文章能夠幫你解決所遇到的問題。