Copy paste text not working in PDF create by Aspose.html 22.2

Copy-paste text not working in PDF file created by Aspose.html version 22.2 using function
Aspose.Html.Converters.Converter.ConvertHTML(document, pdfSaveOptions, streamProvider);

The text is shown correctly in the PDF file, but in paste is shown like this :􀀂􀀃􀀂􀀄􀀃􀀂􀀄􀀃􀀂􀀄􀀃􀀄􀀂􀀃􀀃

My code:

using System;
using System.Configuration;
using System.IO;
using System.Linq;

using Aspose.Html;

{
public class PdfAsposeService : IPdfAsposeService
{

    public byte[] GenerateReceipt(string html, Receipt receipt, int pdfPageWidth, int pdfPageHeight)
    {
        return ConvertHtmlToPdfUsingAspose(html, receipt.LeftMargin, receipt.RightMargin, receipt.TopMargin, receipt.BottomMargin, pdfPageWidth, pdfPageHeight);
    }

    private static byte[] ConvertHtmlToPdfUsingAspose(string html, int leftMargin, int rightMargin, int topMargin, int bottomMargin, int pdfPageWidth, int pdfPageHeight)
    {
        try
        {
            if (pdfPageWidth == 0)
            {
                pdfPageWidth = 297;
            }
            if (pdfPageHeight == 0)
            {
                pdfPageHeight = 210;
            }
            var asposeLicense = ConfigurationManager.AppSettings["AsposeLicense"];
            if (string.IsNullOrEmpty(asposeLicense) || !File.Exists(asposeLicense))
            {
                throw new Exception($"AsposeLicense not found");
            }

            License htmlLicense = new Aspose.Html.License();
            htmlLicense.SetLicense(asposeLicense);
            using (var streamProvider = new MemoryStreamProvider())
            {
                using (var document = new HTMLDocument(html, "."))
                {
                    var pdfSaveOptions = new Aspose.Html.Saving.PdfSaveOptions();
                    pdfSaveOptions.PageSetup.AnyPage = new Aspose.Html.Drawing.Page(new Aspose.Html.Drawing.Size(Aspose.Html.Drawing.Unit.FromMillimeters(pdfPageWidth), Aspose.Html.Drawing.Unit.FromMillimeters(pdfPageHeight)),
                        new Aspose.Html.Drawing.Margin(leftMargin, rightMargin, topMargin, bottomMargin));
                    Aspose.Html.Converters.Converter.ConvertHTML(document, pdfSaveOptions, streamProvider);
                    var memory = streamProvider.Streams.First();
                    memory.Seek(0, System.IO.SeekOrigin.Begin);
                    return memory.ToArray();
                }
            }
        }
        catch (Exception ex)
        {
            Logger.Log(EntryType.Error, ex);
            throw;
        }
    }
}

class MemoryStreamProvider : Aspose.Html.IO.ICreateStreamProvider
{
    // List of MemoryStream objects created during the document rendering
    public System.Collections.Generic.List<MemoryStream> Streams { get; } = new System.Collections.Generic.List<MemoryStream>();
    public Stream GetStream(string name, string extension)
    {
        // This method is called when only one output stream is required, for instance for XPS, PDF or TIFF formats.
        MemoryStream result = new MemoryStream();
        Streams.Add(result);
        return result;
    }
    public Stream GetStream(string name, string extension, int page)
    {
        // This method is called when the creation of multiple output streams are required. For instance, during the rendering HTML to list of image files (JPG, PNG, etc.)
        MemoryStream result = new MemoryStream();
        Streams.Add(result);
        return result;
    }
    public void ReleaseStream(Stream stream)
    {
        //  Here you can release the stream filled with data and, for instance, flush it to the hard-drive
    }
    public void Dispose()
    {
        // Releasing resources
        foreach (var stream in Streams)
            stream.Dispose();
    }
}

}

@rezgar.rashid

Can you please share the sample HTML in .zip format with us? We will test the scenario in our environment and address it accordingly.

Hi Asad

Thanks

The HTML is: “’<p><font face=‘Arial’>ouoiuoiuoiuiouu</font></p>”
And called from this function

public void ConvertToPDF_test()
{
Receipt receipt = new Receipt();

        byte[] buffer = _signingService.GenerateReceipt("<p><font face='Arial'>ouoiuoiuoiuiouu</font></p>", receipt, 297, 210);

        string filepath = @"c:\temp\mygeneratedPDF.pdf";
        if (File.Exists(filepath))
        {
            File.Delete(filepath);
        }

        Encoding encoding = Encoding.GetEncoding("ISO-8859-1"); //Or any other Encoding


        using (FileStream fs = new FileStream(filepath, FileMode.CreateNew))
        {
            using (StreamWriter writer = new StreamWriter(fs, encoding))
            {
                fs.Write(buffer, 0, buffer.Length);
            }
        }

        //FileStream fs = new FileStream(filepath, FileMode.Create);
       
        //fs.Close();
       
    }

Hi Asad

Thanks

The HTML is: “<p><font face=‘Arial’>ouoiuoiuoiuiouu</font></p>”

And called from this function

public void ConvertToPDF_test()

{

Receipt receipt = new Receipt();

byte[] buffer = _signingService.GenerateReceipt("<p><font face='Arial'>ouoiuoiuoiuiouu</font></p>", receipt, 297, 210);

string filepath = @"c:\temp\mygeneratedPDF.pdf";

if (File.Exists(filepath))

{

File.Delete(filepath);

}

Encoding encoding = Encoding.GetEncoding("ISO-8859-1"); //Or any other Encoding

using (FileStream fs = new FileStream(filepath, FileMode.CreateNew))

{

using (StreamWriter writer = new StreamWriter(fs, encoding))

{

fs.Write(buffer, 0, buffer.Length);

}

}

//FileStream fs = new FileStream(filepath, FileMode.Create);

//fs.Close();

}

image002.png (4.32 KB)

@rezgar.rashid

We could not find any Aspose.HTML related code in your responses. Can you please share the actual code that you are using to generate PDF from HTML with Aspose.HTML for .NET?

Hi Asad
Codes that calling Aspose.HTML:

using System;
using System.Configuration;
using System.IO;
using System.Linq;
using Traen.TAS.Domain.TAS;
using Traen.TAS.Service.TAS.Interfaces;
using Aspose.Html;
using Traen.TAS.Common.Logging;
namespace Traen.TAS.Service.TAS
{
public class PdfAsposeService : IPdfAsposeService
{

    public byte[] GenerateReceipt(string html, Receipt receipt, int pdfPageWidth, int pdfPageHeight)
    {
        return ConvertHtmlToPdfUsingAspose(html, receipt.LeftMargin, receipt.RightMargin, receipt.TopMargin, receipt.BottomMargin, pdfPageWidth, pdfPageHeight);
    }

    private static byte[] ConvertHtmlToPdfUsingAspose(string html, int leftMargin, int rightMargin, int topMargin, int bottomMargin, int pdfPageWidth, int pdfPageHeight)
    {
        try
        {
            if (pdfPageWidth == 0)
            {
                pdfPageWidth = 297;
            }
            if (pdfPageHeight == 0)
            {
                pdfPageHeight = 210;
            }
            var asposeLicense = ConfigurationManager.AppSettings["AsposeLicense"];
            if (string.IsNullOrEmpty(asposeLicense) || !File.Exists(asposeLicense))
            {
                throw new Exception($"AsposeLicense not found");
            }

            License htmlLicense = new Aspose.Html.License();
            htmlLicense.SetLicense(asposeLicense);
            using (var streamProvider = new MemoryStreamProvider())
            {
                using (var document = new HTMLDocument(html, "."))
                {
                    var pdfSaveOptions = new Aspose.Html.Saving.PdfSaveOptions();
                    pdfSaveOptions.PageSetup.AnyPage = new Aspose.Html.Drawing.Page(new Aspose.Html.Drawing.Size(Aspose.Html.Drawing.Unit.FromMillimeters(pdfPageWidth), Aspose.Html.Drawing.Unit.FromMillimeters(pdfPageHeight)),
                        new Aspose.Html.Drawing.Margin(leftMargin, rightMargin, topMargin, bottomMargin));
                    Aspose.Html.Converters.Converter.ConvertHTML(document, pdfSaveOptions, streamProvider);
                    var memory = streamProvider.Streams.First();
                    memory.Seek(0, System.IO.SeekOrigin.Begin);
                    return memory.ToArray();
                }
            }
        }
        catch (Exception ex)
        {
            Logger.Log(EntryType.Error, ex);
            throw;
        }
    }
}

class MemoryStreamProvider : Aspose.Html.IO.ICreateStreamProvider
{
    // List of MemoryStream objects created during the document rendering
    public System.Collections.Generic.List<MemoryStream> Streams { get; } = new System.Collections.Generic.List<MemoryStream>();
    public Stream GetStream(string name, string extension)
    {
        // This method is called when only one output stream is required, for instance for XPS, PDF or TIFF formats.
        MemoryStream result = new MemoryStream();
        Streams.Add(result);
        return result;
    }
    public Stream GetStream(string name, string extension, int page)
    {
        // This method is called when the creation of multiple output streams are required. For instance, during the rendering HTML to list of image files (JPG, PNG, etc.)
        MemoryStream result = new MemoryStream();
        Streams.Add(result);
        return result;
    }
    public void ReleaseStream(Stream stream)
    {
        //  Here you can release the stream filled with data and, for instance, flush it to the hard-drive
    }
    public void Dispose()
    {
        // Releasing resources
        foreach (var stream in Streams)
            stream.Dispose();
    }
}

}

@rezgar.rashid

We are checking it and will get back to you shortly.

We are also facing this issue. Any help would be appreciated.

@Sayee

Would you kindly share your sample files and the sample code snippet as well so that we can test the scenario in our environment and address it accordingly.

AsposeIssueDemo.zip (3.3 MB)
Please find the sample demo having the issue. Please check the pdf file in bin directory for the issue.
You copy paste the text in the pdf - to a notepad you get like 􀀂􀀃􀀄􀀂

@rezgar.rashid
@Sayee

We have reproduced the similar issue in our environment as well while using 22.6 version of the API. Therefore, it has been logged as HTMLNET-3914 in our issue tracking system. We will further investigate it in details and let you know once it is resolved. Please be patient and spare us some time.

We are sorry for the inconvenience.

Hi, Can you pls let me know which release it would get fixed? We are stuck and could not use latest ASPOSE releases due to this issue.

@Sayee

This ticket has been resolved in 22.9 version of the API which will be released soon and a notification will also be sent in this forum thread.

The issues you have found earlier (filed as HTMLNET-3914) have been fixed in this update. This message was posted using Bugs notification tool by avpavlysh

I’ve the same issue in an installed Aspose.Total 22.9. I’ve also seen that Aspose.Total 22.9 installs an Aspose.HTML in version 22.8:

image.png (7.0 KB)

@HauptlorenzAG

We will surely update Aspose.Total for .NET package accordingly so that it includes latest versions of all the APIs. Meanwhile, can you please separately check with 22.9 version of Aspose.HTML for .NET if same issue is still there? If so, please share your sample files with us so that we can further proceed to address it accordingly.

I’ve installed Aspose.HTML separately and removed the Aspose.Total package from my example project and the issue is gone.
I assume that your nuget package of Aspose.Total does deliver the wrong Aspose.HTML version.

Thanks for the fast reply!

@HauptlorenzAG

Thanks for your feedback. We are process to update the Aspose.Total Package and will soon update you once it is done. Please spare us some time.

Take your time, for me this is fixed :wink:

@HauptlorenzAG

The Aspose.Total for .NET Package has also been updated.

1 Like