图像转换为PDF中的Andr​​oid转换为、图像、PDF、Andr

由网友(新不如旧)分享简介:我需要一个发送图像以PDF文件的形式在我的Andr​​oid应用程序,但我没有想法如何位图转换为PDF格式。I need to send an image as in form of PDF file in my Android application but I dont have idea how to conv...

我需要一个发送图像以PDF文件的形式在我的Andr​​oid应用程序,但我没有想法如何位图转换为PDF格式。

I need to send an image as in form of PDF file in my Android application but I dont have idea how to convert bitmap to PDF.

我可以用文字写的PDF而已。

I am able to write pdf with text only.

有没有什么解决办法吗?

Is there any solution?

推荐答案

我认为你正在使用iText库的文本PDF转换。使用此图像转换为PDF格式。

I think you are using iText Library to convert the text to pdf. Use this to convert image to 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();
   }
}
阅读全文

相关推荐

最新文章