ImageEn for Delphi and C++ Builder ImageEn for Delphi and C++ Builder

 

ImageEn Forum
Profile    Join    Active Topics    Forum FAQ    Search this forumSearch
Forum membership is Free!  Click Join to sign-up
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 ImageEn Library for Delphi, C++ and .Net
 ImageEn and IEvolution Support Forum
 How to render a PDF page with background color?
 New Topic  Reply to Topic
Author Previous Topic Topic Next Topic  

uko

Germany
35 Posts

Posted - May 21 2025 :  06:03:17  Show Profile  Reply
Hi

I try to render a PDF page on a bitmap with a defined background color (red) but I always get a white page background. This the code I use:

    var lDoc := TPdfDocument.Create;
    try
      lDoc.LoadFromFile('d:\downloads\test_text_back.pdf');
      
      var bmp := TIEBItmap.Create(200, 400, clRed, 255);
      try
        IERenderPDFToBMP(bmp.VclBitmap, lDoc, 0, 200, 400, pw, ph, dpiX, dpiY, prNormal, clRed);

        bmp.DrawToCanvasWithAlpha(self.Canvas, 100, 100);
      finally
        bmp.Free;
      end;
    finally
      lDoc.Free;
    end;


The PDF self has just some text on a single page without background. So what am I doing wrong here?


kind regards,
Ulrich

xequte

39027 Posts

Posted - May 21 2025 :  15:52:11  Show Profile  Reply
Hi Ulrich

The PDF will have a white background, so the red will be replaced by the white.

You should make the image transparent before drawing it onto the red, or just cast the white color as red:

http://www.imageen.com/help/TImageEnProc.CastColorRange.html

Nigel
Xequte Software
www.imageen.com
Go to Top of Page

uko

Germany
35 Posts

Posted - May 22 2025 :  01:39:24  Show Profile  Reply
Hi Nigel,

please look on the attached PDF

Download Attachment: 202552203716_test_text_back.pdf

When you change Adobe Reader to show a transparency grid (page display settings) it shows the page to be entirely transparent with exception of the two text areas.

So using pagecolor parameter of IERenderPDFToBMP I would have expected to see most of the page red with exception of white text areas.

Changing the color after rendering is not a good idea: what if the PDF contains some white areas as content that should appear white (say inside an image or similar)?


kind regards,
Ulrich
Go to Top of Page

xequte

39027 Posts

Posted - May 22 2025 :  03:21:57  Show Profile  Reply
Hi Ulrich

OK, I'm not sure that we implement support for transparent PDF files (as it is not needed for the viewer). I'll need to look into that when I'm back in the office at the end of the May.

Nigel
Xequte Software
www.imageen.com
Go to Top of Page

uko

Germany
35 Posts

Posted - May 22 2025 :  03:46:20  Show Profile  Reply
Thanks!

kind regards,
Ulrich
Go to Top of Page

xequte

39027 Posts

Posted - Jun 02 2025 :  00:36:05  Show Profile  Reply
Hi Ulrich

Sorry, at this time, PDF transparency is not supported and would take time to implement and test.

I have added it to the to-do list for a future version.

Note, also, PDFium does not consider your example above to be transparent.

Nigel
Xequte Software
www.imageen.com
Go to Top of Page

uko

Germany
35 Posts

Posted - Jun 02 2025 :  00:53:59  Show Profile  Reply
Hi Nigel,

thanks for looking onto this!


kind regards,
Ulrich
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
Jump To: