我发现了这个名为Boxable的API,它也使用PDFBox,现在我正在尝试在线实现这些示例,但无法让它工作。这是我的密码。
public static ArrayList <String[]> result = new ArrayList<String[]>();我只是复制了这个函数,就像在这个例子中一样
private static PDPage addNewPage(PDDocument doc) {
PDPage page = new PDPage();
doc.addPage(page);
return page;
}这些是我主要功能的一部分。
我的查询执行
Connection con = null;
PreparedStatement ps = null;
String query = "SELECT * FROM tablename";
try{
con = getConnection();
ps = con.prepareStatement(query);
ResultSet rs = ps.executeQuery();
int columnCount = rs.getMetaData().getColumnCount();
while(rs.next()){
String[] row = new String[columnCount];
for (int i=0;i<columnCount;i++){
row[i] = rs.getString(i+1);
}
result.add(row);
}
} catch (SQLException ex) {
Logger.getLogger(NewClass.class.getName()).log(Level.SEVERE, null, ex);
}表的生成部分
try{
float margin = 10;
PDDocument doc = new PDDocument();
PDPage page = addNewPage(doc);
float tableWidth = page.getMediaBox().getWidth()-(2*margin);
float yStartNewPage = page.getMediaBox().getHeight()-(2*margin);
boolean drawContent = true;
boolean drawLines = true;
float yStart = yStartNewPage;
float bottomMargin = 70;
BaseTable table = new BaseTable(yStart,yStartNewPage,bottomMargin,tableWidth,margin,doc,page,drawLines,drawContent);
Row<PDPage> headerRow = table.createRow(15f);
Cell<PDPage> cell = headerRow.createCell(100,"Sample Table");
cell.setFont(PDType1Font.HELVETICA_BOLD);
cell.setFillColor(Color.BLACK);
table.addHeaderRow(headerRow);
for (String[] print : result){
Row<PDPage> row = table.createRow(10f);
cell = row.createCell((100/3.0f)*2,print[0]);
for (int i=1;i<print.length;i++){
cell = row.createCell((100/9f),print[i]);
}
}
table.draw();
doc.save(new File("java\\sample.pdf"));
doc.close();
} catch (IOException ex) {
Logger.getLogger(NewClass.class.getName()).log(Level.SEVERE, null, ex);
}编译器给出了这个异常。
Exception in thread "main" java.lang.NoClassDefFoundError: org/slf4j/LoggerFactory
at be.quodlibet.boxable.utils.FontUtils.<clinit>(FontUtils.java:23)
at be.quodlibet.boxable.Cell.<init>(Cell.java:110)
at be.quodlibet.boxable.Cell.<init>(Cell.java:71)
at be.quodlibet.boxable.Row.createCell(Row.java:51)
at connect.NewClass.main(NewClass.java:115)上述115号线路是Cell<PDPage> cell = headerRow.createCell(100,"Sample Table");。
我真的不知道出了什么问题,而且Java仍然是新的。还试着读取类的代码,但是无法检测到错误。非常感谢你对此的投入。
发布于 2018-03-25 04:00:57
NoClassDefFoundError意味着您的类路径中没有引用的依赖项。这通常通过使用像Maven这样的依赖关系管理器或者通过手动将jar复制到您的项目根目录来解决。
具体来说,在您的问题中,您在编译时丢失了org.slf4j.LoggerFactory包。
https://stackoverflow.com/questions/49472279
复制相似问题