-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtoPDF.java
More file actions
46 lines (40 loc) · 1.29 KB
/
toPDF.java
File metadata and controls
46 lines (40 loc) · 1.29 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
37
38
39
40
41
42
43
44
45
46
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.util.Scanner;
import com.itextpdf.text.Document;
import com.itextpdf.text.DocumentException;
import com.itextpdf.text.Paragraph;
import com.itextpdf.text.pdf.PdfWriter;
public class toPDF
{
public static Boolean convertpdf(File file,String address)
{
Boolean written=false;
//Blank Document
Document document = new Document();
try
{
//Path of pdf file to be created if not existing already
PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(address+"/License.pdf"));
document.open();
//Write the Document in file system
Scanner readobj = new Scanner(file);
//Loop until we find the EOF
while (readobj.hasNextLine()){
String dataInfo = readobj.nextLine();
written=document.add(new Paragraph(dataInfo+"\n"));
}
readobj.close();
document.close();
writer.close();
} catch (DocumentException e)
{
e.printStackTrace();
} catch (FileNotFoundException e)
{
e.printStackTrace();
}
return written?true:false;
}
}