Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Continuous text in text-area cuts the PDF overflowing the text when using Itext 7.1.7

I see there are lot many questions related to the same scenario this one is little different couldn't figure out the solution. I have a in a tabl in a cell. When I give the continous text like "cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc" Its overflowing the text when I download the print file and its normal when I give normal text with breaks.Here is my code

.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>

please find the pictures it for clear overview This is the entry

I have a click like Go once I do it it downloads the entire document here using JAVA code and the code part is working Good but the issue is with itext 7.1.7. this is happening and I have changed it to flying saucer its working good but causing other issues. I want to stay with Itext 7.1.7 and solve this continuous fix.

This is the pdf

like image 479
Juke Avatar asked May 31 '19 15:05

Juke


2 Answers

pdfHTML allows you to either convert the form-related elements (inputs, text areas) directly into the plain PDF content, or create a PDF with AcroForm (so that those elements are editable, as they are supposed to be in HTML).

To enable that behavior, you should use setCreateAcroForm(true) in ConverterProperties that you pass to HtmlConverter.

If you don't want to have those fields editable, you can flatten those fields as a second step after you have converted the HTML into PDF.

Having that said, the behavior you describe looks like a bug in iText. But the mode of creating the AcroForm and flattening is implemented in a slightly different way and it looks like the textarea would be converted as expected in your case. You haven't attached the whole example so it's hard to verify for sure, but for the small snippet you attached everything is fine. Here is the code you can use:

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();
like image 71
Alexey Subach Avatar answered Oct 12 '22 00:10

Alexey Subach


You can detect whenever the text reaches a new line in the input box, and insert '\n' to force line breaks so that when you download an image, it should have the line break hard-coded. Hope this helps!

like image 23
Beckett O'Brien Avatar answered Oct 12 '22 00:10

Beckett O'Brien