Hi Alex,
Thanks for replying.
Please find attached the sample code which is creating the issue.

On Tue, Jun 1, 2010 at 11:44 AM, Alexis Pigeon <[email protected]>wrote:

> Hi Thomas,
>
>  On 1 June 2010 09:28, Bency Thomas <[email protected]> wrote:
>
>>  Hi,
>>   Iam exporting datagrid to pdf in vb.net using itextsharp.. The pdf
>> generated opens in pdf version 8 and above. But my clients use adobe version
>> 7 and they are unable to open the pdf generated. The error message is
>> "Unable to open. File is damaged or corrupted". Can u please help me with a
>> suitable solution for this.
>>
>
> Our crystal ball is out of service at the moment, we have no way to guess
> what's wrong with the generated file.
>
>
>>  Your help is greatly appreciated...
>>
>
> You'll have to help us so that we can help you :)
> For example, you can send us the PDF file (beware, this is a public mailing
> list, make sure you don't include any confidential data).
> You can also provide a small stand alone piece of code that will enable us
> reproduce the problem.
>
> Cheers,
> alexis
>
>
> ------------------------------------------------------------------------------
>
>
> _______________________________________________
> iText-questions mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/itext-questions
>
> Buy the iText book: http://www.itextpdf.com/book/
> Check the site with examples before you ask questions:
> http://www.1t3xt.info/examples/
> You can also search the keywords list:
> http://1t3xt.info/tutorials/keywords/
>
                    
                Dim arrPendingDetails As New ArrayList(9)
                arrPendingDetails.Insert(0, "ID")
                arrPendingDetails.Insert(1, "Product")
                arrPendingDetails.Insert(2, "Dept")
                arrPendingDetails.Insert(3, "TPending")
                arrPendingDetails.Insert(4, "TUser")
                arrPendingDetails.Insert(5, "TRemarks")
                arrPendingDetails.Insert(6, "FPending")
                arrPendingDetails.Insert(7, "FUser")
                arrPendingDetails.Insert(8, "FRemarks")
                
                ExportToPDF(CType(Viewstate("dsDetails"), DataSet), 
arrFileDetails, "Report - Details ")   



*--------------- Function Export to PDF--------------- *

Public Function ExportToPDF(ByVal dsReport As DataSet, ByVal arrColumNames As 
ArrayList, ByVal reportName As String)
        Dim doc As New Document(PageSize.A4.Rotate, 0, 0, 40, 40)
        Dim filename As String = ""
        Dim smPDF As New System.IO.MemoryStream

        Try
           
            PdfWriter.GetInstance(doc, smPDF)
            doc.Open()
            Dim uri As New 
System.Uri(System.Web.HttpContext.Current.Server.MapPath("Logo.gif"))
            Dim oimg As iTextSharp.text.Image = 
iTextSharp.text.Image.GetInstance(uri)
            oimg.Alignment = oimg.ALIGN_LEFT
            oimg.ScalePercent(50, 50)

            Dim pdftable As New PdfPTable(arrColumNames.Count)
            Dim ocell As PdfPCell
            With pdftable
                ocell = New PdfPCell(oimg)
                ocell.Colspan = (arrColumNames.Count / 2)
                ocell.Border = 0
                ocell.HorizontalAlignment = Element.ALIGN_LEFT
                .AddCell(ocell)

                ocell = New PdfPCell(New iTextSharp.text.Phrase("Report Date : 
" & DateTime.Now.ToString(), FontFactory.GetFont("Arial", 8, 
iTextSharp.text.Font.NORMAL)))
                ocell.Colspan = (arrColumNames.Count / 2)
                ocell.Border = 0
                ocell.HorizontalAlignment = Element.ALIGN_RIGHT
                ocell.VerticalAlignment = Element.ALIGN_BOTTOM
                .AddCell(ocell)

                ocell = New PdfPCell(New iTextSharp.text.Phrase("", 
FontFactory.GetFont("Arial", 12, iTextSharp.text.Font.BOLD)))
                ocell.Border = 0
                ocell.Colspan = arrColumNames.Count
                ocell.HorizontalAlignment = Element.ALIGN_CENTER
                .AddCell(ocell)

                ocell = New PdfPCell(New iTextSharp.text.Phrase("", 
FontFactory.GetFont("Arial", 12, iTextSharp.text.Font.BOLD)))
                ocell.Border = 0
                ocell.Colspan = arrColumNames.Count
                ocell.HorizontalAlignment = Element.ALIGN_CENTER
                .AddCell(ocell)

                ocell = New PdfPCell(New 
iTextSharp.text.Phrase(reportName.ToUpper(), FontFactory.GetFont("Arial", 14, 
iTextSharp.text.Font.BOLD)))
                ocell.Border = 0
                ocell.Colspan = arrColumNames.Count
                ocell.HorizontalAlignment = Element.ALIGN_CENTER
                .AddCell(ocell)

                For i As Integer = 0 To arrColumNames.Count - 1
                    ocell = New PdfPCell(New 
iTextSharp.text.Phrase(arrColumNames(i).ToString(), 
FontFactory.GetFont("Arial", 7, iTextSharp.text.Font.BOLD)))
                    ocell.Border = 1
                    ocell.HorizontalAlignment = Element.ALIGN_CENTER
                    .AddCell(ocell)
                Next


                Dim srow As String = ""
                If dsReport.Tables(0).Rows.Count > 0 Then

                    For Each row As DataRow In dsReport.Tables(0).Rows
                        For Each column As DataColumn In 
dsReport.Tables(0).Columns
                            If Not IsDBNull(row(column)) Then
                                srow = Replace(row(column).ToString().ToUpper, 
"<B>", "")
                                srow = Replace(srow, "</B>", "")
                                srow = Replace(srow, "<HR/>", "")
                                ocell = New PdfPCell(New 
iTextSharp.text.Phrase(Replace(srow, "<BR/>", Environment.NewLine), 
FontFactory.GetFont("Arial", 6, iTextSharp.text.Font.NORMAL)))
                                ocell.Border = 1
                                ocell.HorizontalAlignment = Element.ALIGN_LEFT
                                .AddCell(ocell)
                            Else
                                ocell = New PdfPCell(New 
iTextSharp.text.Phrase("", FontFactory.GetFont("Arial", 6, 
iTextSharp.text.Font.NORMAL)))
                                ocell.Border = 1
                                ocell.HorizontalAlignment = Element.ALIGN_LEFT
                                .AddCell(ocell)
                            End If

                        Next
                    Next
                Else

                End If
            End With
            doc.Add(pdftable)
            doc.Close()


            If Not IsNothing(smPDF) Then
                Dim bytearray As Byte() = smPDF.ToArray()
                smPDF.Flush()
                smPDF.Close()
                System.Web.HttpContext.Current.Response.BufferOutput = True
                System.Web.HttpContext.Current.Response.Clear()
                System.Web.HttpContext.Current.Response.ClearHeaders()
                
System.Web.HttpContext.Current.Response.AddHeader("Content-Disposition", 
"attachment; filename=" & reportName & Date.Now.ToString("ddmmyyyhhmmss") & 
".pdf")
                System.Web.HttpContext.Current.Response.ContentType = 
"application/pdf"
                System.Web.HttpContext.Current.Response.BinaryWrite(bytearray)
              
            End If


           
        Catch ex As Exception
            doc.Close()

        Finally
            doc.Close()
            
        End Try
    End Function

Attachment: Report01242010032415.pdf
Description: Adobe PDF document

------------------------------------------------------------------------------

_______________________________________________
iText-questions mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/itext-questions

Buy the iText book: http://www.itextpdf.com/book/
Check the site with examples before you ask questions: 
http://www.1t3xt.info/examples/
You can also search the keywords list: http://1t3xt.info/tutorials/keywords/

Reply via email to