How to convert TXT to PDF

bot-task
pdf
txt

#1

Just pasting it here, as it could be helpful for everyone:

<?xml version="1.0" encoding="UTF-8"?>
<config charset="UTF-8">
  
  	<script><![CDATA[

		import org.apache.commons.lang.StringUtils;
		import java.io.InputStream;
		import java.net.URL;
		import java.net.URLConnection;

		import java.io.*;
        
        import com.lowagie.text.*;
        import com.lowagie.text.pdf.*;


		URL url = new URL("https://website.com/some_txt_file.txt");
        URLConnection connection = url.openConnection();
        InputStream inputStream = connection.getInputStream();

	
		BufferedReader input = null;
        Document output = null;
        System.out.println("Convert text file to pdf");

  
        input =  new BufferedReader (new InputStreamReader(inputStream, "UTF-8"));
        // letter 8.5x11  see com.lowagie.text.PageSize for a complete list of page-size constants.
        output = new Document(PageSize.LETTER, 40, 40, 40, 40);
  
		PdfWriter.getInstance(output, new FileOutputStream ("/tmp/output_pdf_file.pdf"));
        
        output.open();
        output.addAuthor("Test Author");
        output.addSubject("Test Subject");
        output.addTitle("Test Test");
        
        String line = "";
        while(null != (line = input.readLine())) {
			System.out.println(line);
			Paragraph p = new Paragraph(line);
			p.setAlignment(Element.ALIGN_JUSTIFIED);
			output.add(p);
        }
        System.out.println("Done.");
        output.close();
        input.close();

	]]></script>
  
	<export include-original-data="true">
	</export>
</config>