Spire.PDF is a professional PDF library applied to creating, writing, editing, handling and reading PDF files without any external dependencies. Get free and professional technical support for Spire.PDF for .NET, Java, Android, C++, Python.

Mon Jun 19, 2017 11:18 am

we have been using Free spire pdf for printing pdf in multi threading application, but we are facing the issue attached here, due to this application is crashing, please check and provide me the solution.

snandeesha
 
Posts: 6
Joined: Mon Jun 19, 2017 11:14 am

Tue Jun 20, 2017 3:56 am

Hi S Nandeesha,
I tested your scenario and didn’t reproduce the issue you encountered. Thus, please provide us with your original html file and complete application for investigating. Thanks in advance.

Sincerely,
Nina
E-iceblue support team
User avatar

Nina.Tang
 
Posts: 1182
Joined: Tue Sep 27, 2016 1:06 am

Tue Jun 20, 2017 5:35 am

Hi,
If we use single thread to generate pdf, no issue, but if we use multi thread( more than 3threads) to generate pdf, we are facing the issue . Kindly provide me some solution.

Regards,
Nandeesh

snandeesha
 
Posts: 6
Joined: Mon Jun 19, 2017 11:14 am

Tue Jun 20, 2017 7:59 am

Hello,

Thanks for your prompt reply.
I tested your html file in multi-threaded application and still not found the issue. I enclosed my testing code for your reference. To help us reproduce your issue on our side, please provide us with your complete testing application.
Code: Select all
static void Main(string[] args)
        {
            List<Thread> threads = new List<Thread>();
            for (int i = 0; i < 15; i++)
            {
                string result = String.Format("Result{0}.pdf",i);
                Thread thread = new Thread(() =>
                    {
                        HtmlToPDF(result);
                    });               
                threads.Add(thread);
            }
            threads.ForEach(t => t.Start());
            threads.ForEach(t => t.Join());
        }
       static void HtmlToPDF(string result)
        {
            PdfDocument doc = new PdfDocument();
            String html = File.ReadAllText("testEmailPdf.html");
            PdfHtmlLayoutFormat format = new PdfHtmlLayoutFormat { IsWaiting = true };
            PdfPageSettings setting = new PdfPageSettings { Size = PdfPageSize.A4 };
            doc.Security.KeySize = Spire.Pdf.Security.PdfEncryptionKeySize.Key128Bit;
            doc.Security.OwnerPassword = "$123456$";
            doc.Security.UserPassword = "test";
            doc.Security.Permissions = Spire.Pdf.Security.PdfPermissionsFlags.Print | Spire.Pdf.Security.PdfPermissionsFlags.FillFields;
            Thread thread = new Thread(() =>
            { doc.LoadFromHTML(html, false, setting, format); });
           thread.SetApartmentState(ApartmentState.STA);
            thread.Start();
            thread.Join();           
            doc.SaveToFile(result);
        }

Sincerely,
Nina
E-iceblue support team
User avatar

Nina.Tang
 
Posts: 1182
Joined: Tue Sep 27, 2016 1:06 am

Wed Jun 21, 2017 9:33 am

Hello,

We have received your application via email. The issue has been reproduced and posted to our DEV team. If there is any progress, we will let you know.

Sincerely,
Simon
E-iceblue support team
User avatar

Simon.yang
 
Posts: 620
Joined: Wed Jan 11, 2017 2:03 am

Tue Jun 27, 2017 7:17 am

Do you have any update for the below issue?
And I have one more issue that the PDF file size is too much(156kb), hence how to reduce the file size.

snandeesha
 
Posts: 6
Joined: Mon Jun 19, 2017 11:14 am

Tue Jun 27, 2017 9:56 am

Hello,

Regarding the multi-threaded issue, I got an information from our dev team that the method(HtmlToPdf) is not well supported in multi-threaded using our Spire.pdf, and I am sorry that currently we have no method to resolve the mutil-threaded issue.
For the second issue, I am afraid that there is no direct way to reduce pdf file size at present, and if your pdf file contains images, you could try to compress image to reduce pdf size. Here is sample code of compressing pdf image for your reference.
Code: Select all
PdfDocument pdf = new PdfDocument();
pdf.LoadFromFile("Sample.pdf");

foreach (PdfPageBase page in pdf.Pages)
{
    Image[] images = page.ExtractImages();
    if (images != null && images.Length > 0)
    {
        for (int j = 0; j<images.Length; j++)
        {
            Image image = images[j];
            PdfBitmap bp = new PdfBitmap(image);
            bp.Quality = 20;
            page.ReplaceImage(j, bp);
        }
    }               
}
pdf.SaveToFile("Result.pdf");

Sincerely,
Nina
E-iceblue support team
User avatar

Nina.Tang
 
Posts: 1182
Joined: Tue Sep 27, 2016 1:06 am

Mon Jan 08, 2018 8:05 am

Have you solved the above issue, which I have mentioned earlier.

snandeesha
 
Posts: 6
Joined: Mon Jun 19, 2017 11:14 am

Mon Jan 08, 2018 9:31 am

Dear Nandeesh,

Due to complexity of the reported issue, the problem is not yet resolved. We will keep you informed once there is any good news. Sorry for this delay and thanks for your understanding.

Sincerely,
Nina
E-iceblue support team
User avatar

Nina.Tang
 
Posts: 1182
Joined: Tue Sep 27, 2016 1:06 am

Return to Spire.PDF