PDFsharp & MigraDoc Foundation
https://forum.pdfsharp.net/

How to detect if a page contains an image
https://forum.pdfsharp.net/viewtopic.php?f=2&t=3455
Page 1 of 1

Author:  Entwickler582 [ Tue Sep 13, 2016 8:04 am ]
Post subject:  How to detect if a page contains an image

Is it possible to somehow detect whether a page in the document contains an image? We would like to render the background only if the page in the document contains no image. We tried this code. Unfortunately it does not work as the document objects that are returned are paragraphs or tables. I have no idea where the images (which are definitely there) are hidden.

Code:
                        DocumentObject[] doj = this.renderer.GetDocumentObjectsFromPage(pageNumber);
                        bool containsImg = false;
                        foreach (DocumentObject d in doj)
                        {
                            if (d is MigraDoc.DocumentObjectModel.Shapes.Image)
                            {
                                containsImg = true;
                                break;
                            }
                        }
                        if (!containsImg)
                        {
                            fixedPage.Background = new ImageBrush(image);
                        }

As the next step, we would also like to get the position of the image on the page.

Author:  Thomas Hoevel [ Wed Sep 14, 2016 7:52 am ]
Post subject:  Re: How to detect if a page contains an image

Hi!

The images are where you add them: inside paragraphs, inside table cells, inside paragraphs inside table cells, ...
You will need a recursive approach. IIRC tables that span several pages require special treatment.

After running PrepareDocument you can query the positions of the objects.

Page 1 of 1 All times are UTC
Powered by phpBB® Forum Software © phpBB Group
https://www.phpbb.com/