CAM::P...Content(3pm)
β¨ NAME β¨
CAM::PDF::Content β it's the PDF page layout parser, bestie π like literally the thing that reads all the drawing commands for a single PDF page.
π LICENSE π
Same as CAM::PDF. That's it, that's the whole vibe.
πΈ SYNOPSIS πΈ
use CAM::PDF;
my $pdf = CAM::PDF->new($filename);
my $contentTree = $pdf->getPageContentTree(4);
$contentTree->validate() || die 'Syntax error';
print $contentTree->render('CAM::PDF::Renderer::Text');
$pdf->setPageContent(5, $contentTree->toString());
Okay so this is the whole glow-up in five lines and honestly? Iconic. π«Ά
π¦ DESCRIPTION π¦
This class is your girl for manipulating the layout commands of a single page of a PDF. The page content comes in as a scalar, and it gets parsed according to Adobe's PDF Reference 3rd edition (that's for PDF v1.4, no cap). Every single command from Appendix A of that document is parsed and understood β all of them, periodt. π
A lot of what this content object can do lives inside renderers that you apply to it. Go peek at the canonical renderer, CAM::PDF::GS, plus the render() method down below for the deets. β¨
π FUNCTIONS π
π $pkg->new($content)
π $pkg->new($content, $data)
π $pkg->new($content, $data, $verbose)
Parses a scalar CONTENT that holds your PDF page layout content. Hands you back a parsed-but-not-yet-validated data structure. So like, cute, but unverified. π
The DATA argument is a hash reference of contextual data that might be needed to work with the content. It's only needed for the toString() method (which needs doc => CAM::PDF object so it can deal with images) and for the render methods β the DATA reference gets passed to those verbatim, no edits. Check the individual renderer modules for what elements they require. π
The VERBOSE boolean says whether the parser should Carp when it runs into problems. Default is false. So by default it's gonna be quiet about it. π
π $self->parse($contentref)
This one is meant to be called by the new() method, it's not really a "you" method, iykyk. The argument should be a reference to the content scalar. It's passed by reference so it is never copied. Efficient queen. π
π $self->validate()
Returns a boolean telling you whether the parsed content tree actually conforms to the PDF specification. Vibe check on your syntax. β
π $self->render($rendererclass)
Traverses the content tree using the rendering class you specify. Wanna see renderer examples? Go look at CAM::PDF::GS or CAM::PDF::Renderer::Text. Renderers should typically derive from CAM::PDF::GS, but honestly it's not essential β do your own thing. Typically returns an instance of the renderer class. π
The rendering class gets loaded via require if it's not already in memory.
π $self->computeGS()
π $self->computeGS($skiptext)
Walks through the content tree and computes the coordinates of every graphic point along the way. If the $skiptext boolean is true (default: false) then text blocks get ignored to save time, because they don't change the global graphic state anyway. Skiiip. π§
This is a thin wrapper around render() with CAM::PDF::GS or CAM::PDF::GS::NoText picked as the rendering class.
π $self->findImages()
Traverses the content tree and accumulates embedded images and image references, following whatever the CAM::PDF::Renderer::Images renderer says. πΈ
π $self->traverse($rendererclass)
This recursive method is typically only called by wrapper methods, like render(). It instantiates renderers as needed and calls methods on them. It's the behind-the-scenes main character. π
π $self->toString()
Flattens a content tree back into a scalar, ready to be shoved right back into a PDF document. Heads up though: since whitespace gets discarded by the parser, the scalar you get back will not be identical to the original. Same energy, different spacing. π
π AUTHOR π
See CAM::PDF.
That's the whole page, bestie β brought to you by perl v5.36.0, dated 2022-12-08, from the CAM::P...Content(3pm) era of the manual pages. Go parse something gorgeous. π¦β¨
π¦ where this page comes from
- debian bookworm: libcam-pdf-perl 1.60-5 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- debian trixie: libcam-pdf-perl 1.60-5 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu noble: libcam-pdf-perl 1.60-5 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu resolute: libcam-pdf-perl 1.60-5 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu stonking: libcam-pdf-perl 1.60-5 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms