Merge checks into printable PDF file
Post ReplyMerge checks into printable PDF filePosted: Sunday, March 25, 2018 [20:16:19] - 1
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: $font_color='#000000'; $fonts_folder='/Library/Fonts'; $company_name='Your Company/Your Name'; $company_street='Your Street Address'; $company_city_state_zip='Your City, NY 11211'; $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 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); 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"; } ## 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'); $font_vineta = $pdf->ttfont('VINETAN.TTF'); $font_courier = $pdf->ttfont('Courier New Bold.ttf'); $font_times = $pdf->ttfont('Times New Roman Bold.ttf'); $font_arial = $pdf->ttfont('Arial.ttf'); $font_arial_b = $pdf->ttfont('Arial Bold.ttf'); $font_ocr = $pdf->ttfont('OCRAN.TTF'); my $pdfread = PDF::API2->open($checks_template); ## Open your PDF template for copying. ## READ DATA FOR CHECKS $d = `cat $checks_data_file`; foreach $l (@allnz) {$nol++; if($nol == 1) {next;} ## Skip the header (was used for Excel) #ABA ($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); ## 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->transform( -translate => [67.5, 185.8]); $text->transform( -translate => [449.1, 185.8]); $text->transform( -translate => [29, 160]); if($void) { $text->transform( -translate => [355, 135]); } $text->transform( -translate => [58.6, 126.1]); $text->transform( -translate => [58.6, 112]); $text->transform( -translate => [58.6, 97.9]); $text->font($font_arial, 14); $text->transform( -translate => [551, 243]); $text->font($font_arial, 8); $text->transform( -translate => [47, 184]); $text->font($font_arial_b, 12); $text->transform( -translate => [431.3, 184.9]); $text->font($font_arial, 9); $text->transform( -translate => [25, 75.3]); $text->font($font_vineta, 9); $text->transform( -translate => [23, 247.8]); $text->font($font_courier, 7); $text->transform( -translate => [23, 237.6]); $text->transform( -translate => [23, 229.6]); $text->transform( -translate => [23, 221.6]); $text->font($font_times, 7); $text->transform( -translate => [256.5, 249.7]); $text->transform( -translate => [276, 241.5]); $text->transform( -translate => [291.5, 233.5]); $text->font($font_micr, 18); $text->transform( -translate => [105, 44.65]); $text->transform( -translate => [96, 44.65]); $text->transform( -translate => [177, 44.65]); $text->transform( -translate => [201, 44.65]); $text->transform( -translate => [291, 44.65]); $text->transform( -translate => [210, 44.65]); $text->transform( -translate => [309, 44.65]); $text->transform( -translate => [399, 44.65]); my $gfx = $page->gfx(); $gfx->strokecolor($font_color); $gfx->move(67.5,182.3); $gfx->move(449,182.3); $gfx->move(380,213.1); $gfx->move(23.2,153.5); $gfx->move(58,73.6); $gfx->move(355,73.6); if(-f $signature) { ## If Signature file present - sign the check my $image=$pdf->image_jpeg($signature); # } ## END IF SIGNATURE IMAGE PRESENT } ## FOREACH LINE END $pdf->update(); $pdfread->end; 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';} $mess = "<b>$title</b>\n<p><a href=\"/web_directory_where_PDF_file_saved/newcheck.pdf\">Download PDF file</a></p>"; 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. |