Hi,

I have created a text to pdf converter. I would like to add a button which lets someone select a file rather than having to type the file name. Any ideas ?

Thank you very much, loztop.
#!/usr/bin/perl use Tk; use PDF::Create; use strict; use warnings; my $lab; my $address = "Enter file name"; my $window = MainWindow->new; $lab = $window->Label(-text => "Hello !")->pack; $window->Entry(-textvariable => \$address )->pack; $window->Button(-text => "Convert to pdf", -command => \&convert )->pa +ck; $window->Button(-text => "Quit", -command => \&finito )->pack; MainLoop; sub convert { my $height = 842; my $width = 595; my $result = index($address, '.'); my $a = substr($address, 0, $result); $a = $a.'.pdf'; my $pdf = new PDF::Create('filename' => $a ); my $root = $pdf->new_page('MediaBox' => [ 0, 0, $width, $height ]) +; # Add a page which inherits its attributes from $root my $page = $root->new_page; # Prepare font my $f1 = $pdf->font('Subtype' => 'Type1', 'Encoding' => 'WinAnsiEncoding', 'BaseFont' => 'Helvetica'); my $vert = $height -12; my $FilePath = "access.txt"; open(FILE, $address); while (my $line = <FILE>) { $page->string($f1, 10, 10,$vert, $line); $vert = $vert-12; if($vert<20){ $page = $root->new_page; $vert = $height -12; } } close FILE; $pdf->close; $lab -> configure(-text => "Congratulations $a has been created !" +); $address = "Convert another one !" } sub finito{ exit; }

In reply to Perl Gui File browser select files by loztop

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.