Copy link to clipboard
Copied
Does anyone know how to use FileAttachment property to attach a file in postscript please?
eg. to add document properties you would use:
[ /Title (Your Document Title Here)
/Author (Your Name Here)
/Subject (Your Subject Here)
/Keywords (any keywords you like)
/Creator (Adobe Pdf)
/Custom (Custom Contents)
/AndSoOn (And so on ...)
/AndSoForth (And so forth ...)
/DOCINFO pdfmark
Copy link to clipboard
Copied
I use pdfmarks in PostScript files to accomplish interactivity in the distilled PDF file, so I might be able to help if I understood your question better.
Please explain in more detail, what you want to accomplish.
Copy link to clipboard
Copied
Thanks for your reply. More infomation below:
I have a VBA tool that writes and adds .eps image files (containing PdfMark text) to Powerpoint 2003, so that when printed using a pdf printer such as Pdf995 or Pdfill (which print via a postscript process) they produce clickable interactive pdfs. So hyperlinks (LNK pdfmark), Java GoForward (ANN pdfmark) and Java GoBack (ANN pdfmark) work. I'm also adding Document Properties (DOCINFO pdfmark) and Bookmarks (OUT pdfmark).
If it's technically possible I'd link to add File attachments, such as other pdfs, excel files etc. to the final pdf. I've tried inserting an .eps file into powerpoint containing the code below which results in the error message:
"Adobe Reader could not open 'test.pdf' because it is either not a supported file type or because the file has been damaged (for example, it was sent as an email attachment and wasn't correctly decoded)."
%!PS-Adobe-3.0 EPSF-3.0
%%BoundingBox: 0 0 72 72
%%Creator: PDFMark
%%Title: AttachFILE PDFMark
%%BeginProlog
/pdfmark where
{pop} {userdict /pdfmark /cleartomark load put} ifelse
%%EndProlog
/F (c:test.pdf) def
[/_objdef {mstream} /type /stream /OBJ pdfmark
[{mstream} F /PUT pdfmark
[{mstream} << /Type /EmbeddedFile >> /PUT pdfmark
[/_objdef {mfs} /type /dict /OBJ pdfmark
[{mfs} << /Type /Filespec >> /PUT pdfmark
[{mfs} << /F (c:test.pdf) >> /PUT pdfmark
[{mfs} << /EF << /F {mstream} >> >> /PUT pdfmark
[ /Rect [ 216 503 361 612 ]
/Type /Annot
/Subtype /FileAttachment
/FS {mfs}
/ANN pdfmark
%%EOF
So I'm wondering if it is technically possible, or if there is something wrong with the PdfMark?
Thanks,
Steve
Copy link to clipboard
Copied
Try using the "Embedded File Content (EMBED) pdfmark method as described in the Adobe Acrobat 7.0.5 pdfmark Reference Manual beginning on page 37:
-----------------------------------------------------------
"
Embedded File Content (EMBED)
With Distiller 6.0, the pdfmark feature EMBED enables the embedding of file content into a PDF document. The syntax for this feature is:
[/Name (Unicode Name)
/FS << /Type /Filespec /F (name) /EF << /F {streamName} >> >>
EMBED pdfmark
Basic pdfmark Features
Building an Output Intents Array
2
38 pdfmark Reference Manual
This use of this feature embeds file content into a name tree within the EmbeddedFiles dictionary of the name dictionary (Names, a collection of name trees). This corresponds to the following structure as found in PDF documents:
<</Type /Catalog% The catalog dictionary
/Names% The name dictionary; see PDF 1.4, p. 92
<</EmbeddedFiles% One particular name tree; see p. 93, 101-102
<</Names% The name tree node; p. 102
[
(Unicode Name)% Unique Unicode string used for Acrobat access
<<% The file specification dictionary; p. 122
/F (name)% The file name for export
/EF << ... >>% Embedded file stream dictionary; p. 124
>>
]
>>
>>
>>
For example:
[/NamespacePush pdfmark
[/_objdef {fstream} /type /stream /OBJ pdfmark
[{fstream} << /Type /EmbeddedFile >> /PUT pdfmark
[{fstream} (Simulating file content here) /PUT pdfmark
[/Name (Unicode Unique Name)% e.g., <feff 0041 0073> is Unicode for “As”
/FS<<
/Type /Filespec
/F (myfile.txt)
/EF << /F {fstream} >>
>>
/EMBED pdfmark
[{fstream} /CLOSE pdfmark
[/NamespacePop pdfmark
"
--------------------------------------------
Copy link to clipboard
Copied
Thanks, although I got the following eps file to do almost what I wanted. It attaches a txt file at the moment containing the words "File content string".
I'm still struggling to work out how to read the file contents in from say another pdf or excel file. I thought using "(r) file" should work, but I get an error message when I try to insert the EPS file with this in it. Any ideas? Thanks again.
%!PS-Adobe-3.0 EPSF-3.0
%%BoundingBox: 0 0 10 10
%%Creator: PDFMark
%%Title: AttachFILE PDFMark
%%BeginProlog
/pdfmark where
{pop} {userdict /pdfmark /cleartomark load put} ifelse
%%EndProlog
/Content (File content string) def
[ /_objdef {MyStreamName} /type /stream /OBJ pdfmark
[ {MyStreamName} << /Type /EmbeddedFile>> /PUT pdfmark
[ {MyStreamName} Content /PUT pdfmark
[ /Rect [ 0 0 10 10] /Border [ 0 0 0 ]
/Color [ 0.98 0.99 0.75 ] /Name /PushPin
/FS <</F (testdocument.txt) /Type /FileSpec /EF << /F {MyStreamName} >> >>
/Subtype /FileAttachment /ANN pdfmark
[{MyStreamName}/CLOSE pdfmark
%%EOF
Copy link to clipboard
Copied
I used to use data file reading and writing functions within the PostScript interpreter, but now I just insert individual file streams into the PostScript job stream as part of my PostScript driver.
So the (r) file procedure must be preceded by a string defining the file path and name you want to read and the PostScript interpreter's file system has to be able to access it.
Copy link to clipboard
Copied
Yes thanks, I tried
/Content (c:\\test.pdf) (r) file def
and various other string combinations, but could not get the resultant EPS file inserted into my document 😞
I'd rather not embed the streams directly.
Wondering if using %%DocumentFiles: in the EPS might be a way forward?
Thanks
Copy link to clipboard
Copied
Your c:\\ nomenclature is not recognized by the PostScript interpreter and there is also the issue of 7bit versus 8bit encoding that must be considered with the PostScript file system if you want to "Attach" files that are not 7bit encoded (ie. Excel, Word, etc.).
Here is a PostScript language program that will generate a File Directory of what is available to your PostScript interpreter (Distiller, printer, etc.) and demonstrate the interpreter's directory nomenclature as well.
You need to rethink embedding the stream directly, I think.
%!PS-Adobe
/Courier findfont 5 scalefont setfont
/Buff 100 string def /Wipe 100 string def
/Rebuff {Buff 0 Wipe putinterval} def
/Dir {0 -5 rmoveto gsave Buff show Rebuff grestore
currentpoint 5 sub 35 lt{135 705 rmoveto currentpoint pop 576 ge{showpage title}if}if}def
/Title {36 750 moveto gsave (F I L E S D I R E C T O R Y ) show
400 0 rlineto .5 setlinewidth stroke grestore 0 -5 rmoveto} def
Title
/Courier findfont 5 scalefont setfont
systemdict begin
(*) {Dir} Buff filenameforall
end
showpage
Copy link to clipboard
Copied
More about encoding:
Probably Dov Isaacs could shorten your research and satisfy my curiosity by explaining what can and can't be done as far as "attaching"/"embedding" 8bit encoded files such as Excel spreadsheets in a PostScript program that is destined for Distiller.
Copy link to clipboard
Copied
Result! Embedding PS in Word Field Codes can produce a pdf with any file type attached, you just need to enable read/write access 🙂
Your code only listed files in the destination folder as viewable to the distiller. So I still could not figure out the directory structure, so I just put the file name in without directory path, and made sure the file was in the same location as I distilled to.
The resultant EPS file (seee below) would not embed in Word (probably a Microsoft bug/security), but I did manage to embeded the PS in Word using Field Codes.
On printing to pdf from a Ghostscript based pdf printer I got ERROR: invalidfileaccess OFFENDING COMMAND: file, which I worked out means file access is disabled.
*****
To enable file read/write access from the command line forGhostscript the switch is -dNOSAFER
For Acrodist it's -F (under Windows), -allowfileops (Unix), and for Mac AllowFileOps (under user preferences)
*****
So I printed the Word document to PS using a postscript printer driver, then ran Ghostscript ps2pdf with the -dNOSAFER option. The result was a pdf with the pdf file (or Excel file works fine too) attached.
*****
Any idea if it's possible to embed the command line switch into the PS code directly?
*****
Since Powerpoint does not have Field Codes, I hope to be able to get around my EPS embedding problem by installing an Office 97 EPS embedding file.
*****
My working EPS code (when the resd/write switch is used) is:
%!PS-Adobe-3.0 EPSF-3.0
%%BoundingBox: 0 0 10 10
%%Creator: PDFMark
%%Title: AttachFILE PDFMark
%%BeginProlog
/pdfmark where
{pop} {userdict /pdfmark /cleartomark load put} ifelse
%%EndProlog
/F (test.pdf) (r) file def
[ /_objdef {mstream} /type /stream /OBJ pdfmark
[ {mstream} F /PUT pdfmark
[ {mstream} << /Type /EmbeddedFile>> /PUT pdfmark
[ /Rect [ 0 0 10 10] /Border [ 0 0 0 ]
/Color [ 0.98 0.99 0.75 ] /Name /PushPin /FS <</F (foobar.pdf)
/Type /FileSpec /EF << /F {mstream} >> >>
/Subtype /FileAttachment /ANN pdfmark
%%EOF