代码如下
Dim cb As new iTextSharp.text.Rectangle(595,257) '纸张大小
Dim dc As new iTextSharp.text.Document(cb)
Dim a as integer
Dim ft As String = "C:\WINDOWS\Fonts\msyh.TTF" ' ITextSharp支持中文的字体
Dim ift As iTextSharp.text.pdf.BaseFont = iTextSharp.text.pdf.BaseFont.CreateFont(ft, _
iTextSharp.text.pdf.BaseFont.IDENTITY_H, iTextSharp.text.pdf.BaseFont.NOT_EMBEDDED)
'创建实例,PDF 文件将会保存到这里
Dim writer As iTextSharp.text.pdf.PdfWriter = iTextSharp.text.pdf.PdfWriter.GetInstance(dc,new System.IO.FileStream(file,System.IO.FileMode.Create))
'打开文档
dc.Open()
Dim sumyes As Integer = Math.Ceiling(FileSys.GetFiles("d:\cutoff\").Count /3) * 10 + 100 '读文件名 从小到大
For p As Integer = 1 To sumyes
If FileSys.FileExists("d:\cutoff\" & "test" & p & ".jpg") Then
Dim str As String = "d:\cutoff\" & "test" & p & ".jpg"
Dim ifo As new FileInfo(str)
If str.Contains("jpg") AndAlso ifo.Length > 30000 Then 'ifo.Length > 50000 让文件的大小大于 50k 避免空页面加载
a = a + 1
Dim itIm2 As iTextSharp.Text.Image = iTextSharp.text.Image.getInstance(str) '定义ITextSharp图片
itIm2.SetAbsolutePosition(20,1) '设置图片坐标:原点(0,0)为左下角!
itIm2.ScalePercent(20)
dc.add(itIm2)
dc.newpage
End If
End If
Next
dc.Close()
此主题相关图片如下:捕获.jpg
偶尔会提示以上内容, 应该是内存不足吧! 不知道怎么处理好,请指点下
[此贴子已经被作者于2018/3/28 11:03:08编辑过]