-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathImagePDF.java
More file actions
36 lines (29 loc) · 1.02 KB
/
ImagePDF.java
File metadata and controls
36 lines (29 loc) · 1.02 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
package com.pdf.ravishankarcode;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.net.MalformedURLException;
import com.itextpdf.io.image.ImageDataFactory;
import com.itextpdf.kernel.pdf.PdfDocument;
import com.itextpdf.kernel.pdf.PdfWriter;
import com.itextpdf.layout.Document;
import com.itextpdf.layout.element.Image;
/**
*
* @author Ravishankar.kumar
*
*/
public class ImagePDF {
public static final String IMAGE_PDF = "C://temp//Image.pdf";
public static final String IMAGE_PATH = "C://temp//Image.jpg";
public static void main(String[] args) throws MalformedURLException, FileNotFoundException {
PdfWriter writer;
// path to image
Image image = new Image(ImageDataFactory.create(IMAGE_PATH));
writer = new PdfWriter(new FileOutputStream(IMAGE_PDF));
PdfDocument pdfDoc = new PdfDocument(writer);
Document document = new Document(pdfDoc);
// adding image
document.add(image);
document.close();
}
}