开发者

Can a text file have an image?

The existing functionality is we write data to the text file in the below way.

var 
outfile : Textfile;
begin
  assignfile(outfile,apath);
  Rewrite(Outfile);
  writeln(outfile,'sample');
end;

We have the logic to align the contents in the text file and then load the text file into a report viewer, where the user will be able to print the text file as a printout or PDF.

The requ开发者_StackOverflowirement is that we have 1D and 2D bar code images that need to be printed as part of this text file. Is there any way that I can paste the bar code images in the text file? I tried converting the image in to stream and then again saving the stream in the textfile but it returns me junk data (not image). Is there any other option?


The Motif/X UIL specification includes a way to encode an "ICON" into ASCII files in a more-or-less human-readable way.

There's the old X Bitmap format (XBM), which should do what you want (since barcodes are monochrome). XBM files are essentially C #includes.

Those would all require special readers though. If the "text" file itself has to be directly scannable, you either need to find a way to do it with ASCII Art, or you aren't talking text file anymore.

Hmmm. Another possibility that strikes me is that you could try to embed postscript commands to generate the barcodes on the printer into your text file. You'd have to trick your printer into accepting and executing them from a supposed "text" file though. You up to hacking your printer? :-)


A text file is a text file. By definition it can not have a representation of an image bitmap.

You could "persist" image data into a text file e.g. by first Base64 encoding it. You can later decode that data when you read from the file, in order to retrieve your image. For all practical purposes this is still a very strange approach to image file storage.

If - specifically - you are required to output UPC Barcodes, then you could perhaps solve this by writing the codes as ASCII patterns:

 ███  █ ███   █ █ █ ██ ██ █ █ █  ██ █ █ ███ █
 ███  █ ███   █ █ █ ██ ██ █ █ █  ██ █ █ ███ █
 ███  █ ███   █ █ █ ██ ██ █ █ █  ██ █ █ ███ █
 ███  █ ███   █ █ █ ██ ██ █ █ █  ██ █ █ ███ █
 ███  █ ███   █ █ █ ██ ██ █ █ █  ██ █ █ ███ █
 ███  █ ███   █ █ █ ██ ██ █ █ █  ██ █ █ ███ █
 ███  █ ███   █ █ █ ██ ██ █ █ █  ██ █ █ ███ █
 ███  █ ███   █ █ █ ██ ██ █ █ █  ██ █ █ ███ █
 ███  █ ███   █ █ █ ██ ██ █ █ █  ██ █ █ ███ █
 ███  █ ███   █ █ █ ██ ██ █ █ █  ██ █ █ ███ █
 ███  █ ███   █ █ █ ██ ██ █ █ █  ██ █ █ ███ █
 ███  █ ███   █ █ █ ██ ██ █ █ █  ██ █ █ ███ █
 ███  M E A N I N G L E S S █ █ U P C █ ███ █

Since you are bringing the file into a report viewer (for which I assume you will be writing some code), then you probably don't need the visual data in the text file at all.

All you need to keep in the text file would be

  1. The type of Barcode regime to be used
  2. The underlying alphanumeric information which is supposed to be represented in the code

When you load the file in the viewer you could render a visual barcode using a Barcode Generator


Generally, text files can only contain text. You may need to consider using a file type that can support images, e.g. Word, HTML, OpenDocument etc.


The requirement is that we have 1D and 2D bar code images that need to be printed as part of this text file. Is there any way that I can paste the bar code images in the text file?

NO. When in doubt, try finding an other application out there that deals with text files, see if you can include graphics in it. Try pasting a image into the following applications, they're all text editors:

  • Notepad
  • Your Delphi IDE
  • Notepad++
  • Any of the text editors here: http://en.wikipedia.org/wiki/List_of_text_editors

You'll find none of them is able to place a image into a text file.

What can you do

First of all you need to understand it can't be done with TEXT files. You'll then be able to look for alternatives. There are many formats capable of holding both Text and Graphics. The easiest will probably be the PDF file, because you surely have an Report Generator bundled with your Delphi version it's likely capable of saving stuff as PDF. You may also look at many other things:

  • RTF files, but the encoding is very ugly. You'll probably rely on a Report Generator to generate this.
  • PS files.
  • TIFF or JPEG files (image files; Images can obviously encode images).


Your question is still a little vague, but it's better than the one that was closed yesterday.

I'm assuming that you want the barcode in a file so that it can be printed and then scanned. There's absolutely no point of having a barcode if it is not going to be scanned. I'm also assuming that a text file is something that will be printed as text, e.g. by Notepad.

With these assumptions then the answer to your question is that a scannable barcode cannot be stored in a text file.

You have a number of options to solve your problem:

  • Create a PDF and print that. There are many 3rd party tools for PDF creation.
  • Use Office automation (very heavy duty and somewhat brittle solution). But very quick to implement - only a few lines of code.
  • Print to the printer directly using GDI commands.


The short answer to the question is NO. But there may be ways to meet your requirements... It depends on the capability of your report viewer. Does it understand PDF? PCL? RAVE? If so, leverage that. If you look at a PCL file, for example, you'll find that it's really text with some PCL command sequences. You could make a PCL file that contains basic header information (maybe just ESC+Reset at the top), then your text, and then some fancy PCL for your image. That's what I'd look into, if I was using a report viewer that understood PCL.


They have these cool text files now, that have the extension .html that are often viewed by things called web browsers.

They use them on this cool thing that they call The Internet.

Inside the HTML files they have something really cool, called an Image tag.

I have been assured by some people braver than me, that it is even possible to print out such a file, with its cool graphics, and images, and fonts.

You could also look into a really great product called Fast Reports. It makes printing a lot more easy, and a lot more functional, than you would get in a text-based printing system. Fast Reports even has bar-code features, which is something you're looking for.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜