大家好,我是一个绝对的初学者,所以对我要轻松一点,为什么这对我不起作用,我真的不明白为什么这不起作用,但我是一个初学者,所以如果有人可以为我纠正这个问题,我将非常感激它。我很惊讶它不起作用
import com.itextpdf.kernel.geom.PageSize;
import com.itextpdf.kernel.pdf.PdfDocument;
import com.itextpdf.kernel.pdf.PdfWriter;
import com.itextpdf.layout.Document;
import com.itextpdf.layout.element.Cell;
import com.itextpdf.layout.element.Table;
import java.io.IOException;
public class Main {
public static void main(String[] args) throws IOException {
String path = "C:\\Users\\Kevin\OneDrive\\Desktop\\Generated PDFs\\Table.pdf";
String logosrc = "C:\\Users\\Kevin\\OneDrive\\Desktop\\Generated PDFs\\Images\\mainlogo.png";
PdfWriter pdfWriter = new PdfWriter(path);
PdfDocument pdfDocument = new PdfDocument(pdfWriter);
Document document = new Document(pdfDocument);
pdfDocument.setDefaultPageSize(PageSize.A4);
float col = 280f;
float columnWidth[] = {col, col};
Table table = new Table(columnWidth);
table.addCell(new Cell().add("INVOICE"));
Run Code Online (Sandbox Code Playgroud)
我的错误消息:
java: no suitable method found for add(java.lang.String)
method com.itextpdf.layout.element.Cell.add(com.itextpdf.layout.element.IBlockElement) is not applicable
(argument mismatch; java.lang.String cannot be converted to com.itextpdf.layout.element.IBlockElement)
method com.itextpdf.layout.element.Cell.add(com.itextpdf.layout.element.Image) is not applicable
(argument mismatch; java.lang.String cannot be converted to com.itextpdf.layout.element.Image)
Run Code Online (Sandbox Code Playgroud)
iText 7.0 有一个方法add(String)用于Cell.
对于 iText 7.1,如API 中所述,a的方法Cell仅采用块元素或图像add()。 iText 中的块元素是段落、列表和 div 等内容。
你可以将你的包裹String在一个Paragraph:
table.addCell(new Cell().add(new Paragraph("INVOICE")));
Run Code Online (Sandbox Code Playgroud)
有关 7.0 和 7.1 之间的更多差异,查看7.1 迁移指南可能会有所帮助,其中还包括以下更改:
com.itextpdf.layout.element.Cell#add(java.lang.String)已被删除,请使用BlockElementsuch asParagraph代替。
| 归档时间: |
|
| 查看次数: |
2870 次 |
| 最近记录: |