我的应用程序使用面板来模拟用户填写的模板然后打印。
然而,他们最终会有超过300页,而我的例程会使PDF速度变慢,占用太多内存,最终会因“OutofMemoryException”或“Invalid Parameter”消息而崩溃。
我使用的方法是;将重要信息加载到页面上,然后将其转换为位图图像以放置在PDFPage上。
发现这真的没用,有什么建议吗?
顺便说一句,我使用PDFSharp来做到这一点。
处理此问题的例程;
For i = 0 To Count - 1
If i = 0 Then ConditionReportConfig.SwitchPage5(Pages(i), False) Else ConditionReportConfig.SwitchPage5(Pages(i), True)
If WithPics = True And ConditionReportConfig.PG5.PbxAddress(2) <> "" And ConditionReportConfig.PG5.txt_Occupier5.Enabled = True Then
frm_MsgAttachment.pbx_Picture.Image = Image.FromFile(ConditionReportConfig.PG5.PbxAddress(2))
Dim PicPage As PdfPage = PDFDoc.AddPage
PicPage.Orientation = PageOrientation.Landscape
Dim xgr As XGraphics = XGraphics.FromPdfPage(PicPage)
Dim img As XImage
Dim xBitmap As Bitmap
PicPage.Orientation = PageOrientation.Landscape
xBitmap = New Bitmap(2480, 3508)
frm_MsgAttachment.pbx_Picture.DrawToBitmap(xBitmap, New Rectangle(0, 0, xBitmap.Width, xBitmap.Height))
img = xBitmap
xgr.DrawImage(img, 6, 5, 2300, 3508)
xgr.Dispose()
xgr = Nothing
xBitmap.Dispose()
xBitmap = Nothing
GC.Collect()
End If
Dim CDR5 As PdfPage = PDFDoc.AddPage
CDR5.Orientation = PageOrientation.Landscape
GFX = XGraphics.FromPdfPage(CDR5)
Bitmap = New Bitmap(ConditionReportConfig.PG5.Panel1.Width, ConditionReportConfig.PG5.Panel1.Height)
ConditionReportConfig.PG5.Panel1.DrawToBitmap(Bitmap, New Rectangle(0, 0, Bitmap.Width, Bitmap.Height))
BXImage = Bitmap
GFX.ScaleTransform(0.82)
GFX.DrawImage(BXImage, 0, 25)
GFX.Dispose()
GFX = Nothing
Dim valu = frm_Main.pgb_Load.Value
frm_Main.SetPrgBarValue(valu + tem)
Next