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();
}
}
}