c# – 将图像导出为PDF
作者:互联网
我有一个项目必须将图像导出为PDF.图像和文本都需要导出为pdf.有没有办法通过使用silverPDF.dll和PdfReader来做到这一点?
代码在这里.
private void btnOutlook_Click(object sender, System.Windows.RoutedEventArgs e)
{
XBrush xbrush;
SaveFileDialog savePDF = new SaveFileDialog();
savePDF.Filter = "PDF file format | *.pdf";
if (savePDF.ShowDialog() == true)
{
PdfDocument document = new PdfDocument();
PdfPage page = document.AddPage();
XGraphics gfx = XGraphics.FromPdfPage(page);
XPdfFontOptions options = new XPdfFontOptions(PdfFontEncoding.Unicode, PdfFontEmbedding.Always);
XFont font = new XFont("Huxtable", 20, XFontStyle.Bold, options);
for (int x = 0; x < 10; x++)
{
if (x % 2 == 0)
{
xbrush = XBrushes.Red;
}
else
xbrush = XBrushes.Black;
gfx.DrawString(string.Format("{0}", stringArray[x]), font, xbrush, new XRect(0, (x * 20), page.Width, page.Height), XStringFormats.TopLeft);
}
document.Save(savePDF.OpenFile());
}
}
我可以在此代码中插入将其插入pdf的图像吗?有什么办法吗?感谢所有回复.
解决方法:
它需要是SilverPDF吗?我之前使用iTextSharp库在我以前的雇主做过类似的事情(否则我会粘贴示例代码)
iTextSharp-Working-with-images
标签:c,pdf,silverlight-5-0 来源: https://codeday.me/bug/20190709/1416948.html