iTextSharp PDF coming in white

1

Good afternoon guys, I have the following code:

 public void GerarPDF(long id)
    {
        string HTMLemString = RenderizaHtmlComoString("~/Views/item/item.cshtml", id);
        var regex = new Regex("(\<script(.+?)\</script\>)|(\<style(.+?)\</style\>)",
            RegexOptions.Singleline | RegexOptions.IgnoreCase);
        HTMLemString = regex.Replace(HTMLemString, "");
        string CSSdocumento = CSSemString();
        Byte[] bytes;

        using (var ms = new MemoryStream())
        {
            using (var doc = new Document())
            {
                using (var writer = PdfWriter.GetInstance(doc, ms))
                {
                    doc.Open();
                    var HTMLconversão = '@' + HTMLemString;
                    var CSSconversão = '@' + CSSdocumento;

                    using (var msCss = new MemoryStream(System.Text.ASCIIEncoding.UTF8.GetBytes(CSSconversão)))
                    {
                        using (var msHtml = new MemoryStream(System.Text.ASCIIEncoding.UTF8.GetBytes(HTMLconversão)))
                        {
                            iTextSharp.tool.xml.XMLWorkerHelper.GetInstance().ParseXHtml(writer, doc, msHtml, msCss);
                        }
                    }

                    doc.Close();
                }
            }

            bytes = ms.ToArray();
        }

        new XmlController().SalvarPDF(bytes);

    }

The code that generates the PDF, and below where I get the PDF and use it:

 byte[] PDF = PDFparaAnexo;
 List<MemoryStream> anexos = new List<MemoryStream>();
        anexos.Add(new MemoryStream(PDF));

And below where together the file that is in a memorystream, with its name:

int i = 0;
            foreach (Stream anx in pAnex)
            {
                try
                {
                    Attachment attached = new Attachment(anx, pFileName[i]);
                    mm.Attachments.Add(attached);
                    i++;
                }
                catch (Exception ex)
                {

                }

            }

Only the file is going to be in PDF format, but this is blank, would anyone know why?

    
asked by anonymous 14.03.2017 / 20:51

0 answers