Convert Excel to PDF or PDF/A using threads

Aspose.Cells for Java

Hello,

When I try to convert these two excel files, attached in this topic, to PDF/A, I got a weird PDF.
This happens only the first time. If I try to convert them again it works.
Each thread has its own Workbook.
How to fix that? I am using Aspose.Cells for Java 17.6 (Latest)
If I try convert to PDF instead of PDF/A, problem is the same.

files.zip (78.4 KB)

@cpatricio76

Thanks for your posting and using Aspose.Cells.

We have tested your issue with multiple threads and we are not able to observe this issue. Now, we need your full sample (runnable) code (project) to investigate this issue further.

Here is the sample code we used to test this issue. You can modify this code or provide your own code. Please provide the simplest code as possible.

Java

import com.aspose.cells.*;
import com.aspose.gridweb.GridWebBean;

public class ClsAsposeCells {
	
	public class MyThread implements Runnable
	{
		private String srcFile;
		private String dstFile;
		public MyThread(String srcFile, String dstFile)
		{
			this.srcFile = srcFile;
			this.dstFile = dstFile;
		}
		
		@Override
		public void run()
		{
			try
			{
				Workbook wb = new Workbook(srcFile);
				PdfSaveOptions pdfSaveOpt = new PdfSaveOptions();
//				pdfSaveOpt.setCompliance(PdfCompliance.PDF_A_1_A);
				wb.save(dstFile, pdfSaveOpt);
			}
			catch (Exception e) 
			{
				e.printStackTrace(System.err);
			}
			
		}

	}

	public static void main(String[] args) throws Exception {
		
		SetLicense();
		f1();
		
		System.out.println("Done");
	}
	
	public static void SetLicense() {
		
		String licPath = "F:/Download/Misc/Aspose/Licenses/Aspose.Total.Java.lic";
		
		com.aspose.cells.License lic = new com.aspose.cells.License();
		lic.setLicense(licPath);
				
		System.out.println("Aspose.Cells for Java v"+ CellsHelper.getVersion());
	}
	
	public static void f1() throws Exception{

		ClsAsposeCells o = new ClsAsposeCells();
		o.R();
		
	}
	
	void R() throws Exception
	{
		MyThread myThread1 = new MyThread("F:\\Download\\test1.xls", "F:\\Download\\Temp\\test1.pdf");
		MyThread myThread2 = new MyThread("F:\\Download\\Test1_toLandscape.xls", "F:\\Download\\Temp\\Test1_toLandscape.pdf");

		Thread thread1 = new Thread(myThread1);
		Thread thread2 = new Thread(myThread2);
		thread1.run();
		thread2.run();
		thread1.join();
		thread2.join();
	}

}

I did some modifications to your code and I was able reproduce the problem.

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

import com.aspose.cells.CellsHelper;
import com.aspose.cells.PdfCompliance;
import com.aspose.cells.PdfSaveOptions;
import com.aspose.cells.SaveFormat;
import com.aspose.cells.Workbook;

public class ClsAsposeCells {

public class MyTask implements Runnable
{
    private String srcFile;
    private String dstFile;

    public MyTask(String srcFile, String dstFile)
    {
        this.srcFile = srcFile;
        this.dstFile = dstFile;
    }

    @Override
    public void run()
    {
        try
        {
            Workbook wb = new Workbook(srcFile);
            PdfSaveOptions pdfSaveOpt = new PdfSaveOptions(SaveFormat.PDF);
            pdfSaveOpt.setCompliance(PdfCompliance.PDF_A_1_B);
            wb.save(dstFile, pdfSaveOpt);
        } catch (Exception e)
        {
            e.printStackTrace(System.err);
        }

    }
}

public static void main(String[] args) throws Exception {

    SetLicense();
    f1();

    System.out.println("Done");
}

public static void SetLicense() {

    String licPath = "F:/Download/Misc/Aspose/Licenses/Aspose.Total.Java.lic";

    com.aspose.cells.License lic = new com.aspose.cells.License();
    lic.setLicense(licPath);

    System.out.println("Aspose.Cells for Java v" + CellsHelper.getVersion());
}

public static void f1() throws Exception {

    ClsAsposeCells o = new ClsAsposeCells();
    o.R();

}

void R() throws Exception
{
    ExecutorService executorService = Executors.newFixedThreadPool(20);
    MyTask task1 = new MyTask("F:\\Download\\Test1.xls", "F:\\Download\\Temp\\Test1.pdf");
    MyTask task2 = new MyTask("F:\\Download\\Test1_toLandscape.xls", "F:\\Download\\Temp\\Test1_toLandscape.pdf");
    executorService.execute(task1);
    executorService.execute(task2);
    executorService.shutdown();
}

}

@cpatricio76

Thanks for your feedback and using Aspose APIs.

Please spare us some time, we will look into this issue further and update you asap.

@cpatricio76,

We managed to reproduce the issue as per your details. I have logged the following ticket into our database for product team’s investigation:
CELLSJAVA-42330 - Weird result when converting from Excel to PDF or PDF/A using threads.

Once we figure it out and have some other updates, we will let you know here.

Thank you.

@cpatricio76,

This is to inform you that we have fixed your issue now. We will soon provide you the fixed version after performing QA and incorporating other enhancements and fixes.

Once the fix is available for public use, we will share the Download link here.

Thank you.

Wow…waiting for the fix. Thanks

@cpatricio76

Thanks for using Aspose APIs.

Please download and try the following fix and it should fix your issue. Let us know your feedback.

@shakeel.faiz

Indeed v17.6.3 fixed the issue. Thank you.

@cpatricio76

Thanks for your feedback and using Aspose APIs

It is good to know that your issue is resolved with the latest fix. Let us know if you encounter any other issue, we will be glad to look into it and help you further.

The issues you have found earlier (filed as CELLSJAVA-42330) have been fixed in this update. This message was posted using BugNotificationTool from Downloads module by Amjad_Sahi

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