AppleScript C Perl Shell Xcode Other

Merge checks into printable PDF file

Post Reply
coding / perl     Views: 497Prev .. Next
Merge checks into printable PDF filePosted: Sunday, March 25, 2018 [20:16:19] - 1
rootPosted by:rootMember Since:
June 16 2010
Posts: 357
When Apple came-up with new Pages on macOS Sierra where "Mail merge" option is no longer present that just proved the point of making checks database self-contained.

I merge monthly a small number of checks and print them on "Form 7000 (Standard Business 3-up)" checks for 10+ years at the time of this posting.
This program has very little limit on a number of check it can print, at least for a home business.
Also, checks printed by the program are with recipient name and address for a window envelopes.

This program is a simple addition to the checks database we are using:
View Code## This file is only a part of a program, thus no shebang, no chmod. It is called by: eval{require '/path_to_this_file/check.processing.cgi'};
$font_color='#000000';
$fonts_folder='/Library/Fonts';
$company_name='Your Company/Your Name';
$company_street='Your Street Address';$company_street =~ tr/a-z/A-Z/;
$company_city_state_zip='Your City, NY 11211';$company_city_state_zip =~ tr/a-z/A-Z/;
$company_phone = '+1(212)-555-3245';
$dollrsign='$';
$check_sides='C'; ## MICR FONTS CHARACTER
$pre_aba='A'; ## MICR FONTS CHARACTER
$past_account='B'; ## MICR FONTS CHARACTER
$checks_data_file='/path_to_your_data_file/data.txt';
$signature = '/path_to_your_signature_image/signature.jpg'; ## OPTIONAL
$checks_file='/path_to_where_your_check_is_saved/newcheck.pdf';
## Blank PDF template has the following dimentions:
## Width: 9.5 inchesHeight: 4.12 inches
$checks_template='/path_to_pdf_template/check.blank.pdf';
if(-f $checks_file) {unlink $checks_file;} ## REMOVE OLD CHECK PDF FILE
my @dirs = split(/\//,$checks_file);pop(@dirs);my $verdir = join '/',@dirs;@dirs=();
unless(-d $verdir) {`mkdir -p $verdir`;} ## CREATE DIRECTORY WHERE CHECK IS SAVED IF NOT PRESENT

unless(-f $checks_data_file) { ## THROW ERROR AND EXIT IF NO DATA FILE PRESENT
print "Content-type: text/html\n\nCan not process your request - source file is missing\n";exit(0);
} ## END CHECKS DATA FILE IS MISSING

## Make sure modules are installed on your computer
use PDF::API2;
use PDF::API2::Resource::Font::SynFont;

## Create actual PDF file
my $pdf = PDF::API2->new(-file => $checks_file);
@directories = PDF::API2::addFontDirs($fonts_folder); # tell your program where it should look for fonts
# Make sure all fonts are present on your system, otherwise program will fail
# If you do not have any of the fonts listed - do a Websearch for the file name
$font_micr = $pdf->ttfont('MICR013N.TTF');# MICR 013 BT - BOTTOM NUMBERS ON A CHECK
$font_vineta = $pdf->ttfont('VINETAN.TTF');# Vineta BT
$font_courier = $pdf->ttfont('Courier New Bold.ttf');# Courier New Bold
$font_times = $pdf->ttfont('Times New Roman Bold.ttf');# Times New Roman Bold
$font_arial = $pdf->ttfont('Arial.ttf');# Arial
$font_arial_b = $pdf->ttfont('Arial Bold.ttf');# Arial Bold
$font_ocr = $pdf->ttfont('OCRAN.TTF');# OCR-A BT
my $pdfread = PDF::API2->open($checks_template); ## Open your PDF template for copying.
## READ DATA FOR CHECKS
$d = `cat $checks_data_file`;@allnz = split(/\n/,$d);$d='';
foreach $l (@allnz) {$nol++;
if($nol == 1) {next;} ## Skip the header (was used for Excel)
#ABAAccNChknumLChkNumDateNameStreetCityStateZipMemoAmountAmountLNum_LetterBank1Bank2Bank3Void
($aba,$accn,$chknmb_bot,$chknmb,$date,$name,$street,$city,$state,$zip,\
$memo,$amount,$amount_bot,$am_letters,$bank_l1,$bank_l2,$bank_l3,$void) = split(/\t/,$l);
$pgnmb++;
$pdf->importpage ($pdfread, '1', $pgnmb);
$page = $pdf->openpage($pgnmb);$text = $page->text();
## All coordinates below may vary, they generally work as is.
## Checks printed by this program were successfully accepted by all banks we know.
$text->font($font_ocr, 12); ## OCR Font
$text->fillcolor($font_color);
$coord = 579 - (length($date) * 7.2);
$text->transform( -translate => [$coord, 216.7]);$text->text($date);## DATE486 - 493.4 = 7.4 per letter579 - starting point
$text->transform( -translate => [67.5, 185.8]);$text->text($name);## 185.8 - NAME & AMOUNT LINE HEIGHT
$text->transform( -translate => [449.1, 185.8]);$text->text($amount);## AMOUNT IN NUMBERS
$text->transform( -translate => [29, 160]);$text->text($am_letters);## AMOUNT IN LETTERS
if($void) {
$text->transform( -translate => [355, 135]);$text->text($void);## VOID DATE NOTICE PRINTED ON A CHECK
}
$text->transform( -translate => [58.6, 126.1]);$text->text($name);## NAME
$text->transform( -translate => [58.6, 112]);$text->text($street);## STREET ADDRESS
$text->transform( -translate => [58.6, 97.9]);$text->text("$city $state $zip");## CITY STATE ZIP
$text->font($font_arial, 14);$text->fillcolor($font_color); ## Arial font size 14
$text->transform( -translate => [551, 243]);$text->text($chknmb);## CHECK NUMBER
$text->font($font_arial, 8);$text->fillcolor($font_color);
$text->transform( -translate => [47, 184]);$text->text("PAY");## PAY
$text->font($font_arial_b, 12);$text->fillcolor($font_color);## Arial Bold font size 12
$text->transform( -translate => [431.3, 184.9]);$text->text($dollrsign);## DOLLAR SIGN
$text->font($font_arial, 9);$text->fillcolor($font_color);## Arial font size 9
$text->transform( -translate => [25, 75.3]);$text->text("MEMO: $memo");## MEMO
$text->font($font_vineta, 9);$text->fillcolor($font_color);## Vineta font size 9
$text->transform( -translate => [23, 247.8]);$text->text($company_name);## COMPANY NAME
$text->font($font_courier, 7);$text->fillcolor($font_color);## Courier font size 7
$text->transform( -translate => [23, 237.6]);$text->text($company_street);## COMPANY STREET ADDRESS
$text->transform( -translate => [23, 229.6]);$text->text($company_city_state_zip);## COMPANY CITY STATE ZIP
$text->transform( -translate => [23, 221.6]);$text->text($company_phone);## COMPANY PHONE
$text->font($font_times, 7);$text->fillcolor($font_color);## Times New Roman font size 7
$text->transform( -translate => [256.5, 249.7]);$text->text($bank_l1);## BANK NAME
$text->transform( -translate => [276, 241.5]);$text->text($bank_l2);## BANK LOCATION
$text->transform( -translate => [291.5, 233.5]);$text->text($bank_l3);## BANK BRANCH
$text->font($font_micr, 18);$text->fillcolor($font_color);## MICR font size 18, prints bank numbers
$text->transform( -translate => [105, 44.65]);$text->text($chknmb_bot);## CHECK NUMBER BOTTOM
$text->transform( -translate => [96, 44.65]);$text->text($check_sides);## CHECK SIDE LEFT
$text->transform( -translate => [177, 44.65]);$text->text($check_sides);## CHECK SIDE RIGHT
$text->transform( -translate => [201, 44.65]);$text->text($pre_aba);## PRE ABA
$text->transform( -translate => [291, 44.65]);$text->text($pre_aba);## PAST ABA
$text->transform( -translate => [210, 44.65]);$text->text($aba);## ABA
$text->transform( -translate => [309, 44.65]);$text->text($accn);## ACCOUNT NUMBER
$text->transform( -translate => [399, 44.65]);$text->text($past_account);## PASR NUMBER
my $gfx = $page->gfx();## Print the lines on a check
$gfx->strokecolor($font_color);
$gfx->move(67.5,182.3);$gfx->line(431,182.3);$gfx->stroke;
$gfx->move(449,182.3);$gfx->line(582.5,182.3);$gfx->stroke;
$gfx->move(380,213.1);$gfx->line(582.5,213.1);$gfx->stroke;
$gfx->move(23.2,153.5);$gfx->line(582.5,153.5);$gfx->stroke;
$gfx->move(58,73.6);$gfx->line(318,73.6);$gfx->stroke;
$gfx->move(355,73.6);$gfx->line(582.5,73.6);$gfx->stroke;
if(-f $signature) { ## If Signature file present - sign the check
my $image=$pdf->image_jpeg($signature);$gfx->image( $image, 355, 75, 171, 48 ); ## FOR JPEG IMAGE
#my $image=$pdf->image_png($signature);$gfx->image( $image, 355, 75, 171, 48 ); ## FOR PNG IMAGE
} ## END IF SIGNATURE IMAGE PRESENT
} ## FOREACH LINE END
$pdf->update();$pdf->end;## Close check PDF file
$pdfread->end;## CLose PDF template file

if($in{'delcrnt'}) { ## Delete data file if requested
if(-f $checks_data_file) {unlink $checks_data_file;}
} ## END IF DELETE SOURCE REQUESTED

## Print the result page by providing virables and calling sub routine to print it.
if($pgnmb > 1) {$chsss='s';}$title = "Download check$chsss file";
$mess = "<b>$title</b>\n<p><a href=\"/web_directory_where_PDF_file_saved/newcheck.pdf\">Download PDF file</a></p>";&error;


Program actually uses system True Type Fonts.
We bought MICR fonts for checks printing a long time ago when they weren't free. Do a Web Search for "MICR fonts" for more information.There's no place like ~
coding / perlPrev .. Next
 
Post Reply
Home - Coding: AppleScript C Perl Shell Xcode Other
Our Telegram Group