CSV to PDF Crops Words in Java

Hello,
I noticed CSV to PDF crops words in Java. I am converting CSV to PDF but some cell have 50+ characters but showing output file have only 20 character approx.
I used below code:

Workbook book = new Workbook(Filename);
book.save(Pathdata + File.separator+ Fname + ".pdf", SaveFormat.PDF); 

I also attached file Excel Test.zip (363.9 KB)

I also attached screen shot Screenshot (18).png (68.2 KB)

Thanks

@David_jack
Aspose.Cells works as MS Excel.If you open the csv file in MS Excel, you will view the same result as generated pdf.
If you want to show all character, please auto fit width of the columns as the following codes before saving:
Workbook book = new Workbook( “Excel Test.csv”);
book.getWorksheets().get(0).autoFitColumns();//auto fit width of the columns
book.save(“dest.pdf”);

Hello @simon.zhao
thx for solution
one file is not converted by the above code showing exception Invalid end row index.
I attached file csvFile.zip (4.5 MB)

please check this file.

@David_jack
It’s the limitation of MS Excel. If you do not want to check the limitation of MS Excel,please set TxtLoadOptions .CheckExcelRestriction as the following codes:
TxtLoadOptions loadOptions = new TxtLoadOptions(LoadFormat.Csv);
loadOptions.CheckExcelRestriction = false;
Workbook wb = new Workbook(dir + “Main_types_of_fuel_long_updated_16-7-20.csv”, loadOptions);

Hello @simon.zhao
i used below code in java using aspose cell 21.10
TxtLoadOptions loadOptions = new TxtLoadOptions(LoadFormat.CSV);
loadOptions.setCheckExcelRestriction(false);
Workbook book = new Workbook(Filename,loadOptions);
book.getWorksheets().get(0).autoFitColumns();
pageSetup.setOrientation(PageOrientationType.LANDSCAPE);
book.save(Pathdata + File.separator + Fname + “.pdf”, SaveFormat.PDF);

your code not valid
loadOptions.CheckExcelRestriction = false;
so i used loadOptions.setCheckExcelRestriction(false);
but same error (Invalid end row index.) in same file (Main_types_of_fuel_long_updated_16-7-20.csv) upload earlier
one more file have same issue i attached file issue.zip (8.7 MB)

so my issue not resolved plz suggest

@David_jack,

We noticed this issue as you mentioned. Do you need to export all the rows of CSV file (even that are beyond the limitation of MS Excel (1,048,576 rows by 16,384 columns)), please confirm? After your confirmation, we will log appropriate ticket for your issue/requirements.

@Amjad_Sahi
yes we need this , so please resolve this as soon as possible

Can we add watermark / image in all pages of pdf while using above code in this thread . If yes please suggest code for java.
Thanks

@David_jack,

Thanks for your confirmation.

We have logged a ticket with an id “CELLSJAVA-44070” for your issue. The issue is logged as following:
CELLSJAVA-44070 - Exception “Invalid end row index” in CSV to PDF rendering

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

See the document with example code on how to add watermark to the worksheet for your reference. You need to embed such a code before rendering to PDF file format.

@Amjad_Sahi

See the document with example code on how to add watermark to the worksheet for your reference. You need to embed such a code before rendering to PDF file format.
This work only on 1st page other pages not showing watermark as i mentioned i need all pages watermark
I attached output file and input file file.zip (51.6 KB)

@David_jack,

Yes, in that case, you need to insert watermark to each and every page in the worksheet.

@Amjad_Sahi
(RE: csv to pdf watermark not set in every pages of pdf )
can know how it possible in java.
i Am searching code put every page water mark but not found so plz suggest .

And one more question can we blur few pages of pdf? or any restriction can apply to pdf

@David_jack,

You should write your own code and logic to paste word art watermark to every page of the worksheet. I have written a sample code to accomplish the task for your reference. Please refer to it for reference and write/update your own code accordingly:
e.g.
Sample code:

TxtLoadOptions loadOptions = new TxtLoadOptions(LoadFormat.CSV);
        loadOptions.setCheckExcelRestriction(false);
        Workbook workbook = new Workbook("f:\\files\\mid1234.csv",loadOptions);

        Worksheet worksheet = workbook.getWorksheets().get(0);
        worksheet.autoFitColumns();
        worksheet.getPageSetup().setOrientation(PageOrientationType.LANDSCAPE);
        ImageOrPrintOptions printoption = new ImageOrPrintOptions();
        printoption.setPrintingPage(PrintingPageType.DEFAULT);
        SheetRender sr = new SheetRender(worksheet, printoption);
        int pageCount = sr.getPageCount();
        System.out.println(pageCount);
        CellArea [] area = worksheet.getPrintingPageBreaks(printoption);
        System.out.println(area.length);
        int strow = 0;
        int stcol = 0;
        for(int i =0 ;i<area.length;i++)
        {
            //Get each page range/area.
            strow = area[i].StartRow;
            stcol = area[i].StartColumn;

            // Add Watermark
            com.aspose.cells.Shape wordart = worksheet.getShapes().addTextEffect(MsoPresetTextEffect.TEXT_EFFECT_1, "CONFIDENTIAL",
                    "Arial Black", 50, false, true, strow + 18, 8, stcol+ 1, 0, 130, 800);
            // Get the fill format of the word art
            FillFormat wordArtFormat = wordart.getFill();
            // Set the color
            wordArtFormat.setOneColorGradient(com.aspose.cells.Color.getRed(), 0.2, GradientStyleType.HORIZONTAL, 2);
            // Set the transparency
            wordArtFormat.setTransparency(0.9);

            // Make the line invisible
            LineFormat lineFormat = wordart.getLine();
            lineFormat.setWeight(0.0);
        }

        workbook.save("f:\\files\\out1.pdf", SaveFormat.PDF);

You cannot blur PDF pages as Aspose.Cells is spreadsheet file format APIs and not PDF manipulation API. Aspose.Cells for Java only provides some security options that you may apply but it will be applied to the PDF document as a whole.

@David_jack
Please try the lastest fix 21.11.7.
(https://forum.aspose.com/uploads/default/57690) (7.5 MB)
We have fixed the issue of throwing Exception, but the data beyond the limitation of MS Excel is lost in generated pdf file. We are still working on it.

@David_jack
Please set TxtLoadOptions.ExtendToNextSheet property to extend data to next sheet when the rows or columns of data exceed limit.

The issues you have found earlier (filed as CELLSJAVA-44070) have been fixed in Aspose.Cells for Java 23.3.