Экспорт html в PDF

Для экспорта понадобятся несколько библиотек из NuGet:

  • itext7
  • itext7.commons
  • itext7.pdfhtml

В Package после сборки добавляем следующие библиотеки с зависимостями:

MemoryStream pdfDest = new ByteArrayOutputStream();
ConverterProperties converterProperties = new ConverterProperties();
HtmlConverter.ConvertToPdf(_html.Text, pdfDest, converterProperties);

Page.Response.Clear();
Page.Response.ContentType = "applacation/pdf";
Page.Response.AddHeader("content-disposition", "attachment;filename=file1.pdf");
Page.Response.Cache.SetCacheability(HttpCacheability.NoCache);
Page.Response.BinaryWrite(pdfDest.ToArray());
Page.Response.End();

Ответить

Ваш адрес email не будет опубликован. Обязательные поля помечены *