I am struggling to get PNG files with transparency to import into a PDF. I have tried several different PNG files with no look. The transparent background section either comes out as black or blurred.
Please see the code I have been experimenting with below.
--------------------------------
Dim FormatProvider As New PdfFormatProvider
FormatProvider.ExportSettings.ImageQuality = ImageQuality.High
Dim Document As New RadFixedDocument
Dim Page As RadFixedPage = Document.Pages.AddPage()
Page.Size = New Size(PageWidth, PageHeight)
Editor = New FixedContentEditor(Page)
'Method 1
Editor.Position.Translate(0, 0)
Dim imageStreamSource As New FileStream("Logo1.png", FileMode.Open, FileAccess.Read, FileShare.Read)
Dim decoder As New PngBitmapDecoder(imageStreamSource, BitmapCreateOptions.PreservePixelFormat, BitmapCacheOption.Default)
Dim bitmapSource As BitmapSource = decoder.Frames(0)
Editor.DrawImage(bitmapSource.ToImageSource)
'Method 2
Editor.Position.Translate(0, 200)
Using source As FileStream = File.Open("Logo2.png", FileMode.Open)
Dim imageSource As New Resources.ImageSource(source)
Editor.DrawImage(imageSource)
End Using
'Method 3
Editor.Position.Translate(0, 400)
Dim bitmap As New BitmapImage()
bitmap.BeginInit()
bitmap.UriSource = New Uri("Logo3.png")
bitmap.EndInit()
Editor.DrawImage(bitmap.ToImageSource)
Dim filename As String = "test.pdf"
Using DocStream As New FileStream(filename, FileMode.Create)
FormatProvider.Export(Document, DocStream)
End Using
-----------------------------------
Any advice would be very much appreciated. I am finding the RadPDFProcessing tool extremely useful in a dynamic product brochure project i am working on but i need to be able to use transparent images. If its not possible to use a PNG file is the another file format i could import to the PDF that allows for transparency?
Please see the code I have been experimenting with below.
--------------------------------
Dim FormatProvider As New PdfFormatProvider
FormatProvider.ExportSettings.ImageQuality = ImageQuality.High
Dim Document As New RadFixedDocument
Dim Page As RadFixedPage = Document.Pages.AddPage()
Page.Size = New Size(PageWidth, PageHeight)
Editor = New FixedContentEditor(Page)
'Method 1
Editor.Position.Translate(0, 0)
Dim imageStreamSource As New FileStream("Logo1.png", FileMode.Open, FileAccess.Read, FileShare.Read)
Dim decoder As New PngBitmapDecoder(imageStreamSource, BitmapCreateOptions.PreservePixelFormat, BitmapCacheOption.Default)
Dim bitmapSource As BitmapSource = decoder.Frames(0)
Editor.DrawImage(bitmapSource.ToImageSource)
'Method 2
Editor.Position.Translate(0, 200)
Using source As FileStream = File.Open("Logo2.png", FileMode.Open)
Dim imageSource As New Resources.ImageSource(source)
Editor.DrawImage(imageSource)
End Using
'Method 3
Editor.Position.Translate(0, 400)
Dim bitmap As New BitmapImage()
bitmap.BeginInit()
bitmap.UriSource = New Uri("Logo3.png")
bitmap.EndInit()
Editor.DrawImage(bitmap.ToImageSource)
Dim filename As String = "test.pdf"
Using DocStream As New FileStream(filename, FileMode.Create)
FormatProvider.Export(Document, DocStream)
End Using
-----------------------------------
Any advice would be very much appreciated. I am finding the RadPDFProcessing tool extremely useful in a dynamic product brochure project i am working on but i need to be able to use transparent images. If its not possible to use a PNG file is the another file format i could import to the PDF that allows for transparency?