Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p><a href="http://search.cpan.org/dist/CAM-PDF/" rel="nofollow noreferrer">CAM::PDF</a> can do the geometry part quite nicely, but has some trouble with the string matching sometimes. The technique would be something like the following lightly-tested code:</p> <pre><code>use CAM::PDF; my $pdf = CAM::PDF-&gt;new('my.pdf') or die $CAM::PDF::errstr; for my $pagenum (1 .. $pdf-&gt;numPages) { my $pagetree = $pdf-&gt;getPageContentTree($pagenum) or die; my @text = $pagetree-&gt;traverse('MyRenderer')-&gt;getTextBlocks; for my $textblock (@text) { print "text '$textblock-&gt;{str}' at ", "($textblock-&gt;{left},$textblock-&gt;{bottom})\n"; } } package MyRenderer; use base 'CAM::PDF::GS'; sub new { my ($pkg, @args) = @_; my $self = $pkg-&gt;SUPER::new(@args); $self-&gt;{refs}-&gt;{text} = []; return $self; } sub getTextBlocks { my ($self) = @_; return @{$self-&gt;{refs}-&gt;{text}}; } sub renderText { my ($self, $string, $width) = @_; my ($x, $y) = $self-&gt;textToDevice(0,0); push @{$self-&gt;{refs}-&gt;{text}}, { str =&gt; $string, left =&gt; $x, bottom =&gt; $y, right =&gt; $x + $width, #top =&gt; $y + ???, }; return; } </code></pre> <p>where the output looks something like this:</p> <pre><code>text 'E' at (52.08,704.16) text 'm' at (73.62096,704.16) text 'p' at (113.58936,704.16) text 'lo' at (140.49648,704.16) text 'y' at (181.19904,704.16) text 'e' at (204.43584,704.16) text 'e' at (230.93808,704.16) text ' N' at (257.44032,704.16) text 'a' at (294.6504,704.16) text 'm' at (320.772,704.16) text 'e' at (360.7416,704.16) text 'Employee Name' at (56.4,124.56) text 'Employee Title' at (56.4,114.24) text 'Company Name' at (56.4,103.92) </code></pre> <p>As you can see from that output, the string matching will be a little tedious, but the geometry is straightforward (except maybe for the font height).</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload