Spire.PDF is a professional PDF library applied to creating, writing, editing, handling and reading PDF files without any external dependencies. Get free and professional technical support for Spire.PDF for .NET, Java, Android, C++, Python.

Fri Jan 20, 2023 5:24 am

Hi,
I'm have some PDF files and need add to end of documents 2 QRCode whits signers information. I'm need to get size of remaining space on page, to understand place QRCodes to end page or addin new page.
is it possible to use Spire.PDF to calculate the free space on the page?

AlexKarpenko
 
Posts: 2
Joined: Tue Feb 04, 2020 9:16 am

Fri Jan 20, 2023 9:43 am

Hi,

Thanks for your inquiry.
Please see the following code for reference.
Code: Select all
            PdfDocument pdf = new PdfDocument();
            pdf.LoadFromFile("sample.pdf");
            PdfPageBase p = pdf.Pages[0];
            // find all texts
            string allTexts = p.ExtractText();
            string[] tr = allTexts.Split(' ');

            // find the last word
            string wanted = tr[tr.Length - 2];
            // get PdfTextFind colloection
            PdfTextFind[] result = p.FindText(wanted, TextFindParameter.None).Finds;
            PdfTextFind text = result[result.Length - 1];
            List<RectangleF> list = text.TextBounds;
            RectangleF rf = list[list.Count - 1];
            // get the height of the text
            float textBoundHeight = rf.Height;
            float textPosition = text.Position.Y;
            // get height of the page
            float pageHeight = p.Size.Height;
            // calculate the free height
            float freeHeight = pageHeight - textBoundHeight - textPosition;

If the code does not meet your requirement, please provide your pdf documents to help us work out a solution for you. You can send them to us via email ([email protected]) or attach them here. Thanks for your assistance.

Sincerely,
Triste
E-iceblue support team
User avatar

Triste.Dai
 
Posts: 1000
Joined: Tue Nov 15, 2022 3:59 am

Thu Jan 26, 2023 5:28 am

The code works fine. Thank you very much!

AlexKarpenko
 
Posts: 2
Joined: Tue Feb 04, 2020 9:16 am

Thu Jan 26, 2023 12:58 pm

Hello,

Thanks for your feedback.
If you have any issue in the future, just feel free to contact us.

Sincerely,
Abel
E-iceblue support team
User avatar

Abel.He
 
Posts: 1010
Joined: Tue Mar 08, 2022 2:02 am

Return to Spire.PDF