Image distorted while converting excel to pdf

Both excel and PDF files are attached, please check issue docuIssues.zip (2.2 MB)
ment with screenshots001_Garment_Specification_85800_04082018_1116.zip (506.9 KB)

@sreeni.ravulapati

For your 001_Garment_Specification_85800_04082018_1116.xls

We were able to observe this issue and logged it in our database for investigation and for a fix. Once, the issue is resolved or we have some other news for you, we will update you asap.

This issue has been logged as

  • CELLSJAVA-42582 - Image is distorted while converting Excel to Pdf

For your Copy of 001_Garment_Specification_12600_04092018_1241.xls

We have tested this issue with the following code using the most recent version i.e. 18.3.5 and found the output Pdf is good.

Java

Workbook wb = new Workbook(in);
wb.save("out.pdf");

Download Link:
out2.pdf (1.9 MB)

@shakeel.faiz

As you suggested , we installed 18.3.5 still issue persist, also image quality (size) getting distorted, please take look at document.
Below is code for excel to PDF.
public static String convertExcelToPDF (String filePathStr){

	    Workbook workbook = null;
		try{
			com.aspose.cells.License license = new com.aspose.cells.License();
			license.setLicense("Aspose.Cells.lic");
		if (License.isLicenseSet()) {
			    System.out.println("License is Set!***********");
			}
			FontConfigs.setFontFolder("/usr/share/fonts/msttcore", true);
			workbook = new com.aspose.cells.Workbook(filePathStr);
			WorksheetCollection workSheetColl = workbook.getWorksheets();
			Worksheet specReport = workSheetColl.get(0);
			specReport.autoFitRows();
			Worksheet revisionLogSheet = workSheetColl.get(1);
			revisionLogSheet.autoFitRows();
			if("004_Packaging_and_Folding".equalsIgnoreCase(filePathStr)){
				Worksheet gtin = workSheetColl.get(2);
				gtin.autoFitRows();
			}
			PdfSaveOptions pdfSaveOptions = new PdfSaveOptions();
			pdfSaveOptions.setOnePagePerSheet(true);
			pdfSaveOptions.setAllColumnsInOnePagePerSheet(true);
		   	workbook.save(filePathStr.split(".xls")[0]+".pdf", pdfSaveOptions);
		} catch (Exception e) {
				e.printStackTrace();
		}
		
		logger.debug("After conversion filePathStr*****"+ filePathStr.split(".xls")[0]+".pdf");
		return filePathStr.split(".xls")[0]+".pdf";
			  
	  
  }

ImageIssue.zip (2.6 MB)

@sreeni.ravulapati

Thanks for using Aspose APIs.

Please try the following sample code and let us know if it generates correct results. Please share the output Excel file generated by the code for a reference.

It will help us identify if the issue is existing because of code or because of some bug in Aspose.Cells.

Java

Workbook wb = new Workbook(dirPath + "001_Garment_Specification_12600_04102018_1837.xls");

PdfSaveOptions opts = new PdfSaveOptions();
opts.setOnePagePerSheet(true);

wb.save(dirPath + CellsHelper.getVersion() + "-output.pdf", opts);

@sreeni.ravulapati

We have looked into your issue further and found that your code is using sheet.autofitRows() that makes the row height changes and the image property is Move but don’t size with cells, so after sheet.autofitRows(), the image exceeds rows in the output pdf.

FYI:
If you manually autofit rows in Microsoft Excel, you will also find this issue.

@shakeel.faiz

So what is the solution for this issue.

Sreeni

Aspose version :18.3.5, attached pdf has the version in the name
001_Garment_Specification_12600_04112018_055918.3.5001_Garment_Specification_12600_04112018_055918.3.5.pdf (1.9 MB)

@sreeni.ravulapati

We are afraid, there is no good solution for it. Because if you will change the row heights, the images that were aligned previously will no more be aligned.

However, you may try the following code and see if it works fine for you.

Java

//Specify Auto Fitter Options - Auto Fit Only Auto 
AutoFitterOptions autoOpts = new AutoFitterOptions();
autoOpts.setOnlyAuto(true);

//Autofit Worksheet Rows	
worksheet.autoFitRows(autoOpts);

@shakeel.faiz

Still image size is not as excel after specifying auto fitter options, please take look at attached doc.
Now this issue (image size/quality) become show stopper for project, please advise.

SreeniImage Qality Issue2.zip (451.3 KB)

@sreeni.ravulapati

We are afraid, we still could not replicate your issue. Please provide us the following things.

1 - Environment/OS/JDK Settings
2 - Are you using JAI (Java Advanced Imaging) API?
3 - Runnable Sample Code (Exact code where we don’t have to do any modification)
4 - Sample Excel File being used inside the code, it should also be exact. Do not provide copy of it.
5 - PDF file generated by you on your machine for our comparison.

@shakeel.faiz

Ok, I will get all the requested info mean while, please could you send output and sample code your using?

Sreeni

@sreeni.ravulapati

Here is the code we used to test this issue.

Java

Workbook workbook = new com.aspose.cells.Workbook(dirPath + "001_Garment_Specification_12600_04102018_1837.xls");
WorksheetCollection workSheetColl = workbook.getWorksheets();

Worksheet specReport = workSheetColl.get(0);
specReport.autoFitRows();

Worksheet revisionLogSheet = workSheetColl.get(1);
revisionLogSheet.autoFitRows(true);

PdfSaveOptions pdfSaveOptions = new PdfSaveOptions();
pdfSaveOptions.setOnePagePerSheet(true);
pdfSaveOptions.setAllColumnsInOnePagePerSheet(true);

workbook.save(dirPath + CellsHelper.getVersion() + "-output.pdf", pdfSaveOptions);

@shakeel.faiz

Issue narrow down to that, if excel file open manually, enable printer and save then PDF file generating correctly, otherwise it is not generating correctly (image getting small).
So look like need set printer settings, here is printer setting : Print One sided, Collated, Landscape Orientation, Legal 8.5" x 14, Narrow Margins :Left 0.25", Right 0.25", Top:0.75’’ bottom0.75" Header 0.3, Fotter 0.3, Fit Sheet on Pne Page,.
Please advise, it is very high priority for go live.
Excel file1_Working.zip (2.0 MB)

Excel file without printer settingsExcel_file_notworking.zip (2.5 MB)

Correct PDF file attchedNEW_ABC.xlsThu Apr 12 22:40:15 EDT 2018_SreeOutputFile.pdf (1.9 MB)

not good pdf file attachNEW_ABC.xlsThu Apr 12 21:43:53 EDT 2018_SreeOutputFile.pdf (1.9 MB)
ed

Now, Printer setting also added, still same issue. java file attached. take a look.
Also do we need to add printer setting to excel file to generate pdf correctly?

SreeniLatestVerExcelToPDF.zip (1.7 KB)

@sreeni.ravulapati

Please download the modified code and try it at your end. It works fine as we have tested it. The code is same as yours except we have removed the page setup settings and added changing the shape placement as MOVE_AND_SIZE so that pictures got adjusted when heights of the row change. Besides, auto height row is true as it is the problem of auto height row.

Sample Code Link:
modifiedLatestVerExcelToPDF_placement.zip (1.7 KB)