PDA

View Full Version : مشكل در تهيه pdf از گزارش



r_mehrizi
یک شنبه 27 اردیبهشت 1388, 12:47 عصر
من يه گزارش ساختم كه اطلاعات را به خوبي نشون ميده در كنار اون يه دكمه گذاشتم كه كاربر بتونه اطلاعات را به pdf تبديل كنه
اما فايل pdf كه ساخته ميشه اطلاعات اون به هم ريخته هستش
فايل pdf را براتون ميذارم.كدها هم به اين شكله



Protected Sub btn_export_Click(ByVal sender As Object, ByVal e As System.Web.UI.ImageClickEventArgs) Handles btn_export.Click
Dim ConnInfo As New ConnectionInfo
Dim Str As String = ASP.global_asax.StrCon
Dim s() As String = str.Split(";")
With ConnInfo
.ServerName = s(0).Split("=")(1).Trim '"."
.DatabaseName = s(1).Split("=")(1).Trim '"Northwind"
.IntegratedSecurity = True
End With
Dim rep As New ReportDocument
rep.PrintOptions.PaperOrientation = PaperOrientation.DefaultPaperOrientation
rep.Load(Server.MapPath("../../report/" & (Session("kind") & ".rpt").ToString.Trim))
'===========================
Dim cls As New clsBase
rep.SetParameterValue("@search", Session("str_query").ToString)
rep.SetParameterValue("Tarikh", cls.getdate.Trim)
' rep.SetParameterValue("Title", Session("strTitle"))
rep.PrintOptions.PrinterName = ""
Me.CrystalReportViewer1.ReportSource = rep
Dim RepTbls As Tables = rep.Database.Tables
For Each RepTbl As Table In RepTbls
Dim RepTblLogonInfo As TableLogOnInfo = RepTbl.LogOnInfo
RepTblLogonInfo.ConnectionInfo = ConnInfo
RepTbl.ApplyLogOnInfo(RepTblLogonInfo)
Next
Me.CrystalReportViewer1.ReportSource = rep
Me.CrystalReportViewer1.DataBind()
Dim path As String = Server.MapPath("report").ToString.Trim
path = path & "\..\..\..\report\rep.pdf"
rep.ExportToDisk(ExportFormatType.PortableDocForma t, path)
DownloadFile(path, GetFileType(path))

End Sub

Public Shared Sub DownloadFile(ByVal FilePath As String, Optional ByVal ContentType As String = "")
Dim t As System.IO.FileAttributes
t = File.GetAttributes(FilePath)
If File.Exists(FilePath) Then
Dim myFileInfo As FileInfo
Dim StartPos As Long = 0, FileSize As Long, EndPos As Long
myFileInfo = New FileInfo(FilePath)
FileSize = myFileInfo.Length
EndPos = FileSize
HttpContext.Current.Response.Clear()
HttpContext.Current.Response.ClearHeaders()
HttpContext.Current.Response.ClearContent()
Dim Range As String = HttpContext.Current.Request.Headers("Range")
If Not ((Range Is Nothing) Or (Range = "")) Then
Dim StartEnd As Array = Range.Substring(Range.LastIndexOf("=") + 1).Split("-")
If Not StartEnd(0) = "" Then
StartPos = CType(StartEnd(0), Long)
End If
If StartEnd.GetUpperBound(0) >= 1 And Not StartEnd(1) = "" Then
EndPos = CType(StartEnd(1), Long)
Else
EndPos = FileSize - StartPos
End If
If EndPos > FileSize Then
EndPos = FileSize - StartPos
End If
HttpContext.Current.Response.StatusCode = 206
HttpContext.Current.Response.StatusDescription = "PartialContent"
HttpContext.Current.Response.AppendHeader("Content-Range", "bytes " & StartPos & "-" & EndPos & "/" & FileSize)
End If
If Not (ContentType = "") And (StartPos = 0) Then
HttpContext.Current.Response.ContentType = ContentType
End If
HttpContext.Current.Response.AppendHeader("Content-disposition", "attachment; filename=" & myFileInfo.Name)
HttpContext.Current.Response.WriteFile(FilePath, StartPos, EndPos)
HttpContext.Current.Response.End()
End If
End Sub
'================================
Public Shared Function GetFileType(ByVal FilePath As String) As String
' Dim path1 As Path
Dim fullpath = path.GetFullPath(FilePath)
Dim name = path.GetFileName(fullpath)
Dim ext = path.GetExtension(fullpath)
Dim type As String = ""
If Not IsDBNull(ext) Then
ext = LCase(ext)
End If
Select Case ext
Case ".htm", ".html"
type = "text/HTML"
Case ".txt"
type = "text/plain"
Case ".doc", ".rtf"
type = "Application/msword"
Case ".csv", ".xls"
type = "Application/x-msexcel"
Case ".pdf"
type = "application/pdf"
Case Else
type = "text/plain"
End Select
Return type
End Function

Tasiyan
دوشنبه 28 اردیبهشت 1388, 19:04 عصر
http://barnamenevis.org/forum/showpost.php?p=709046&postcount=2
منظور فيلد داخل كريستال رو رايت تو لفت كن
:لبخند:

r_mehrizi
سه شنبه 29 اردیبهشت 1388, 09:30 صبح
اين كه گفتيد را امتحان كردم اما درست نشد .نظر ديگري نداريد؟

r_mehrizi
سه شنبه 29 اردیبهشت 1388, 13:35 عصر
توي قسمت properties خاصيت textformat را به crRTFText تبديل كرد