【发布时间】:2015-06-04 22:38:53
【问题描述】:
我已经搜索了几个小时试图找出如何做到这一点,但没有任何成功。
我确实找到了将“system.drawing.graphics”对象读入 XGraphics 类型的“FromGraphics”命令,但不确定如何将其添加到 PDF 输出中。
我发现的大多数示例都展示了如何从现有文件中获取图像并将其保存为 PDF,但是如何使用已实用的预制 system.drawing.graphics 对象来执行此操作?
非常感谢 C# 和/或 VB.net 示例而不是 GIF。
例如如何更改如下示例以使用 system.drawing.graphics 对象?
string pdfpath = Server.MapPath("PDFs");
string imagepath = Server.MapPath("Images");
Document doc = new Document();
try
{
PdfWriter.GetInstance(doc, new FileStream(pdfpath + "/Images.pdf", FileMode.Create));
doc.Open();
doc.Add(new Paragraph("GIF"));
Image gif = Image.GetInstance(imagepath + "/mikesdotnetting.gif");
doc.Add(gif);
}
catch (Exception ex)
{
//Log error;
}
finally
{
doc.Close();
}
【问题讨论】:
-
你得到了很好的答案。只是为了确保您做对了:Graphics 对象不包含任何图形。它只是在 a) 表面 b) 位图 c) 打印页面上绘制像素的工具。或者 d) 转换成 PDF,如果您使用 pdf 库中的特殊 Graphics 对象..
标签: c# vb.net pdf pdfsharp system.drawing.graphics