2013-04-01 36 views
5

我想將幾個.jpg文件(使用設備相機拍攝)轉換爲一個.pdf文件。我看到很多像iText,mupdf,PDFjet,pdjBox這樣的工具。如何將jpg轉換爲Android java中的pdf

有沒有更簡單的東西? (就像一個API準備好了android?)

謝謝。

回答

5

使用iText庫將文本轉換爲pdf。使用它將圖像轉換爲pdf。

import java.io.*; 
import com.lowagie.text.*; 
import com.lowagie.text.pdf.*; 
public class imagesPDF 
{  
    public static void main(String arg[])throws Exception 
    {     
     Document document=new Document(); 
     PdfWriter.getInstance(document,new FileOutputStream("YourPDFHere.pdf")); 
     document.open(); 
     Image image = Image.getInstance ("yourImageHere.jpg"); 
     document.add(new Paragraph("Your Heading for the Image Goes Here")); 
     document.add(image);    
     document.close(); 
    } 
} 
+0

以及如何添加多個圖像,每個圖像在一個單獨的頁面..? –

+0

嘿@Nathan,我已經使用您的代碼將.jpg文件轉換爲pdf。但問題是,當我的圖像完全存儲在設備中時,我只能獲得Pdf文檔中圖像的一部分。你能幫我解決這個問題嗎? –

+0

它有點緊急。如果你能幫忙。所以我可以接受你的答案。 –