Convert image to PDF in Java Android

Ludger

I need to convert an image to PDF file in my Android application but i found two library iTextG and iText. Are they open source?

João Marcos

YES, iText is an open source library. Infomation from itext oficial site: "iText is a free/open source software (F/OSS) project, giving you a lot of freedom and flexibility.... You have to respect the Affero General Public License (AGPL)."

and you can use it like that:

import com.itextpdf.text.Document;
import com.itextpdf.text.pdf.PdfWriter;
import com.itextpdf.text.Image;


public class ImageToPDF {
  public static void main(String ... args) {
    Document document = new Document();
    String input = "c:/temp/capture.png"; // .gif and .jpg are ok too!
    String output = "c:/temp/capture.pdf";
    try {
      FileOutputStream fos = new FileOutputStream(output);
      PdfWriter writer = PdfWriter.getInstance(document, fos);
      writer.open();
      document.open();
      document.add(Image.getInstance(input));
      document.close();
      writer.close();
    }
    catch (Exception e) {
      e.printStackTrace();
    }
  }
}

この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。

侵害の場合は、連絡してください[email protected]

編集
0

コメントを追加

0

関連記事

分類Dev

Why convert in ImageMagick can not convert pdf to image

分類Dev

OpenOffice convert doc to pdf with JAVA

分類Dev

convert parsefile image to byte in android

分類Dev

Is there way to convert docx to image-only pdf with convertapi?

分類Dev

Convert Curl command into Java/Android

分類Dev

Android java change drawable image

分類Dev

Add all sizes of image asset in Android Studio with a PDF or Vector file

分類Dev

How to get image from java webservice on Android

分類Dev

Draw with a Canvas over an Image in Android/Java

分類Dev

Convert pdf to png in R

分類Dev

Convert PDF background color

分類Dev

Preview PDF as image in ranger

分類Dev

Convert a PDF to thumbnail using PDF.JS

分類Dev

How can we add '.svg' formatted image in pdf using itext library in java/struts2

分類Dev

convert html with inline svg to pdf

分類Dev

Convert html to pdf with ajax and mpdf

分類Dev

Convert an JSON table to an PDF with mPDF

分類Dev

Convert Numpy array to image

分類Dev

Android Java, How to pass an image from camera to Firebase Storage

分類Dev

PDF to Raster image, mistake in render

分類Dev

How can I convert HTML with CSS3 & SVG to an image - preferably from Java?

分類Dev

Generate Thumbnail of Pdf in Android

分類Dev

How to sign a PDF in Android

分類Dev

Android Pdf Viewer FileNotFoundException

分類Dev

Docx to Pdf Converter in Java

分類Dev

SSJS or Java generate PDF

分類Dev

Batch convert 4 PDF pages to one PDF page

分類Dev

Is there a fast way to convert a image into WEBP?

分類Dev

How to convert icon to image in flutter?