Why lengthy string is rendering in multiple pages in pdf while using smart markers in Java

template1.zip (60.2 KB)
I’m trying to use the smart markers in java application to generate the pdf report but
Lengthy string is rendering in multiple pages in pdf while using smart markers in Java.
like in one page one line of text and in 2nd page another line of text. please refer the output pdf.
Please find the attached template file having smart markers and output pdf file as welSample2.pdf (61.3 KB)
l.

NOTE1: I tried with the below specified code for work around , but did not work.
Worksheet worksheet = workbook.getWorksheets().get(0);
worksheet.autoFitRows();
worksheet.autoFitColumns();

NOTE2: I tried with below specified code , but it’s rendering the entire text in one, which i do not require.
// PdfSaveOptions ps = new PdfSaveOptions();
// ps.setAllColumnsInOnePagePerSheet(true);

------------------------------------ w.getWorkbook().save(“H:\mytickets_fenis\AsposePoc\src\main\resources\Sample2.pdf”, ps);

But I need to generate the pdf report having paragraphs with no of lines for example:

The sample lengthy string is Below specified :

“Since your serial number column does not come from your source and exists outside of Smart Markers, so you cannot evaluate auto-numbers in the data source or in smart markers. You have to insert/merge those serial numbers manually after your markers are processed and data is filled into the cells. For example, you may count the number of records/rows in your custom list, so you may insert counter (serial numbers) into the cells of the first column via Cell.putValue() method. You may simply use some loop to be iterated upto number of records in the list to specify the (variable) counter (e.g. cnt++) to be inserted into the cells of the column accordingly.”;

like the above paragraphs.
Could you please suggest/provide the idea to achieve my requirement.

below is the snippet in java:

I’m using aspose-cells 21.9 version.

String s = “Since your serial number column does not come from your source and exists outside of Smart Markers, so you cannot evaluate auto-numbers in the data source or in smart markers. You have to insert/merge those serial numbers manually after your markers are processed and data is filled into the cells. For example, you may count the number of records/rows in your custom list, so you may insert counter (serial numbers) into the cells of the first column via Cell.putValue() method. You may simply use some loop to be iterated upto number of records in the list to specify the (variable) counter (e.g. cnt++) to be inserted into the cells of the column accordingly.”;

WorkbookDesigner w = new WorkbookDesigner();
byte[] photo1 = Files.readAllBytes(Paths.get(“H:\mytickets_fenis\AsposePoc\src\main\resources\SmartMarkers\TMS.PNG”));
Workbook workbook = new Workbook(“H:\mytickets\AsposePoc\src\main\resources\template1.xlsx”);
w.setWorkbook(workbook);
List ds = new ArrayList<>();
ds.add(new DataSource(“abc”, "def xyz address line 1 ",
“Cust 8978123 address line 2”, s,
“apuy897”, “United nations”, “1testsubject 2testsubject 3testsubject 4testsubject 5testsubject”));
w.setDataSource(“DS”, ds);
w.process(); w.getWorkbook().save(“H:\mytickets\AsposePoc\src\main\resources\Sample2.pdf”);


This Topic is created by amjad.sahi using Email to Topic tool.

You may set IsTextWrapped as true for corresponding cell in your template file, or by code as below before you call auto-fit:

            style = cell.GetStyle();
            style.IsTextWrapped = true;
            cell.SetStyle(style);

Moreover, you may try to do two things in the template Excel file containing smart markers and re-save it to be used by Aspose.Cells for Java API:

  1. Change the marker “&=DS.add3” to “&=DS.add3(noadd)”.
  2. Right click on A14 cell and open Formula Cells… dialog box. Now click “Wrap text” in Alignment tab.

I am not sure about DataSource and how do you create the class. In case, you still find the issue, could you please share a standalone sample console application which we could execute to get the resultant PDF file. This will help us to evaluate your issue and we can assist you better.

Hi,
Thanks for the quick response.
I already tried with those options as you all specified/suggested, But that did not work well, Getting the one page but most of the text is missing. I attached the report and the source code as well. Please check and suggest the ideas to resolve.
smartmarker-issue.zip (65.4 KB)

Thanks.

@Rakesh_M,
After setting the data, run the relevant methods of auto fit to expand rows and columns based on strings.
So please move the following code before the save method.

        worksheet.autoFitRows();
        worksheet.autoFitColumns();

Hi,
I already tried this as well, But this is also not working.

@Rakesh_M,

Please make sure that you call Worksheet.autoFitRows() after designer.process() method. I did test your scenario/case using the simplest lines of code and it works fine:
e.g.
Sample code:


String s = "Since your serial number column does not come from your source and exists outside of Smart Markers, so you cannot evaluate auto-numbers in the data source or in smart markers. You have to insert/merge those serial numbers manually after your markers are processed and data is filled into the cells. For example, you may count the number of records/rows in your custom list, so you may insert counter (serial numbers) into the cells of the first column via Cell.putValue() method. You may simply use some loop to be iterated upto number of records in the list to specify the (variable) counter (e.g. cnt++) to be inserted into the cells of the column accordingly.";

Workbook workbook = new Workbook();
WorkbookDesigner designer = new WorkbookDesigner();
designer.setWorkbook(workbook);
Worksheet w = workbook.getWorksheets().get(0);
w.getCells().get("A1").putValue("&=$VariableArray");
w.getCells().setColumnWidth(0, 38);
Style style = w.getCells().get("A1").getStyle();
style.setTextWrapped(true);
w.getCells().get("A1").setStyle(style);

// Set the DataSource for the marker(s).
designer.setDataSource("VariableArray", new String[] {s});
PdfSaveOptions ps = new PdfSaveOptions();
ps.setAllColumnsInOnePagePerSheet(true);
designer.process();

w.autoFitRows();

designer.getWorkbook().save("f:\\files\\out_java121.pdf", ps);
workbook.save("f:\\files\\out_java121.xlsx"); 

Please find attached the output files for your reference.
out_java121.zip (28.6 KB)