For some TXT and CSV files (mostly small files) conversions to PDF without LoadOptions do not generate PDF document. Generated output contains input file content - it’s not PDF document.
Adding to converter CsvLoadOptions/TxtLoadOptions objects resolve problem
OS: Windows 11 Pro (22H2)
JAVA: Eclipse Temurin / Adoptium. jdk-17.0.8.1+1
GroupDocs Conversion: 23.10
test-files.zip (305 Bytes)
Source code:
import com.groupdocs.conversion.Converter;
import com.groupdocs.conversion.licensing.License;
import com.groupdocs.conversion.options.convert.PdfConvertOptions;
import com.groupdocs.conversion.options.load.CsvLoadOptions;
import com.groupdocs.conversion.options.load.TxtLoadOptions;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import lombok.val;
public class TxtCsvConversionSample {
public static void main(String[] args) throws Exception {
val licenseFile = new File(args[0]);
val csvFile = new File(args[1]);
val txtFile = new File(args[2]);
val convertDocLicense = new License();
convertDocLicense.setLicense(new FileInputStream(licenseFile));
val csvLoadOptions = new CsvLoadOptions();
val txtLoadOptions = new TxtLoadOptions();
val convertOptions = new PdfConvertOptions();
val csv1InputStream = new FileInputStream(csvFile);
val csv2InputStream = new FileInputStream(csvFile);
val csvOkOutputStream = new FileOutputStream("csv2pdf-ok.pdf");
val csvErrorOutputStream = new FileOutputStream("csv2pdf-error.pdf");
val csvWithOptionsConverter = new Converter(() -> csv1InputStream, () -> csvLoadOptions);
csvWithOptionsConverter.convert(() -> csvOkOutputStream, convertOptions);
val csvWithoutOptionsConverter = new Converter(() -> csv2InputStream);
csvWithoutOptionsConverter.convert(() -> csvErrorOutputStream, convertOptions);
val txt1InputStream = new FileInputStream(txtFile);
val txt2InputStream = new FileInputStream(txtFile);
val txtOkOutputStream = new FileOutputStream("txt2pdf-ok.pdf");
val txtErrorOutputStream = new FileOutputStream("txt2pdf-error.pdf");
val txtWithOptionsConverter = new Converter(() -> txt1InputStream, () -> txtLoadOptions);
txtWithOptionsConverter.convert(() -> txtOkOutputStream, convertOptions);
val txtWithoutOptionsConverter = new Converter(() -> txt2InputStream);
txtWithoutOptionsConverter.convert(() -> txtErrorOutputStream, convertOptions);
}
}