On Saturday 08 April 2006 03:34 pm, Steve Litt wrote:
> Hi all,
>
> Is there a way I can have something in my LyX file (maybe a comment
> environment or something), and have it occur in the PDF output without
> having it print or be viewable?
>
> If that's not possible, is there a way I can "brand" a PDF with a number
> somehow? I have pdftk.
>
> Thanks
>
> SteveT
Here's how it's done, assuming you want to tweak org.pdf so it includes
metadata MYKEY=MYVALUE in the output PDF, tweaked.pdf:
[EMAIL PROTECTED] ~]$ pdftk org.pdf dump_data output mymetadata.txt
[EMAIL PROTECTED] ~]$ echo InfoKey: MYKEY >> mymetadata.txt
[EMAIL PROTECTED] ~]$ echo InfoValue: MYVALUE >> mymetadata.txt
[EMAIL PROTECTED] ~]$ pdftk org.pdf update_info mymetadata.txt output
tweaked.pdf
You've now put metadata key MYKEY with value MYVALUE into tweaked.pdf. You can
quickly pull that data out with my check_pdf.sh script:
[EMAIL PROTECTED] ~]$ ./check_pdf.sh tweaked.pdf MYKEY
[EMAIL PROTECTED] ~]$
Here's the (bash script) code for check_pdf.sh, which I put in the public
domain and disclaim all warranty and liability:
#!/bin/bash
cat $1 | grep -a "$2" | sed -e "s/.*$2\s*//" | format_pdf_metadata_value.exe
format_pdf_metadata_value.exe simply grabs the value from the line containing
the key. It should work under Linux or Windows (or BSD, which I assume would
make it Mac compatible). Here is the C source code for
format_pdf_metadata_value.exe, which I put in the public domain and disclaim
all warranty and liability:
#include <stdio.h>
int main(int argc, char *argv[])
{
int ord = getc(stdin);
int count = 0;
/* GO TO OPENING PAREN */
for(; ord != '(' && count < 20; count++, ord=getc(stdin));
if(count >= 20) /* magic number, much bigger than needed */
{
fprintf(stderr, "Value not found\n");
return(1);
}
/* GO PAST OPENING PAREN */
for(; ord == '('; ord=getc(stdin));
/* BLOW OFF LEADING NONPRINTABLES */
for(;((ord < 0) || (ord > 127)); ord = getc(stdin));
/* PRINT UP TO BUT NOT INCLUDING CLOSING PAREN */
/* DO NOT PRINT ALL THE NULL BYTES */
for(; ord != ')'; ord = getc(stdin))
if(ord != 0)
putc(ord, stdout);
return 0;
}