CSV to PDF conversion - issue with Japanese characters in the PDF using Java

Hi,
I am using aspose-cells java (version 21.4) to convert a CSV file to PDF. The CSV file has some Japanese characters. When this file is converted to PDF, the Japanese characters are not printed properly. Also the columns alignment is not proper for all rows(Even when a CSV with only EN characters are converted to PDF).
I have used the following lines of code for conversion.

LoadOptions opts = new LoadOptions(LoadFormat.CSV);
Workbook csvworkbook = new Workbook(inputStream, opts);
csvworkbook.save("csv-to-pdf.pdf", com.aspose.cells.SaveFormat.PDF);

When the same data is added in ods and converted to pdf, the pdf conversion is fine.
I have attached the .csv and also the .ods files I used for conversion.
csv-issue.7z (45.9 KB)

Kindly help me to resolve this issue.

Regards,
Raz

@dev.raz,

I opened your CSV and ODS files into MS Excel manually and found CSV file is displayed differently than ODS, see the screenshot attached. That’s why, the output PDF file (by Aspose.Cells) is not rendered fine. Please give us a CSV file that should be displayed fine into MS Excel, so we could evaluate and test your conversion on our end.
sc_shot1.png (51.9 KB)

Thank you @Amjad_Sahi for the quick response. I created that CSV with Apache open office. When I open the CSV file with Open Office, the file opens correctly. I set Character Set as Japanese (Shift-JIS) while opening the file. Is there any limitations for aspose.cells that I need to consider before converting CSV to PDF?

CSV-open-settings.PNG (20.2 KB)

@dev.raz,

Thanks for providing further details.

Please try the following sample code to get better resultant PDF file:
e.g.
Sample code:

TxtLoadOptions opts = new TxtLoadOptions(LoadFormat.CSV);
opts.setEncoding(Encoding.getEncoding("Shift_JIS"));
Workbook csvworkbook = new Workbook("f:\\files\\zsample.csv", opts);
csvworkbook.save("f:\\files\\csv-to-pdf.pdf", com.aspose.cells.SaveFormat.PDF);

Hope, this helps a bit.

@Amjad_Sahi

Thanks for the suggestion. Setting Encoding rendered the Japanese characters.
But as I mentioned here,

The column width is not set equally for all rows. Refer this image.
Col-width-issue.PNG (9.8 KB)

I tried setting the AutoFitterOptions but that doesn’t fix the problem.
Sample code:

TxtLoadOptions opts = new TxtLoadOptions(LoadFormat.CSV);
opts.setEncoding(Encoding.getEncoding("Shift_JIS"));
Workbook csvworkbook = new Workbook("f:\\files\\zsample.csv", opts);
AutoFitterOptions afo = new AutoFitterOptions();
afo.setAutoFitWrappedTextType(AutoFitWrappedTextType.PARAGRAPH);
csvworkbook.getWorksheets().get(0).autoFitColumns(afo);
csvworkbook.save("f:\\files\\csv-to-pdf.pdf", com.aspose.cells.SaveFormat.PDF);

Could you provide a solution for this issue.?

@dev.raz,

You are right. By setting encoding, Japanese chars are displayed but still the columns alignment and widths are not proper for all the rows when rendering data with Japanese chars to PDF file format. I tried some options but to no avail. I have logged a ticket with an id “CELLSJAVA-43461” for your issue. Please spare us little time to evaluate your issue thoroughly. Hopefully we will figure out your issue soon.

Once we have an update on it, we will update you.

@dev.raz,
The default separator for Csv file is comma, however the separator for the your file is tab. So set separator to tab will be OK: TxtLoadOptions.setSeparator('\t')

Code:

TxtLoadOptions opts = new TxtLoadOptions(LoadFormat.CSV);
opts.setEncoding(Encoding.getEncoding("Shift_JIS"));
//set separator to tab
opts.setSeparator('\t');
Workbook csvworkbook = new Workbook("f:\\files\\zsample.csv", opts);
AutoFitterOptions afo = new AutoFitterOptions();
//afo.setAutoFitWrappedTextType(AutoFitWrappedTextType.PARAGRAPH);
csvworkbook.getWorksheets().get(0).autoFitColumns(afo);
csvworkbook.save("f:\\files\\csv-to-pdf.pdf", com.aspose.cells.SaveFormat.PDF);

@ahsaniqbalsidiqui

Thankyou. That worked.

@dev.raz,

Good to know that your issue is resolved by the suggested code segment. In the event of further queries or issue, feel free to write us back.