PDFsharp & MigraDoc Foundation

PDFsharp - A .NET library for processing PDF & MigraDoc Foundation - Creating documents on the fly
It is currently Thu Mar 28, 2024 9:31 am

All times are UTC


Forum rules


Please read this before posting on this forum: Forum Rules



Post new topic Reply to topic  [ 2 posts ] 
Author Message
PostPosted: Tue Sep 13, 2016 8:04 am 
Offline

Joined: Tue Apr 05, 2016 11:23 am
Posts: 11
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.


Top
 Profile  
Reply with quote  
PostPosted: Wed Sep 14, 2016 7:52 am 
Offline
PDFsharp Guru
User avatar

Joined: Mon Oct 16, 2006 8:16 am
Posts: 3095
Location: Cologne, Germany
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.

_________________
Regards
Thomas Hoevel
PDFsharp Team


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 2 posts ] 

All times are UTC


Who is online

Users browsing this forum: Google [Bot] and 146 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron
Privacy Policy, Data Protection Declaration, Impressum
Powered by phpBB® Forum Software © phpBB Group