I have a unique problem where I have to use only HTML because of platform constraints to send out receipt emails.
The receipts need to have a CODE128 Barcode generated on them. Unfortunately because I can only use HTML in the email template I am looking to figure out how to create these barcodes and link them with an IMG tag.
So my current idea is to use the PDFCrowd php library on a different server and then create an IMG tag in the email template with the SRC being a GET Request URL to the other server with the php library on it.
Then I would generate html with inline css and convert that to an image and stream it back out.
Would the HTML Email Template IMG tag work with that type of URL Setup!?
...This is for a quick and dirty shopify solution.
<?php
require 'pdfcrowd.php';
try
{
// create the API client instance
$client = new \Pdfcrowd\HtmlToImageClient("username", "apikey");
// configure the conversion
$client->setOutputFormat("png");
// create output file for conversion result
$output_file = fopen("HelloWorld.png", "wb");
// run the conversion and store the result into an image variable
$image = $client->convertString("<html><body><h1>Hello World!</h1></body></html>");
// write the image the into the output file
fwrite($output_file, $image);
// close the output file
fclose($output_file);
}
catch(\Pdfcrowd\Error $why)
{
// report the error to the standard error stream
fwrite(STDERR, "Pdfcrowd Error: {$why}\n");
}
?>
You can use a barcode generator that can be found on github here. I remember being in a similar need sometime back, downloaded the barcode generator and it got the job done.
Example 1:
Parameters:
HTML Source Code:
<img alt="testing" src="/code/barcode.php" />
Result:
Example 2:
Parameters:
HTML Source Code:
<img alt="testing" src="/code/barcode.php?text=testing&print=true" />
Result:
Example 3:
Parameters:
HTML Source Code:
<img alt="TESTING" src="/code/barcode.php?codetype=Code39&size=40&text=TESTING&print=true" />
Result:
More examples in the source link.