Spire.PDF is a professional PDF library applied to creating, writing, editing, handling and reading PDF files without any external dependencies. Get free and professional technical support for Spire.PDF for .NET, Java, Android, C++, Python.

Fri Jan 01, 2016 11:34 pm

My object is to add an existing pdf document to another existing pdf document as a new layer. Both have only one page, same size.
I faced this problem: some docs have white background, so this new layer covers the other content of the page under this layer.

Is there a way to make transparent only a specific color (the white background)?
Thanks for any reply.

vad
 
Posts: 2
Joined: Sat Mar 29, 2014 8:53 am

Mon Jan 04, 2016 3:22 am

Hi,

Thanks for your posting and using our Spire.PDF.
Please try the function layer.Graphics.SetTransparency(0.6f, 0.6f, PdfBlendMode.Multiply);.
Share sample code:
Code: Select all
       
            PdfDocument doc1 = new PdfDocument();
            doc1.LoadFromFile(@"..\..\Input\Layers\WhiteBackgroundDoc1.pdf");

            PdfDocument doc2 = new PdfDocument();
            doc2.LoadFromFile(@"..\..\Input\Layers\WhiteBackgroundDoc2.pdf");

            //Create page template
            PdfTemplate template = doc1.Pages[0].CreateTemplate();

            PdfPageLayer layer = doc2.Pages[0].PageLayers.Add("NewLayer");
            layer.Graphics.SetTransparency(0.6f, 0.6f, PdfBlendMode.Multiply);     
            layer.Graphics.DrawTemplate(template,PointF.Empty);

            doc2.SaveToFile("AddLayers.pdf");
            doc1.Close();
            doc2.Close();


Best Regards,
Amy
E-iceblue support team
User avatar

amy.zhao
 
Posts: 3011
Joined: Wed Jun 27, 2012 8:50 am

Mon Jan 04, 2016 11:09 am

Hy Amy,

Thank you for your answer.
I examined the way you suggested (and the other blendmodes). Altough it's an amazing effect, I've got two problems.
First, the fading. As I see, it can be corrected by the SetTransparency(1f, 1f, PdfBlendMode.Multiply) parameters.
Second, not only the white parts get transparent, but everything.
For a little explanation: I'm working on a GIS-application, where the order of the shapes can be important. Which shape covers which, it may hase meaning. That's why the layered PDF-structure is needed.
If everything is transparent, the order of the shapes will be lost. So, I'm afraid, I have to look for some other solution.
Thanks again.

Best regards,
vad

vad
 
Posts: 2
Joined: Sat Mar 29, 2014 8:53 am

Tue Jan 05, 2016 1:26 am

Hi,

Thanks for your feedback.
Sorry that my solution doesn't resolve your issue. At present we don't have the methods to make transparent only a specific color (the white background), sorry.

Best Regards,
Amy
E-iceblue support team
User avatar

amy.zhao
 
Posts: 3011
Joined: Wed Jun 27, 2012 8:50 am

Return to Spire.PDF

cron