從這裏下載iText API http://itextpdf.com/product/itextg並將其添加到您的項目中。
使用這個類,並調用所需的功能創建PDF
public class CreatePDF {
private static Font normalFont = new Font(Font.FontFamily.TIMES_ROMAN, 25,
Font.NORMAL, BaseColor.BLACK);
private static Font Head = new Font(Font.FontFamily.TIMES_ROMAN, 35,
Font.BOLD, BaseColor.BLACK);
//Path is the path where you want your pdf to get stored
public void createPDFDoc(ArrayList<notesWrapper> notesList,String path) {
// TODO Auto-generated method stub
Document document = new Document();
try {
PdfWriter.getInstance(document, new FileOutputStream(path));
document.open();
for(int i=0;i<notesList.size();i++)
{
addContentHead(document,"Image "+(i+1));
addContent(document,notesList.get(i).message);
if(i<notesList.size())
{
document.newPage();
}
}
document.close();
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
private void addContent(Document document,String content) throws DocumentException {
Paragraph preface = new Paragraph();
addEmptyLine(preface, 1);
if(!content.equalsIgnoreCase("insert note"))
preface.add(new Paragraph(content, normalFont));
else
addEmptyLine(new Paragraph(), 1);
addEmptyLine(preface, 3);
document.add(preface);
}
private void addContentHead(Document document,String content) throws DocumentException {
Paragraph preface = new Paragraph();
addEmptyLine(preface, 1);
preface.add(new Paragraph(content, Head));
addEmptyLine(preface, 3);
document.add(preface);
}
private static void addEmptyLine(Paragraph paragraph, int number) {
for (int i = 0; i < number; i++) {
paragraph.add(new Paragraph(" "));
}
}
}
通過iText API的應用做ü意味着jar文件?我已經有了jar文件,並且已經添加到構建路徑。我希望能夠通過活動課來到這個班。請告訴我 – Sam 2015-04-02 11:46:29
是的,當然是jar文件 – Ajeet 2015-04-02 11:48:27
請告訴我如何從一個活動課來到這個班,例如。 – Sam 2015-04-02 11:55:06