如何在Android java中将jpg转换为pdf

Ofe*_*gev 5 java pdf android pdf-generation

我想将几个.jpg文件(使用设备相机拍摄)转换为ONE .pdf文件.我看到很多工具,如iText,mupdf,PDFjet,pdjBox.

有更简单的事情吗?(就像为Android准备的API?)

谢谢.

Nat*_*han 5

使用iText Library将文本转换为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();
   }
}
Run Code Online (Sandbox Code Playgroud)