在 Jdeveloper 中使用 iText 处理 PDF 文件时出现 ClassNotFoundException
ClassNotFoundException when handling PDF files using iText in Jdeveloper
我需要你的帮助来解决以下错误
java.lang.ClassNotFoundException: com.itextpdf.text.DocumentException
这是由 运行 生成的一个简单的 void
方法,用于在 Jdeveloper 中显示 PDF 文件。我在库中添加了 itext jar 文件,我拥有的版本是 5.5.6。
如果我正在写一个简单的PDF,该方法将被执行。但是,当我使用下面的代码时,它会生成错误。代码是:
public class pdf {
private StreamedContent streamedContent;
private static final long serialVersionUID = 1L;
@PostConstruct
public void CreatePDF() throws DocumentException, IOException {
try{
Document document = new Document(PageSize.A4, 50, 50, 50, 50);
OutputStream out = new ByteArrayOutputStream();
PdfWriter writer = PdfWriter.getInstance(document, out);
document.open();
PdfPTable table = new PdfPTable(1);
PdfPCell cell = new PdfPCell(new Phrase("\u0627\u0644\u0633\u0644\u064a\u0637\u064a"));
cell.setBorder(Rectangle.NO_BORDER);
cell.setRunDirection(PdfWriter.RUN_DIRECTION_RTL);
table.addCell(cell);
document.add(table);
document.close();
out.close();
InputStream in =new ByteArrayInputStream(((ByteArrayOutputStream)out).toByteArray());
streamedContent = new DefaultStreamedContent(in, "application/pdf");
//-------
Map<String, Object> session = FacesContext.getCurrentInstance().getExternalContext().getSessionMap();
byte[] b = (byte[]) session.get("reportBytes");
if (b != null) {
streamedContent = new DefaultStreamedContent(new ByteArrayInputStream(b), "application/pdf");
}
}
catch (Exception e) {
}
}
iText WAR 文件保存在 /lib 文件夹下并且运行良好。兼容版本为iText 2.1.7 请参考PrimeFaces Guide中的Dependencies
我需要你的帮助来解决以下错误
java.lang.ClassNotFoundException: com.itextpdf.text.DocumentException
这是由 运行 生成的一个简单的 void
方法,用于在 Jdeveloper 中显示 PDF 文件。我在库中添加了 itext jar 文件,我拥有的版本是 5.5.6。
如果我正在写一个简单的PDF,该方法将被执行。但是,当我使用下面的代码时,它会生成错误。代码是:
public class pdf {
private StreamedContent streamedContent;
private static final long serialVersionUID = 1L;
@PostConstruct
public void CreatePDF() throws DocumentException, IOException {
try{
Document document = new Document(PageSize.A4, 50, 50, 50, 50);
OutputStream out = new ByteArrayOutputStream();
PdfWriter writer = PdfWriter.getInstance(document, out);
document.open();
PdfPTable table = new PdfPTable(1);
PdfPCell cell = new PdfPCell(new Phrase("\u0627\u0644\u0633\u0644\u064a\u0637\u064a"));
cell.setBorder(Rectangle.NO_BORDER);
cell.setRunDirection(PdfWriter.RUN_DIRECTION_RTL);
table.addCell(cell);
document.add(table);
document.close();
out.close();
InputStream in =new ByteArrayInputStream(((ByteArrayOutputStream)out).toByteArray());
streamedContent = new DefaultStreamedContent(in, "application/pdf");
//-------
Map<String, Object> session = FacesContext.getCurrentInstance().getExternalContext().getSessionMap();
byte[] b = (byte[]) session.get("reportBytes");
if (b != null) {
streamedContent = new DefaultStreamedContent(new ByteArrayInputStream(b), "application/pdf");
}
}
catch (Exception e) {
}
}
iText WAR 文件保存在 /lib 文件夹下并且运行良好。兼容版本为iText 2.1.7 请参考PrimeFaces Guide中的Dependencies