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.

Mon Oct 27, 2014 8:06 am

Dear reader,

I'm trying to add a background to an existing PDF. That works fine, except for the transparency: the image I'm adding appears faded (more transparent) on the page than the original image. Setting the transparency of the background image to 100, causes the background image to appear correct, however, it hides the content of the page.

Is there a solution for this problem?

Thanks and kind regards,

Geri Wolters

geriwolters
 
Posts: 3
Joined: Wed Jul 30, 2014 11:18 am

Mon Oct 27, 2014 9:04 am

Dear geriwolters,

Thanks for your inquiry.

For background image, you can set the "page.BackgroudOpacity" to the proper value to display.
Also, you can set the transparency of PdfImage on page (the original image), see link below:
http://www.e-iceblue.com/Tutorials/Spir ... B.NET.html

Best Regards,
Burning
E-iceblue Support Team
Best Regards,
Burning
E-iceblue Support Team
User avatar

burning.liu
 
Posts: 406
Joined: Mon Aug 04, 2014 6:47 am

Mon Oct 27, 2014 1:26 pm

Dear Burning,

Thanks for your reply. Just to make things clear:

I am modifying an existing PDF by processing each page and set for that page the BackgroundImage property. When I set BackgroundTransparancy to 100, I only see the background clearly. Everything else is just not visible. It appears that the background image is on top of the content of the page, hiding the content. It should (I believe) be underneath the content.

I do not think that has anything to do with transparency on the image on the page, as I don't place one.

I believe the behavior is easy to reproduce:
1) Open an existing PDF
2) For each page, set the background image
3) Save the PDF.

For testing, you can set the BackGroundTransparency to 100%. In my case, ONLY the background image is visible, the rest is hidden. The page content should be projected over the background image, not underneath it.

Is there a way to push the background image down?
Or do I have to create a new PDF entirely and somehow (how) copy the content of the original page?

Thanks and kind regards,

Geri Wolters

geriwolters
 
Posts: 3
Joined: Wed Jul 30, 2014 11:18 am

Tue Oct 28, 2014 2:24 am

Dear geriwolters,

Thanks for your reply.

In Spire.Pdf, we set page.BackgroundOpacity to display page's background, not transparency, they are opposite.
See the code below:
Code: Select all
PdfDocument pdf = new PdfDocument("GenerationDocumentHandler.pdf");
Image img = Image.FromFile("Background.png");
foreach (PdfPageBase page in pdf.Pages)
{
    page.BackgroundImage = img;
    page.BackgroudOpacity = 0.25f;// default, NOTE: it's Opacity, not transparency
}
pdf.SaveToFile("result.pdf");

Best Regards,
Burning
E-iceblue Support Team
Best Regards,
Burning
E-iceblue Support Team
User avatar

burning.liu
 
Posts: 406
Joined: Mon Aug 04, 2014 6:47 am

Tue Oct 28, 2014 7:24 am

Dear Burning.

I'm trying to do just that.

However, my results are different.

page.BackgroundImage = backgroundImage;
page.BackgroudOpacity = .1f;

Result: background is looking faded. Not what I need.

page.BackgroundImage = backgroundImage;
page.BackgroudOpacity = 1f;

Background is crisp (as it should be), but the page content is not shown.

page.BackgroundImage = backgroundImage;
page.BackgroudOpacity = .9f;

Background is crisp, but the content is very faded.

Am I missing something?

What my requirements are, is that the background image is crisp AND the page content is crisp as well. Making both 50% is not acceptable.

If this method doesn't work with the BackgroundImage property, is there another way to achieve this? Something like Z-ordering layers or such?

Thanks and kind regards,

Geri Wolters

geriwolters
 
Posts: 3
Joined: Wed Jul 30, 2014 11:18 am

Tue Oct 28, 2014 9:05 am

Dear geriwolters,

Thanks for your reply.

I found another way to meet your requirement, please refer to the code below:
Code: Select all
PdfDocument loNewDoc = new PdfDocument();
PdfTemplate template = new PdfTemplate(PdfPageSize.A4);
string textWater = "Burning.Liu from E-iceblue Support Team";
PdfFont font = new PdfFont(PdfFontFamily.TimesRoman, 24);
PdfBrush brush = PdfBrushes.Red;

float x = font.MeasureString(textWater).Width;
float y = font.MeasureString(textWater).Height;

template.Graphics.SetTransparency(.8f); // set transparency for image
PdfImage lopdfImage = PdfImage.FromFile("p1.png");
template.Graphics.DrawImage(lopdfImage, 100, 100); //draw image at first
//here you can set tranparency again to make content more clearly
template.Graphics.SetTransparency(1f);
template.Graphics.DrawString(textWater, font, brush, new PointF(100, 100)); // then draw the string

PdfPageBase page = loNewDoc.Pages.Add(PdfPageSize.A4, new PdfMargins(0));
template.Draw(page.Canvas, new PointF(0, 0));
loNewDoc.SaveToFile("templatetry.pdf");

Best Regards,
Burning
E-iceblue Support Team
Best Regards,
Burning
E-iceblue Support Team
User avatar

burning.liu
 
Posts: 406
Joined: Mon Aug 04, 2014 6:47 am

Thu Oct 30, 2014 8:00 am

Dear geriwolters,

Have you tried the method I provided? Did it work well?
Please feel free to contact us if you have any problems.

Best Regards,
Burning
E-iceblue Support Team
Best Regards,
Burning
E-iceblue Support Team
User avatar

burning.liu
 
Posts: 406
Joined: Mon Aug 04, 2014 6:47 am

Fri Jun 17, 2016 1:48 pm

Got exact the same problem as the OP had.

I tried your suggested solution but still does not work. It creates text, though what I want =
1. Have an existing PDF file with text in it.
2. Add a background image to it and show it as the original background image (not faded).

This doesn't seem to work like the OP stated, setting opacity sets the background image on top showing its original colors/image but hiding all the other text of the initial PDF file. Transparency doesn't seem to work either.
As for the suggested solution, all this does is create some custom text on the background image, though I want to keep the original PDF file and its content (the text).

NicolasMous
 
Posts: 6
Joined: Fri Jun 17, 2016 1:43 pm

Mon Jun 20, 2016 7:46 am

Hi,

Thanks for your posting.
Please try the following solution to add background image.
Code: Select all
  PdfDocument doc = new PdfDocument();
            doc.LoadFromFile(input);
            foreach (PdfPageBase page in doc.Pages)
            {
                page.BackgroundImage = Image.FromFile("..\\..\\Background.png");
            }
             string output = "result.pdf";
            doc.SaveToFile(output);


Best Regards,
Amy
E-iceblue support team
User avatar

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

Wed Jun 22, 2016 6:01 am

Hi,

Has your issue been resolved?
Thanks for your feedback in advance.

Best Regards,
Amy
E-iceblue support team
User avatar

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

Tue Jul 26, 2016 10:22 am

Hi Amy,

The issue has not been resolved. When trying out your solution it still has a faded background. See here the result:

The original background picture:
Image


The PDF with the merged Background:
Image

NicolasMous
 
Posts: 6
Joined: Fri Jun 17, 2016 1:43 pm

Wed Jul 27, 2016 3:26 am

Hi,

Thanks for your feedback.
Please try to use following method.
Code: Select all
page.BackgroudOpacity = 1;


Sincerely,
Betsy
E-iceblue support team
User avatar

Betsy
 
Posts: 802
Joined: Mon Jan 19, 2015 6:14 am

Fri Jul 29, 2016 7:19 am

Hi,

Did you test the method I provided ? Has your issue been resolved ?
Thanks for your feedbac.

Sincerely,
Betsy
E-iceblue support team
User avatar

Betsy
 
Posts: 802
Joined: Mon Jan 19, 2015 6:14 am

Tue Aug 02, 2016 11:21 am

No this does'nt work. Like stated in the Post on Fri Jun 17, 2016 and like the OP stated on his post on Tue Oct 28, 2014, the initial text of the orignal PDF (without the background) gets overlapped/dissapears by the background image if you set the
Code: Select all
BackgroudOpacity
to 1.....

NicolasMous
 
Posts: 6
Joined: Fri Jun 17, 2016 1:43 pm

Wed Aug 03, 2016 6:07 am

Hi,

Thanks for your response.
If you want to set backgroud image for PDF and the initial text of the orignal PDF doesn't get overlapped, the backgroud image must be transparent, I think you can set the BackgroudOpacity to 0.8f (or other value according to your requirement), the color of backgroud image is close to the original. I have attached the result PDF with setting the BackgroudOpacity to 0.8f.

Sincerely,
Betsy
E-iceblue support team
User avatar

Betsy
 
Posts: 802
Joined: Mon Jan 19, 2015 6:14 am

Return to Spire.PDF