Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DocX.ConvertToPdf() does not convert inserted html content. #464

Open
KevinStreetCoder opened this issue Oct 30, 2023 · 5 comments
Open

Comments

@KevinStreetCoder
Copy link

KevinStreetCoder commented Oct 30, 2023

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

}

@KevinStreetCoder KevinStreetCoder changed the title DocX.ConvertToPdf() does not converst inserted html content. DocX.ConvertToPdf() does not convert inserted html content. Oct 30, 2023
@XceedBoucherS
Copy link
Collaborator

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

@KevinStreetCoder
Copy link
Author

KevinStreetCoder commented Oct 30, 2023 via email

@XceedBoucherS
Copy link
Collaborator

Hi @KevinStreetCoder ,
If you bought the product, I invite you to contact the Xceed support at support@xceed.com.
Explain the problem, give them code so they can test the issue and you should receive clear instructions.
Thank you

@KevinStreetCoder
Copy link
Author

KevinStreetCoder commented Nov 1, 2023

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.

@evancekafando
Copy link

Hi @KevinStreetCoder ,
As suggested by @XceedBoucherS, could you please send us your HTML script that raises the issue at Xceed support support@xceed.com.
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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants