Quantcast
Channel: Recent Threads — Xamarin Community Forums
Viewing all articles
Browse latest Browse all 204402

How to modify PDF to show image overlay

$
0
0

Hi,

I'm trying to build a PDF document preview in a Xamarin.Forms iOS client. The user should be able to load an image and place it inside the PDF document. Currently, I am able to create a copy of the affected PdfPage and show it in the PdfView (including the user's image). The problem now is, that the user's image is always overlayed by the annotations (which are images too) of the page.

I already tried to create a custom page class, by inheriting from PdfPage, and override the Draw method inside. There, I called base.Draw(box, context) and then drawed the user's image. But it is still overlayed by the annotation.

    context.DrawImage(
                new CGRect(
                    (int)Position.X - (int)(Image.Width * 0.5),
                    (int)Position.Y - (int)(Image.Height * 0.5),
                    (int)Image.Width,
                    (int)Image.Height
                ),
                Image
            );

I also managed to add a watermark text to the PdfPage that overlays all content.

        var attributes = new UIStringAttributes()
            {
                ForegroundColor = UIColor.FromRGBA(255, 0, 0, 125),
                Font = UIFont.BoldSystemFontOfSize(84)
            };

            var text = new NSAttributedString("WATERMARK", attributes);

            text.DrawString(new CGPoint(250, 40));

But I have absolutely no idea, how to use an image here instead of simple text.

My questions:
1. How to draw a CGImage into a PdfPage that overlays the annotation?
OR
2. How to add the CGImage as a PdfAnnotation
OR
3. How to add a watermark (image, not text/string) to the PdfPage
OR
4. How to add a image stamp to the PdfPage

One answer to any of the questions would solve my problem, but up to now I was unable to find any sample code for this problem.


Viewing all articles
Browse latest Browse all 204402

Latest Images

Trending Articles



Latest Images

<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>