ADI@345 Ответов: 1

Как отобразить изображение в формате pdf в столбце таблицы с помощью itextsharp


На самом деле я могу вставить изображение в pdf, но не могу вставить изображение в столбец таблицы в pdf..

Что я уже пробовал:

string imageURL = Server.MapPath(".") + "/logo.png";
       iTextSharp.text.Image png = iTextSharp.text.Image.GetInstance(imageURL);

      using (StringWriter sw = new StringWriter())
      {
          using (HtmlTextWriter hw = new HtmlTextWriter(sw))
          {
              StringBuilder sb = new StringBuilder();

              sb.Append("<table  border = '0.5' cellspacing='0' cellpadding='2' width='100%'>");
              sb.Append("<tr>");

              //Resize image depend upon your need

              png.ScaleToFit(140f, 120f);

              //Give space before image

              png.SpacingBefore = 10f;

              //Give some space after the image

              png.SpacingAfter = 1f;

              png.Alignment = Element.ALIGN_LEFT;

              sb.Append("<td style='float:left;'> " + png. + " </td>");

              sb.Append("<td style='float:right;'>");
              sb.Append("web link services pvt ltd");
              sb.Append("</td>");
              sb.Append("</tr>");



              sb.Append(" </table>");

              //Export HTML String as PDF.
              StringReader sr = new StringReader(sb.ToString());
              Document pdfDoc = new Document(PageSize.A4, 10f, 10f, 10f, 0f);
              HTMLWorker htmlparser = new HTMLWorker(pdfDoc);
              PdfWriter writer = PdfWriter.GetInstance(pdfDoc, Response.OutputStream);
              pdfDoc.Open();
              htmlparser.Parse(sr);


              pdfDoc.Close();
              Response.ContentType = "application/pdf";
              Response.AddHeader("content-disposition", "attachment;filename=Invoice.pdf");
              Response.Cache.SetCacheability(HttpCacheability.NoCache);
              Response.Write(pdfDoc);
              Response.End();
          }
      }
  }

1 Ответов

Рейтинг:
1

debasish mishra

Попробуйте это и дайте мне знать.

Как вставить изображение в ячейку сетки PDF в C#[^]