PDFsharp & MigraDoc Foundation
http://forum.pdfsharp.de/

Get content Bounding Box
http://forum.pdfsharp.de/viewtopic.php?f=2&t=4292
Page 1 of 1

Author:  ChrisysZero [ Mon Oct 18, 2021 3:29 pm ]
Post subject:  Get content Bounding Box

Hi, I have recently started using PDFSharp, previously I used iTextSharp to manage my PDF files and I'm having trouble trying to get the Bounding Box surrounding only the content inside a pdf page, I need to get the height in point units of said content.

With iTextSharp this is the code used:
Code:
private iTextSharp.text.pdf.PdfRectangle GetContentBoundingBox(iTextSharp.text.pdf.PdfReader reader)
    {
      PdfReaderContentParser parser = new PdfReaderContentParser(reader);
      TextMarginFinder finder = parser.ProcessContent(1, new TextMarginFinder());
      return new iTextSharp.text.pdf.PdfRectangle(finder.GetLlx(), finder.GetLly(), finder.GetUrx(), finder.GetUry());
    }
var contentSize = GetContentBoundingBox(readerHeaderFooter);

var neededHeight = contentSize.Height;


Is there any similar functionality on PDFsharp? or a way to achieve the same or similar results.
Please help.

Author:  TH-Soft [ Wed Oct 20, 2021 6:51 am ]
Post subject:  Re: Get content Bounding Box

PDFsharp does not render PDF. To find the positions of content on the page it is necessary to render PDF.

Author:  ChrisysZero [ Wed Oct 20, 2021 3:14 pm ]
Post subject:  Re: Get content Bounding Box

TH-Soft wrote:
PDFsharp does not render PDF. To find the positions of content on the page it is necessary to render PDF.


Thx for your answer Thomas, can you please elaborate a little bit more on how to find the positions and bounding boxes of the contents on the page, and since you are saying we need to render to PDF I guess I will need to use MigraDoc for this?.

It would be enough if you mention some of the main classes that are required for this purpose, a little sample snippet would be ideal.


Regards

Chris.

Author:  TH-Soft [ Wed Oct 20, 2021 6:09 pm ]
Post subject:  Re: Get content Bounding Box

ChrisysZero wrote:
It would be enough if you mention some of the main classes that are required for this purpose, a little sample snippet would be ideal.
These classes do not exist within PDFsharp and there is no sample code at hand.

Author:  ChrisysZero [ Wed Oct 20, 2021 6:39 pm ]
Post subject:  Re: Get content Bounding Box

TH-Soft wrote:
ChrisysZero wrote:
It would be enough if you mention some of the main classes that are required for this purpose, a little sample snippet would be ideal.
These classes do not exist within PDFsharp and there is no sample code at hand.


I undestand that, thats why I said that "guess I will need to use MigraDoc for this" since MigraDoc uses a render for its documents, so I was reffering to the classes or an example snippet using MigraDoc, sorry for any confusion Thomas, so now the question would be: is it possible to achieve this using MigraDoc?


Regards
Chris.

Author:  TH-Soft [ Wed Oct 20, 2021 9:31 pm ]
Post subject:  Re: Get content Bounding Box

With MigraDoc you can "prepare" a document and then access the render information for all objects of the document. PDF pages imported into MigraDoc will be treated like rectangles and empty regions of those PDF pages will not be taken into the account.

But since you set left and right margins, top and bottom margins, it may not even be necessary to access the render information.

I assumed you were managing existing PDF files. This approach will not work for those.
It will work for PDF documents you create using the MigraDoc document object model.

Author:  ChrisysZero [ Thu Oct 21, 2021 2:40 pm ]
Post subject:  Re: Get content Bounding Box

TH-Soft wrote:
With MigraDoc you can "prepare" a document and then access the render information for all objects of the document. PDF pages imported into MigraDoc will be treated like rectangles and empty regions of those PDF pages will not be taken into the account.

But since you set left and right margins, top and bottom margins, it may not even be necessary to access the render information.

I assumed you were managing existing PDF files. This approach will not work for those.
It will work for PDF documents you create using the MigraDoc document object model.


Thx for your answer Thomas what I'm trying to achieve is the following:

I Have a single page pdf with little content, then using MigraDoc read/import the page into it and get the bounding box surrounding the content in that page, since I need to use the width and height of said content.

Here is a sample pdf page attached, I need to get the red box/bounding box surrounding the content, this pdf is created externally not with MigraDoc or PDFsharp. So what I'm trying to achieve is to read/import the pdf with a single page and get the bounding box of its contents. Is this possible with MigraDoc?


Regards
Chris.

Attachments:
Screenshot 2021-10-21 092552.png
Screenshot 2021-10-21 092552.png [ 15.65 KiB | Viewed 4235 times ]

Author:  TH-Soft [ Thu Oct 21, 2021 6:04 pm ]
Post subject:  Re: Get content Bounding Box

ChrisysZero wrote:
Here is a sample pdf page attached, I need to get the red box/bounding box surrounding the content, this pdf is created externally not with MigraDoc or PDFsharp. So what I'm trying to achieve is to read/import the pdf with a single page and get the bounding box of its contents. Is this possible with MigraDoc?
As I wrote a few times in this thread: Cannot be done with MigraDoc or PDFsharp out of the box.

Author:  ChrisysZero [ Thu Oct 21, 2021 6:10 pm ]
Post subject:  Re: Get content Bounding Box

TH-Soft wrote:
ChrisysZero wrote:
Here is a sample pdf page attached, I need to get the red box/bounding box surrounding the content, this pdf is created externally not with MigraDoc or PDFsharp. So what I'm trying to achieve is to read/import the pdf with a single page and get the bounding box of its contents. Is this possible with MigraDoc?
As I wrote a few times in this thread: Cannot be done with MigraDoc or PDFsharp out of the box.


OK thx so much for your patience and time Thomas.

Regards

Chris.

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