DocX
DocX copied to clipboard
DocX.ConvertToPdf() does not convert inserted html content.
When converting from word document to pdf the content that were inserted with the line of code below, were not converted to pdf.
Below is the method that convert word to pdf:
public (byte[], string) GetPDF(int reportID, bool email) { (byte[] docContent, string fileName) = CreateWORD(reportID, true);
using (var documentStream = new MemoryStream(docContent))
{
try
{
// Load the DocX document from the memory stream
using (var document = DocX.Load(documentStream))
{
// Create a separate memory stream to store the PDF content
using (MemoryStream pdfStream = new MemoryStream())
{
// Convert the Document to PDF and save it to the pdfStream
documentStream.Seek(0, SeekOrigin.Begin); // Reset the stream position
try
{
DocX.ConvertToPdf(document, pdfStream);
}
catch (Exception ex)
{
return (new byte[0], fileName);
}
if (email)
{
// Return the PDF content as a byte array
pdfStream.Seek(0, SeekOrigin.Begin); // Reset the stream position
return (pdfStream.ToArray(), fileName);
}
else
{
// Provide the PDF document as a downloadable file
HttpContext.Current.Response.Clear();
HttpContext.Current.Response.ContentType = "application/pdf";
HttpContext.Current.Response.AddHeader("Content-Disposition", "attachment; filename=" + fileName + ".pdf");
HttpContext.Current.Response.BinaryWrite(pdfStream.ToArray());
HttpContext.Current.Response.End();
return (pdfStream.ToArray(), fileName);
}
}
}
}
catch (Exception ex)
{
return (new byte[0], fileName);
}
}
}
Hi,
So if I understand correctly, you are : -loading a docx -calling document.InsertContent(HtmlParse(partnerReports.achievements), Xceed.Document.NET.ContentType.Html, targetParagraph) on that docx -calling DocX.ConvertToPdf() for that docx and the result is the html part is not in PDF.
If yes, then this is a known issue. But please note that in the latest release of "Xceed Words for .NET", v3.0, this is all fixed. You can try it here : https://www.xceed.com/en/our-products/product/words-for-net.
Thank you
Hello Xceedsoftware/Docx
Thanks for the fast response. I did the purchase recently and last week I was sent the upgraded version activation key and I am using it but still facing the same problem.
On Mon, 30 Oct 2023, 17:48 XceedBoucherS, @.***> wrote:
Hi,
So if I understand correctly, you are : -loading a docx -calling document.InsertContent(HtmlParse(partnerReports.achievements), Xceed.Document.NET.ContentType.Html, targetParagraph) on that docx -calling DocX.ConvertToPdf() for that docx and the result is the html part is not in PDF.
If yes, then this is a known issue. But please note that in the latest release of "Xceed Words for .NET", v3.0, this is all fixed. You can try it here : https://www.xceed.com/en/our-products/product/words-for-net.
Thank you
— Reply to this email directly, view it on GitHub https://github.com/xceedsoftware/DocX/issues/464#issuecomment-1785380449, or unsubscribe https://github.com/notifications/unsubscribe-auth/AMXSG6LCDWO72Y2KU75ZGO3YB642RAVCNFSM6AAAAAA6VVOEWWVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTOOBVGM4DANBUHE . You are receiving this because you authored the thread.Message ID: @.***>
Hi @KevinStreetCoder , If you bought the product, I invite you to contact the Xceed support at [email protected]. Explain the problem, give them code so they can test the issue and you should receive clear instructions. Thank you
Hi @XceedBoucherS It worked fine with only if the html contains string/text only but I get the Error: "The remote server returned an error: (400) Bad Request. ", even with word document, if the html contains images and Tables, if I use the previous version v2.5 on same code the word is generated perfectly with Images.
Hi @KevinStreetCoder , As suggested by @XceedBoucherS, could you please send us your HTML script that raises the issue at Xceed support [email protected]. We suspect that the issue may occur when retrieving or loading the images from the HTML script. But we need to test the exact scenario and investigate further Thank you