[pdftex] inverse operation to \pdffiledump
Akira Kakuto
kakuto at fuk.kindai.ac.jp
Wed Jan 6 13:55:19 CET 2010
Hi Alexander,
> I am looking for a way to embed binary files, such as png image files, as
> hex-encoded strings into the TeX source of a document and to restore them
> on the disk just before using them.
If you admit shell escape, the following is possible:
\newwrite\grfFile
\immediate\openout\grfFile=tmp.txt
\immediate\write\grfFile{%
89504E470D0A1A0A0000000D494844520000001800000012080300000076%
32EEAC00000060504C5445423212CA9A0AF1D21A986D06D4A00AA68008E1%
BB13DAD5CB6A5312AC8E107A6A3AEAEAE2DBB012EECA1A8A62029A7A0EA5%
9A7D948A64654A0EFEE29AFEFEF27262327A623AFEE222EEC20AE2E2DABA%
8202BA8E0AC6AA12FEF2F2FEDA1A00000079EDA0BB0000002074524E53FF%
FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF%
005C5C1BED00000001624B47441F050D10BD000000097048597300000048%
000000480046C96B3E00000009767041670000001A0000001200CF6BEC27%
000000CD4944415418D36D91EBB2C2200C8423D080353952DA9E4651FAFE%
6F69E8F4A2A33B933FFBCD125860560D3EB629B5D10FF32ED0B9C47026E6%
4713E2E51DF8F16A8ACA30DAD11FE0161E655A548CE470DBC0B33BAB0F53%
9DC278ED861940CF011FCCB481C908250FFD5D94C51AD84061B250C11DE0%
1F3F0042BF82C4EBEA65BD0251D27F033A29E96B622473005D9E5B10F567%
880D17D80280CEC6FDBA68565240C825BF3FB01136B0487DDB3D8F4A320A%
AB04C9354725B5444B8448E44E7FEF25D6DA93CDCE659B3E6BFFFD512FE7%
BE2090ECBAD6BE0000000049454E44AE426082%
}%
\immediate\closeout\grfFile
\immediate\write18{hex2bin tmp.txt tmp.png}
\pdfximage {tmp.png}\pdfrefximage\pdflastximage
\bye
where a source of hex2bin is
/*
* hex2bin
*/
#include <stdio.h>
#include <stdlib.h>
int tobin(int c)
{
int r;
if('0' <= c && '9' >= c)
r = c - '0';
if('A' <= c && 'F' >= c)
r = c - 'A' + 10;
return r;
}
int main(int argc, char *argv[])
{
FILE *fin, *fout;
int c1, c2, c;
fin = fopen(argv[1], "rb");
fout = fopen(argv[2], "wb");
while(1) {
c1 = getc(fin);
c2 = getc(fin);
if(c2 == EOF)
break;
c = tobin(c1) * 16 + tobin(c2);
fprintf(fout, "%c", c);
}
fclose(fin);
fclose(fout);
return 0;
}
More information about the pdftex
mailing list