【发布时间】:2019-10-10 10:49:36
【问题描述】:
我有一个按钮,用于从我的静态目录 (C:\myfolder) 中的所有图像创建 pdf。 但我有错误
对于下面一行中的字符串“files”,“can not convert from string[] to string”:
DrawImage(gfx, files, 0, 0, (int)page.Width, (int)page.Height);
我该如何解决这个错误? 谢谢。 这是我的代码:
string[] files = Directory.GetFiles(@"C:\myfolder");
PdfDocument document = new PdfDocument();
document.Info.Title = "Created in Pdf";
foreach (string img in files)
{
PdfPage page = document.AddPage();
XGraphics gfx = XGraphics.FromPdfPage(page);
DrawImage(gfx, files, 0, 0, (int)page.Width, (int)page.Height);
}
if(document.PageCount > 0)
{
document.Save(@"C:\test.pdf");
}
void DrawImage(XGraphics gfx, string jpegSamplePath, int x, int y, int width, int height)
{
XImage image = XImage.FromFile(jpegSamplePath);
gfx.DrawImage(image, x, y, width, height);
}
【问题讨论】:
标签: c# arrays string c#-4.0 pdfsharp