use warnings; use strict; use IPC::System::Simple qw(system capture); use Test::More tests => 2; BEGIN { use Gscan2pdf::Document; use Gtk3 -init; # Could just call init separately use PDF::Builder; } ######################### Gscan2pdf::Translation::set_domain('gscan2pdf'); use Log::Log4perl qw(:easy); Log::Log4perl->easy_init($WARN); my $logger = Log::Log4perl::get_logger; Gscan2pdf::Document->setup($logger); # Create test image system( Gscan2pdf::Helpers::get_imagemagick_command(), 'label:The quick brown fox', qw(-alpha Off -depth 1 -colorspace Gray), '-family', 'DejaVu Sans', qw(-pointsize 12 -units PixelsPerInch -density 300), qw(-border 20x10 test.png) ); my $info = capture(qw(identify test.png)); my ( $width, $height ); if ( $info =~ /(\d+)x(\d+)/ ) { ( $width, $height ) = ( $1, $2 ) } my $slist = Gscan2pdf::Document->new; # dir for temporary files my $dir = File::Temp->newdir; $slist->set_dir($dir); my $hocr = <

The quick brown fox.

EOS $slist->import_files( paths => ['test.png'], finished_callback => sub { $slist->{data}[0][2]->import_hocr($hocr); $slist->save_pdf( path => 'test.pdf', list_of_pages => [ $slist->{data}[0][2]{uuid} ], options => { text_position => 'right' }, finished_callback => sub { $slist->import_files( paths => ['test.pdf'], finished_callback => sub { # Because we cannot reproduce the exact typeface used # in the original, we cannot expect to be able to # round-trip the text layer. Here, at least we can check # that we have scaled the page size correctly. like $slist->{data}[1][2]->export_hocr, qr/bbox\s0\s0\s$width\s$height/xsm, 'import text layer'; Gtk3->main_quit; } ); } ); } ); Gtk3->main; like( capture(qw(pdftotext test.pdf -)), qr/The\s*quick\s*brown\s*fox/, 'PDF with expected text' ); ######################### unlink 'test.png', 'test.pdf'; Gscan2pdf::Document->quit();