iText 7(7.0.2)错误:类型Document中的方法add(AreaBreak)不适用于参数(段落)

时间:2017-04-24 06:28:09

标签: itext7

我正在尝试学习iText7(7.0.2),并构建一个基本的pdf,但在document.add(new Paragraph("Hello World!"))遇到错误,说

  

类型Document中的方法add(AreaBreak)不适用于参数(段落)“

任何帮助都会感激不尽。

public static void main(String args[]) throws IOException {
    File file = new File(DEST);
    file.getParentFile().mkdirs();
    new PdfTest().createPdf(DEST);
}

public void createPdf(String dest) throws IOException {
    //Initialize PDF writer
    PdfWriter writer = new PdfWriter(dest);

    //Initialize PDF document
    PdfDocument pdf = new PdfDocument(writer);

    // Initialize document
    Document document = new Document(pdf);

    //Add paragraph to the document
    document.add(new Paragraph("Hello World!"));

    //Close document
    document.close();
}

1 个答案:

答案 0 :(得分:0)

运行你的榜样。它的工作非常好。我最好的猜测是你有来自 itextpdf5 的旧缓存。确保 .pom -file仅包含 itext7 依赖项。并且,正如mkl在他的评论中提到的,导入段落的正确方法是

import { Routes, RouterModule } from '@angular/router';


export const router: Routes = [
   { path: '',  redirectTo: 'main', pathMatch: 'full'},
  { path: 'main', component:AdminBodyComponent  },
  { path: 'admin', component:AdminComponent  },
  { path: 'posts',component:PostsComponent},
  { path: 'addposts',component:AddPostComponent}];

export const routes: ModuleWithProviders = RouterModule.forRoot(router);
step2:
inject into your .ts file
constructor(
  private router:Router,
  ...
)
step3:
this.router.navigate(['/addposts']);