Created
August 7, 2011 12:47
-
-
Save emasaka/1130347 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env perl | |
| use strict; | |
| use warnings; | |
| use feature qw(say); | |
| use Encode; | |
| use PDF::API2; | |
| my $pdf = PDF::API2->open($ARGV[0]) or die; | |
| for my $p (1 .. $pdf->pages) { | |
| my $page = $pdf->openpage($p); | |
| next unless $page->{Annots}; | |
| for my $a ($page->{Annots}->elementsof) { | |
| $a->realise; | |
| next unless $a->{Contents}; | |
| my $text = $a->{Contents}->val; | |
| eval { $text = decode('utf-16', $text); }; # error in ascii string | |
| $text =~ tr/\r/\n/; | |
| say encode('utf-8', $text) if $text; | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment