我没有。tiff 文件/图像,现在我想转换为单个 PDF...
我为此编写了代码,它工作正常。但问题是,我将图像存储在临时文件夹中。并想在 PDF 生成后删除这些文件。它给了我错误。 “文件被另一个进程使用”
我的代码是:
string RootDirPath = ConfigurationManager.AppSettings["RootDirPath"].ToString();
string PDFDirPath = ConfigurationManager.AppSettings["PDFDirPath"].ToString();
string TmpFolderpath = System.DateTime.Now.ToString("d").Replace('/', '_');
// creation of the document with a certain size and certain margins
iTextSharp.text.Document document = new iTextSharp.text.Document(iTextSharp.text.PageSize.A4, 0, 0, 0, 0);
// creation of the different writers
iTextSharp.text.pdf.PdfWriter writer = iTextSharp.text.pdf.PdfWriter.GetInstance(document, new System.IO.FileStream((PDFDirPath + PDFName + ".pdf"), System.IO.FileMode.Create));
// load the tiff image and count the total images
DirectoryInfo RootDir = new DirectoryInfo(RootDirPath + TmpFolderpath);
FileInfo[] files = RootDir.GetFiles();
System.Drawing.Bitmap bm = null;
document.Open();
for (int i = 0; i < files.Count(); i++)
{
bm = new System.Drawing.Bitmap(RootDirPath + TmpFolderpath + "/" + files[i].Name);
iTextSharp.text.pdf.PdfContentByte cb = writer.DirectContent;
iTextSharp.text.Image img = iTextSharp.text.Image.GetInstance(bm, System.Drawing.Imaging.ImageFormat.Bmp);
img.ScalePercent(72f / img.DpiX * 100);
img.SetAbsolutePosition(0, 0);
cb.AddImage(img);
}
document.Close();
writer.Close();
bm.Dispose();
请让我知道,我做错了什么......谢谢