Hi everyone, I’m new to GroupDocs and interested in trying it out for my use case (converting HTML div to PDF). Can anyone here give me a hint or some guidance? I’m looking to perform this conversion in a background process and retrieve a byte array in Core 6 MVC.
Production Deployment Target: Linux Debian-12
@Calistasoft_Calistasoft
To convert an HTML <div>
to a PDF using GroupDocs in a .NET Core 6 MVC application, you can utilize the GroupDocs.Conversion library. Below is a straightforward example demonstrating how to perform this conversion and retrieve the result as a byte array:
using GroupDocs.Conversion;
using GroupDocs.Conversion.Options.Convert;
using System.IO;
// Sample HTML content
string htmlContent = "<div><h1>Hello World</h1><p>This is a sample div content.</p></div>";
// Convert HTML to PDF
using (var converter = new Converter(htmlContent))
{
var options = new PdfConvertOptions();
using (var pdfStream = new MemoryStream())
{
converter.Convert(pdfStream, options);
byte[] pdfBytes = pdfStream.ToArray();
// Now you can use pdfBytes as needed
}
}
In this example, replace htmlContent
with your actual HTML content. The Converter
class is used to handle the conversion, and the result is stored in a MemoryStream
, which you can then convert to a byte array.
Ensure that you have included the necessary GroupDocs.Conversion NuGet package in your project to access these classes and methods.
If you have any further questions, feel free to ask!
thank you for your speedy reply
can we do that online?
unfortunately there is no testing page for this, cmiiw
I’m trying to do the following in GroupDocs
internal static async Task<byte[]> QSHtml2BytesAsync(string url, string divFirstPage, string divSecondPage, string divThirdPage)
{
byte[] ret = null;
try
{
using (var converter = new Converter(url))
{
var options = new PdfConvertOptions();
using (var pdfStream = new MemoryStream())
{
converter.Convert(pdfStream, options);
byte[] pdfBytes = pdfStream.ToArray();
}
}
}
how to accomplish this
Hello @Calistasoft_Calistasoft ,
Thank you for your interest in our product. Please refer to this documentation to correctly perform conversion using a URL. We also have GitHub demo examples that you can review and use to try different types of conversions. If you still have any questions, we’ll be happy to help.