从这里下载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