java - 使用 Itext 7.1.7 时,文本区域中的连续文本会剪切溢出文本的 PDF

标签 java html css textarea itext7

我看到有很多问题与同一场景相关,但这个场景略有不同,无法找出解决方案。我在一个单元格的表格中有一个。当我给出像“cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc”这样的连续文本时,当我下载打印文件时它会溢出文本,而当我给出带有中断的普通文本时它会正常。这是我的代码

.generaltable {
	background-color : #5C7FBF;
	border:thin;
	width : 100%;
	font-family: Arial, Helvetica, sans-serif;
	font-size: 14px;
	}
  
  
	.column {
	background-color : #DEEDFF;
	font-weight : bold;
	padding-bottom : 1px;
	padding-left : 1px;
	padding-right : 1px;
	padding-top : 1px;
	text-align : center;
	font-family: Arial, Helvetica, sans-serif;
	font-size: 14px;
	border: none;
	}
  
 .edit {
	background-color : #DEEDFF;
	border-width: 1px;
	border-style:solid;
	border-color:#DEEDFF;
	border: 1px solid #DEEDFF;
	color: black;
	text-align : left;
	font-weight : bold;
	font-family: Arial, Helvetica, sans-serif;
	font-size: 14px;
	word-break: break-all;
	}
  
  .iedit2 {
	background-color : white;
	text-align: left;
	color: black;
	font-family: Arial, Helvetica, sans-serif;
	font-weight: bold;
	border-top: 1px solid #999999;
	border-right: 1px solid #333333;
	border-bottom: 1px solid #333333;
	border-left: 1px solid #999999;
	word-break: break-all;
	}
  
  
  
  
  
<table border="1" width="100%" align="center" cellpadding="2" cellspacing="1"  class="generaltable">  <tbody><tr id="Row35494#0">
    <th id="04" class="column" width="39%"><a href="javascript:alert('Self Explanatory')">Brief                 description of the issue *</a></th>
        <td id="1 04" width="39%" class="edit">
            <textarea id="269494_0" class="iedit2" cols="35" rows="5" wrap="virtual" maxlength="4000"                   name="fiy">ssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssss
             </textarea>
        </td>
      </tr>
  </tbody>
 </table>

请找到图片以获得清晰的概览This is the entry

一旦我点击了 Go,它就会使用 JAVA 代码在此处下载整个文档,并且代码部分运行良好,但问题出在 itext 7.1.7 上。这种情况正在发生,我已将其更改为飞碟,它工作正常但会导致其他问题。我想继续使用 Itext 7.1.7 并解决这个连续修复。

This is the pdf

最佳答案

pdfHTML 允许您将与表单相关的元素(输入、文本区域)直接转换为纯 PDF 内容,或使用 AcroForm 创建 PDF(以便这些元素是可编辑的,因为它们应该在 HTML 中) .

要启用该行为,您应该在传递给 HtmlConverterConverterProperties 中使用 setCreateAcroForm(true)

如果您不想让这些字段可编辑,您可以在将 HTML 转换为 PDF 后将这些字段拼合为第二步。

话虽如此,您描述的行为看起来像是 iText 中的错误。但是创建 AcroForm 和展平的模式是以稍微不同的方式实现的,看起来文本区域会按照您的情况进行转换。您没有附上整个示例,因此很难确定地验证,但是对于您附上的小片段,一切都很好。这是您可以使用的代码:

ByteArrayOutputStream baos = new ByteArrayOutputStream();
HtmlConverter.convertToPdf(new FileInputStream("C:\\file.html"), baos,
        new ConverterProperties().setCreateAcroForm(true));

PdfDocument document = new PdfDocument(new PdfReader(new ByteArrayInputStream(baos.toByteArray())), 
        new PdfWriter(new File("C:\\out.pdf")));
PdfAcroForm acroForm = PdfAcroForm.getAcroForm(document, false);
acroForm.flattenFields();
document.close();

关于java - 使用 Itext 7.1.7 时,文本区域中的连续文本会剪切溢出文本的 PDF,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56397796/

相关文章:

javascript - 如何使我的 div 在调整大小处理程序 dragg 上调整大小?

javascript - HTML:停止在 div 中呈现 HTML 代码

html - 生成 html 作为输出的 UI 原型(prototype)工具

css - 溢出 : hidded doesn't work when hiding an absolute positioned div

css - <div> 旁边的另一个 <div> 内的 <div> 的全尺寸

java - 包含另一个小部件的 gwt 小部件 : 2 different clickhandlers

java - AtomicInteger.updateAndGet() 和 AtomicInteger.accumulateAndGet() 之间在功能上有什么区别吗?

html - Div 围绕定义列表折叠

java - Android中命令包含中文或空格时如何发送HTTP命令?

java - 如何避免重复出现相同的号码?