Я создал проект, в котором я извлек несколько строк из текстового файла и сохранил их в формате pdf. Мой код для получения строк из текстового файла
while (scanner.hasNextLine()) {
final String lineFromFile = scanner.nextLine();
lineID++;
if(lineFromFile.contains(phrase)) {
//String output=scanner.nextLine();
int lineno=lineID;
while (scanner.hasNextLine()) {
//output=scanner.nextLine();
//res.add(output);
lineID++;
fileContents.append(scanner.nextLine() + System.lineSeparator());
// arr.add(scanner.nextLine());
if(lineID==lineno+13)
{
break;
}
//System.out.println(output);
///temp=output;
}
// System.out.println(scanner.nextLine());
System.out.println("I found " +phrase+ " in line no " +lineID );
}
}
String listString = fileContents.toString();
System.out.println(listString);
Это дает такой вывод в консоли
Active Internet connections (servers and established)
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp 0 0 127.0.0.1:82 0.0.0.0:* LISTEN 3202/docker-proxy
tcp 0 0 127.0.0.53:53 0.0.0.0:* LISTEN 1227/systemd-resolv
tcp 0 0 127.0.0.1:37335 0.0.0.0:* LISTEN 1553/containerd
tcp 0 0 127.0.0.1:631 0.0.0.0:* LISTEN 1425/cupsd
tcp 0 0 0.0.0.0:443 0.0.0.0:* LISTEN 1704/nginx: master
tcp 0 0 192.168.0.4:443 192.168.0.96:51114 TIME_WAIT -
tcp 0 0 10.10.100.140:49376 52.25.121.22:443 ESTABLISHED 6289/firefox
tcp 0 0 192.168.0.4:41382 192.168.0.96:22 TIME_WAIT -
tcp 0 0 192.168.0.4:443 192.168.0.96:51148 TIME_WAIT -
tcp6 0 0 ::1:631 :::* LISTEN 1425/cupsd
tcp6 0 0 :::443 :::* LISTEN 1704/nginx: master
, который чистый и аккуратный, в простом для понимания формате, но когда я пишу та же строка для элемента парагаф в pdf, используя этот код Предисловие к абзацу = new Paragraph ();
// We add one empty line
addEmptyLine(preface, 3);
document.add(preface);
ParagraphBorder border = new ParagraphBorder();
String str[] = output.split("\\r?\\n");
java.util.List<String> al = new ArrayList<String>();
al = Arrays.asList(str);
Paragraph p = new Paragraph("Description:"+System.lineSeparator()+ output.trim(), FontFactory.getFont("ARIAL", 9));
document.add(p);
я получаю файл pdf, как это ![enter image description here](https://i.stack.imgur.com/RbmR2.png)
which is not as good as i get in console. So how to allign like this one with border.
введите описание изображения здесь