Spire.Doc is a professional Word .NET library specifically designed for developers to create, read, write, convert and print Word document files. Get free and professional technical support for Spire.Doc for .NET, Java, Android, C++, Python.

Fri May 28, 2021 4:10 am

Hi
When I load an image from disk with a transparent background (either png or gif, same result) and insert it into a document and then save as pdf the transparency is lost.
When I save it as a docx, the transparency is preserved.
Is there a way that the transparency can be preserved when saving to pdf?
Code: Select all
 Dim range As TextRange = selection.GetAsOneRange()
                Dim index As Integer = range.OwnerParagraph.ChildObjects.IndexOf(range)
                Dim pic As New DocPicture(pDoc)
                pic.LoadImage(System.Drawing.Image.FromFile(pImage))

                range.OwnerParagraph.ChildObjects.Insert(index, pic)
                range.OwnerParagraph.ChildObjects.Remove(range)

chrisguest
 
Posts: 7
Joined: Wed Jun 17, 2020 8:49 am

Fri May 28, 2021 8:41 am

Hello,

Thanks for your inquiry.
I simulated a Doc file and an image with transparent background, and then tested your code with Spire.Doc Pack(hot fix) Version:9.4.18, but I did not reproduce your issue. If you are using an older version, we recommend you upgrade to the latest version and try it again.
If this issue still occurs, please provide your input file and your image with transparent background to help us investigate further. Thanks in advance.

Sincerely,
Brian
E-iceblue support team
User avatar

Brian.Li
 
Posts: 1271
Joined: Mon Oct 19, 2020 3:04 am

Sat May 29, 2021 3:15 am

Hi Brian
The issue is still occurring with the hotfix. Input file attached.

chrisguest
 
Posts: 7
Joined: Wed Jun 17, 2020 8:49 am

Mon May 31, 2021 3:36 am

Hello,

Thanks for your response and sorry for the late reply as weekend.
I am sorry that I did not see the attachment you mentioned, and this website has the size limitation for attachment. You could upload it to the DropBox or OneDrive and then share the download link with us.

Sincerely,
Brian
E-iceblue support team
User avatar

Brian.Li
 
Posts: 1271
Joined: Mon Oct 19, 2020 3:04 am

Mon May 31, 2021 6:11 am

Hi Brian
The file is only 65 KB and I have reattached it.
The onedrive link is:
https://1drv.ms/w/s!AlE0Wtfwqe8-ktRJRF1 ... g?e=RNLSl3

chrisguest
 
Posts: 7
Joined: Wed Jun 17, 2020 8:49 am

Mon May 31, 2021 11:43 am

Thanks for your sharing.

For the file you provided, I directly opened it with MS Word, and then saved the picture in the first page as a png file, but I found that its background is not transparent.

Meanwhile, I used the following code to insert an image with a transparent background into your file, and then convert it to a pdf file, but found that the background of image in the generated pdf file is still transparent. Attached are my test image and the output file.
Code: Select all
        Dim input As String = "HCR20V3I.1097071.14_V11.docx"
        Dim doc As New Document()
        doc.LoadFromFile(input)
        Dim selections() As TextSelection = doc.FindAllString("Risk", True, True)


        Dim selection = selections(0)

        Dim range As TextRange = selection.GetAsOneRange()
        Dim index As Integer = range.OwnerParagraph.ChildObjects.IndexOf(range)
        Dim pic As New DocPicture(doc)
        pic.LoadImage(System.Drawing.Image.FromFile("Logo1.png"))

        range.OwnerParagraph.ChildObjects.Insert(index, pic)
        range.OwnerParagraph.ChildObjects.Remove(range)
        doc.SaveToFile("result.pdf", FileFormat.PDF)


To help us investigate further, please provide your test image, your output pdf file and your OS information (Win7, 64bit). Thanks in advance.

Sincerely,
Brian
E-iceblue support team
User avatar

Brian.Li
 
Posts: 1271
Joined: Mon Oct 19, 2020 3:04 am

Thu Jun 03, 2021 11:39 am

Hello

How is your issue now? Any feedback will be greatly appreciated.

Sincerely,
Brian
E-iceblue support team
User avatar

Brian.Li
 
Posts: 1271
Joined: Mon Oct 19, 2020 3:04 am

Return to Spire.Doc