Dispose Method for FlexReport?

Posted by: cvandien on 30 April 2019, 12:03 pm EST

    • Post Options:
    • Link

    Posted 30 April 2019, 12:03 pm EST

    Hello,

    Esha provided the following code (works great) for rasterizing a .PDF page and displaying it an ImageField so that I could co-mingle the .PDF with other report elements…

    I need to delete the images that are created when the form closes and (assuming) I need to dispose of the ImageField to break the connection to the Imge Files so I can do a File.Delete(filename) command.

    Setting the objects to Nothing does not resolve the issue… What is the referred process of disposing the Report?

    Here’s the code that derives each .PDF page:

                C1PdfDocumentSource1.LoadFromFile("\\TCHWhiteCloud\WhiteCloudAttachments\Active Admit Nurses.pdf")
    
                'Create JPEGFilter object
                Dim filter As New JpegFilter()
                filter.FileName = "../../Images/" & Globals.Username.ToUpper & ".jpg"
    
                C1PdfDocumentSource1.Export(filter)
    
                Dim d As New System.IO.DirectoryInfo(directoryName)
                'Dim img As ImageField
    
                For i As Integer = 1 To d.GetFiles.GetUpperBound(0) + 1
                    img = New ImageField
                    Dim subSection As SubSection = C1FlexReport1.Sections.Detail.SubSections.Add()
                    subSection.Visible = True
                    subSection.Height = C1FlexReport1.Layout.PageSize.Height
                    subSection.AutoHeight = AutoSizeBehavior.None
    
                    img.Top = 0
                    img.Left = 0
                    img.MarginTop = 0
                    img.MarginBottom = 0
                    img.Height = 1440 * 8.9
                    img.Width = 1440 * 7.9
                    'img.AutoHeight = AutoSizeBehavior.GrowAndShrink
                    'img.AutoWidth = AutoSizeBehavior.GrowAndShrink
                    img.PictureScale = PictureScaleEnum.Scale
                    img.BackColor = Color.LightGray
    
                    img.Border.Color = Color.Black
                    img.Border.Style = BorderStyleEnum.Solid
    
                    img.Picture = Image.FromFile(Path.Combine(directoryName, Globals.Username.ToUpper & "_page" & i & ".jpg"))
    
                    subSection.Fields.Add(img)
    
                Next
    
  • Posted 1 May 2019, 3:17 am EST

    Hi Chuck,

    You can set the image to the ImageField using a stream instance. This can be done as follows:

    Public Class Form1
        Dim stream1 As FileStream
        Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
    .
    .
    .
      img.Top = 0
                img.Left = 0
                img.MarginTop = 0
                img.MarginBottom = 0
                img.Height = 1440 * 8
                img.Width = 1440 * 7
                img.Border.Style = C1.Win.C1Document.DashStyle.Solid
                img.Border.Color = Color.Red
                img.Border.Width = 40
                img.PictureScale = PictureScaleEnum.Scale
                stream1 = New FileStream(Path.Combine(directoryName, "DefaultDocument_page" & i & ".jpg"), FileMode.Open, FileAccess.Read)
                img.Picture = Image.FromStream(stream1)
                subSection.Fields.Add(img)
    
            Next
    
            C1FlexReport1.Render()
            C1FlexViewer1.DocumentSource = C1FlexReport1
            stream1.Dispose()
        End Sub
    End Class
    

    You can now delete the image files using File.Delete(filename) command.

    Hope it helps.

    Best Regards,

    Esha

  • Posted 1 May 2019, 4:28 pm EST

    thank you for your help and ideas.

Need extra support?

Upgrade your support plan and get personal unlimited phone support with our customer engagement team

Learn More

Forum Channels