Guest User

Untitled

a guest
Jul 19th, 2018
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.70 KB | None | 0 0
  1. #!/usr/bin/perl
  2. # f2c-tab.pl
  3. # Gibt eine Umrechnungstabelle Fahrenheit->Celsius als Text auf der Standard-
  4. # ausgabe oder als PDF-Dokument aus
  5.  
  6. use strict;
  7. use PDF::API2;
  8.  
  9.  
  10. if (!(($#ARGV == 0 && $ARGV[0] == "--txt") || ($#ARGV == 1 && $ARGV[0] == "--pdf"))) {
  11. print "perl f2c-tab.pl OPTIONS [FILENAME]\n";
  12. print " OPTIONS\n";
  13. print " --txt plain text to stdout\n";
  14. print " --pdf pdf document to given FILENAME\n";
  15. exit;
  16. }
  17.  
  18.  
  19. sub f2c {
  20. return ($_[0] - 32) * 5 / 9;
  21. }
  22.  
  23. my $out = "";
  24.  
  25. for (my $i = 0; $i < 100; $i+=5) {
  26. my $c = $i; $out.=sprintf " %3d F = %5.1f C ", $c, f2c($c);
  27. my $c = $i + 100; $out.=sprintf " %3d F = %5.1f C ", $c, f2c($c);
  28. my $c = $i + 200; $out.=sprintf " %3d F = %5.1f C ", $c, f2c($c);
  29. my $c = $i + 300; $out.=sprintf " %3d F = %5.1f C ", $c, f2c($c);
  30. $out.="\n";
  31. }
  32.  
  33. if ($#ARGV == 1 && $ARGV[0] == "--pdf") {
  34. pdfOutput ($ARGV[1], "Umrechnungstabelle Fahrenheit --> Celsius", $out);
  35. } else {
  36. print $out;
  37. }
  38.  
  39. sub pdfOutput { my ($filename, $heading, $text) = @_;
  40. my $pdf = PDF::API2->new(-file => "$filename");
  41. $pdf->mediabox(595,842);
  42. my $page = $pdf->page;
  43. my $regular = $pdf->corefont('Courier',-encoding => 'latin1');
  44. my $bold = $pdf->corefont('Arial-Bold',-encoding => 'latin1');
  45.  
  46. my $line = $page->gfx;
  47. $line->strokecolor ("blue");
  48. $line->move (70,760);
  49. $line->line (525,760);
  50. $line->stroke;
  51.  
  52. my $txt = $page->text;
  53. $txt->textstart;
  54. $txt->font($bold, 20);
  55. $txt->translate(70,770);
  56. $txt->text($heading);
  57. $txt->font($regular, 11);
  58. my $startPos = 720;
  59. my @lines = split "\n", $text;
  60. while($_=shift @lines) {
  61. $txt->translate(60,$startPos); $startPos-=10;
  62. $txt->text($_);
  63. }
  64. $txt->textend;
  65. $pdf->save;
  66. $pdf->end( );
  67. }
Add Comment
Please, Sign In to add comment