有誰知道如何將圖像文件輕鬆轉換爲PDF格式。我需要的是從數據庫中獲取圖像並將其作爲PDF顯示在屏幕上。我究竟做錯了什麼?我試圖使用iText,但沒有結果。 我的代碼:Vaadin轉換並顯示圖像爲PDF
StreamResource resource = file.downloadFromDatabase();//get file from db
Document converToPdf=new Document();//Create Document Object
PdfWriter.getInstance(convertToPdf, new FileOutputStream(""));//Create PdfWriter for Document to hold physical file
convertToPdf.open();
Image convertJpg=Image.getInstance(resource); //Get the input image to Convert to PDF
convertToPdf.add(convertJpg);//Add image to Document
Embedded pdf = new Embedded("", convertToPdf);//display document
pdf.setMimeType("application/pdf");
pdf.setType(Embedded.TYPE_BROWSER);
pdf.setSizeFull();
謝謝。
分割的兩個步驟。 PDF是否正確生成?顯示它。 (但是爲什麼要通過PDF來顯示圖像,直接顯示圖像會更有效 –
爲什麼要將圖像轉換成PDF?這需要一些用戶安裝PDF程序。當然,將圖像顯示爲 –
Chris,問題在於當我用Vaadin顯示圖像時 - 它的大小(比例)總是依賴於瀏覽器,Firefox在窗口寬度內呈現圖像,而Chrome顯示的圖像與比屏幕尺寸更大,更寬,但是我需要確保圖像總是以全屏顯示,並且不會被瀏覽器切斷。 – Lena