Using PDFlib I'm adding elements to a page. My objective is to somehow retrieve combined height and width of the elements after page is closed with $p->end_page_ext("");
.
I know combined height of elements added to that page.
Question. Is it possible to use PDF's ArtBox
to somehow store these dimensions and later retrieve them?
I'm not interested in page's height or width - only the space that added elements occupy.
with PDFlib you can also add the ArtBox to a page. (use option "ArtBox {llx lly urx ury}
" within the begin_page_ext/end_page_ext()
option list.
Afterwards you can retrieve this values from the PDF. For example when using the pCOS interface (it's part of PDFlib+PDI, PLOP, or TET). You find a code sample for the MediaBox in the pCOS Cookbook: https://www.pdflib.com/pcos-cookbook/pages/page_size/
To retrieve the ArtBox you just need to use the pCOS paths:
// $pageno is the 0 based index of the pages. First page is 0
if ($p->pcos_get_number($doc, "type:pages[" . $pageno . "]/ArtBox") == 5)
{
$llx = sprintf("%.2f", $p->pcos_get_number($doc, "pages[" . $pageno . "]/ArtBox[0]"));
$lly = sprintf("%.2f", $p->pcos_get_number($doc, "pages[" . $pageno . "]/ArtBox[1]"));
$urx = sprintf("%.2f", $p->pcos_get_number($doc, "pages[" . $pageno . "]/ArtBox[2]"));
$ury = sprintf("%.2f", $p->pcos_get_number($doc, "pages[" . $pageno . "]/ArtBox[3]"));
}