0

我有一个pdf,用户从他的桌面复制文本并在提交时生成pdf。我使用itext-2.1.7。但是由于我们使用了一些非标准的字母,因此这些字母被转换为它们的 html 代码字符代码。这是我使用“application/pdf;charset=UTF-8”的文档的 servlet。

BaseFont bf;
try {
  HttpSession session = request.getSession(true);
  if (session.getAttribute("taxnumber") == null || session.getAttribute("email") == null || session.getAttribute("password") == null) {
    request.setAttribute("message", "The user does not exist in our database");
    request.getRequestDispatcher("/Login.jsp").forward(request, response);
  }
  String title = request.getParameter("doctitle");
  String date = request.getParameter("docdate");
  String text = request.getParameter("brokerstext");
  String[] newdate = date.split("/");
  Document document = new Document(PageSize.A4);
  PdfWriter writer = PdfWriter.getInstance(document, response.getOutputStream());
  document.open();

  document.add(new Paragraph(newdate[1] + "/" + newdate[0] + "/" + newdate[2]));
  document.add(new Paragraph(title));
  document.add(new Paragraph(text));
  document.add(Chunk.NEWLINE);
  document.add(Chunk.NEWLINE);
  document.add(Chunk.NEWLINE);
  document.add(new LineSeparator());
  document.add(Chunk.NEWLINE);
  document.add(new LineSeparator());
  document.add(Chunk.NEWLINE);
  document.add(Chunk.NEWLINE);
  document.add(new Paragraph("Brokers's digital signature Clients's digital signature"));

  PdfFormField field1 = PdfFormField.createSignature(writer);
  field1.setWidget(new Rectangle(72, 100, 172, 200), PdfAnnotation.HIGHLIGHT_INVERT);
  field1.setFieldName("mySig1");
  field1.setTitle("Klijent1");
  field1.setFlags(PdfAnnotation.FLAGS_PRINT);
  field1.setPage();
  PdfAppearance tp1 = PdfAppearance.createAppearance(writer, 72, 48);
  tp1.rectangle(0.5f, 0.5f, 71.5f, 47.5f);
  tp1.stroke();
  field1.setAppearance(PdfAnnotation.APPEARANCE_NORMAL, tp1);
  writer.addAnnotation(field1);

  PdfFormField field2 = PdfFormField.createSignature(writer);
  field2.setWidget(new Rectangle(372, 100, 472, 200), PdfAnnotation.HIGHLIGHT_INVERT);
  field2.setFieldName("mySig2");
  field2.setTitle("Klijent2");
  field2.setFlags(PdfAnnotation.FLAGS_PRINT);
  field2.setPage();
  PdfAppearance tp2 = PdfAppearance.createAppearance(writer, 72, 48);
  tp2.rectangle(0.5f, 0.5f, 71.5f, 47.5f);
  tp2.stroke();
  field2.setAppearance(PdfAnnotation.APPEARANCE_NORMAL, tp2);
  writer.addAnnotation(field2);

  document.close();

我确实用过

public static final String FONT = "C:/Windows/Fonts/segoeui.ttf";   
bf = BaseFont.createFont(FONT, BaseFont.IDENTITY_H, BaseFont.EMBEDDED);
document.add(new Paragraph(title,new Font(bf, 12)));

购买一些其他字体,但它并没有帮助看起来像这样的文本“o deponovanim novčanim”转移到这个“o deponovanim nov&#.....”,stackoverflow 显示它是一样的。所以在 pdf 中,我得到了我的信件的 html 代码。如何正确显示。

4

1 回答 1

1

请将title和的值text以纯文本形式写入日志文件。它们包含相同的 HTML 代码的可能性为 99.9%。如果他们这样做,您就没有与 iText 相关的问题。相反,您遇到了 Servlet 问题;-)

于 2013-05-02T17:08:23.767 回答