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
 Watermark on PDF
 New Topic  Reply to Topic
Author Previous Topic Topic Next Topic  

aleatprog

132 Posts

Posted - May 17 2024 :  15:55:44  Show Profile  Reply
Hi,

I need to insert a watermark below the text of a PDF document.

Adding an image using e.g. ImageEnView1.PdfViewer.Objects.AddImage(100, 800, 200, 200, bmp), is it somehow possible to assign it the background index in order to insert it below the other objects? Or do I need to cut & paste each object on top of the watermark using a loop?

Ale

xequte

38608 Posts

Posted - May 17 2024 :  18:46:49  Show Profile  Reply
Hi Ale

Unfortunately there is not a method to set the z-order with PDFium.

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

aleatprog

132 Posts

Posted - May 18 2024 :  03:50:10  Show Profile  Reply
Hi Nigel,

as mentioned in the opening post, I tried to change the z-order with cut & paste using the following code:

for i := 0 to ImageEnView1.PdfViewer.Objects.Count - 1 do
  if ImageEnView1.PdfViewer.Objects.Items[i].ObjectType = ptText then
    begin
      ImageEnView1.PdfViewer.SelectedObject := i;
      ImageEnView1.PdfViewer.CutToClipboard();
      ImageEnView1.PdfViewer.PasteFromClipboard();
    end;
ImageEnView1.PdfViewer.ApplyChanges;
ImageEnView1.PdfViewer.SaveToFile(path);


The result was inproper (see attached images). Following the main issues:

- While iterating, the number of objects resulting from ImageEnView1.PdfViewer.Objects.Count decreased causing the error 'Argument "Index" (i) out of range' due to i > ImageEnView1.PdfViewer.Objects.Count;
- Occasionaly, object position changed;
- Occasionaly, object/text content disappeared;
- Frequently, object formatting (e.g. text size, text style) changed.

With the above code, quite no text object had been copied properly. The correct objects in the output image should be objects which had been excluded from the iteration as I manually reduced the range in order not to get out of range.

Is there a way to improve the code in order to get proper results?

Ale

Output:


Input:
Go to Top of Page

xequte

38608 Posts

Posted - May 20 2024 :  00:20:24  Show Profile  Reply
It is not possible to do this using PDFium.

PDFium does not support clipboard or object streaming, so the process you use below is not going to be 1:1. At this stage PDFium does not provide methods to get all the properties of an object, nor all the the methods to set the properties of an object, so information will be lost.

Nigel
Xequte Software
www.imageen.com
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
Jump To: