embedding images using pdfmarks

  • Follow


Hello,

I am trying to embed a jpeg image into a PDF produced by distilling a
PS file. This image will be used for creating the appearance of a
push-button [widget annotation].

My question is, how do I get the binary data of a jpeg image into the
XObject's stream, using a pdfmark? The pdfmark standard [version 6,
Page 17] mentions two methods for adding content to a stream:

1. [ {streamname} string /PUT pdfmark--- Can the binary contents of
the image file be pushed through in a string? If yes, the content
might imbalance the delimiting parenthesis of the string. Will
escaping the parenthesis in the content with the backsslash '\'
characters work?

2. [ {streamname} file /PUT pdfmark---This file is supposed to be a PS
file object. Can somebody provide an example on using a PS file object
in this context?

-----------------------------------------------------------

Quoting the standard from the same page.... "The resultant PDF object
associated with the stream named object is always compressed
using a lossless method that can be specified in Acrobat Distiller's
Adobe PDF Settings dialog."

Can this encoding of the stream data be turned off [maybe by embedding
some params for distiller, in the PS file]?

----------------------------------------------------------

I'll greatly appreciate any help that gets me going in the right
direction. Thanks in advance...

Amit
0
Reply amit 9/28/2004 6:34:25 AM

Amit wrote:
> I am trying to embed a jpeg image into a PDF produced by distilling a
> PS file. This image will be used for creating the appearance of a
> push-button [widget annotation].

This is possible, but not for the faint of heart since it requires
mashing JPEG, PostScript, pdfmark, and PDF techniques.

> My question is, how do I get the binary data of a jpeg image into the
> XObject's stream, using a pdfmark? The pdfmark standard [version 6,
> Page 17] mentions two methods for adding content to a stream:

You can get the binary contents of a disk file into a stream. However, as
you note, Distiller will always apply Flate compression to the data
which defeats the idea of directly using JPEG image data. I am not
aware of any workaround for this behavior.

You _can_ do this, however, if you refrain from JPEG compression
and use raw image data instead. For the sake of completeness, here's
an idiom which you can use to construct an image object from
raw pixel data provided in a disk file:

[/_objdef {myImage} /type /stream /OBJ pdfmark
[ {myImage}
<<
	/Type /XObject
	/Subtype /Image
	/Width 745
	/Height 493
	/ColorSpace /DeviceRGB
	/BitsPerComponent 8
 >>
/PUT pdfmark
[ {myImage} (nesrin.raw) (r) file /PUT pdfmark

> I'll greatly appreciate any help that gets me going in the right
> direction. Thanks in advance...

As an alternative to fetching the image data from a disk file
you could embed the JPEG data directly in the PostScript stream.
My old jpeg2ps utility may come in handy here (available at
http://www.pdflib.com/products/more/jpeg2ps.html).

The basic trick is to place the image on the page and attach a
name to it via pdfmark. You can then refer to the image data
using this name, and construct the Form XObject which you need
as button icon. You'll have to get rid of the initial image on
the page, either by placing it outside the page, hiding it
behind a rectangle or a similar method.

The code below implements all this, assuming you wrapped the
JPEG data with appropriate PostScript data (using jpeg2ps).
There are many opportunities for enhancements, but you'll get
the basic idea.

Thomas

-----------------------------------------------------------------

%!PS

% attach a name to the next image
[ /_objdef {myImage} /NI pdfmark

save
/showpage {} def
0.1 0.1 scale
% now comes JPEG data, wrapped as EPS (created with jpeg2ps)

%!PS-Adobe-3.0 EPSF-3.0
%%Creator: jpeg2ps V1.9 by Thomas Merz
%%Title: nesrin.jpg
%%CreationDate: Tue Sep 28 10:45:16 2004
%%BoundingBox: 20 20 592 399
%%DocumentData: Clean7Bit
%%LanguageLevel: 2
%%EndComments
%%BeginProlog
%%EndProlog
%%Page: 1 1
/languagelevel where {pop languagelevel 2 lt}{true} ifelse {
   (JPEG file 'nesrin.jpg' needs PostScript Level 2!\n) dup print flush
   /Helvetica findfont 20 scalefont setfont 100 100 moveto show showpage stop
} if
save
/RawData currentfile /ASCII85Decode filter def
/Data RawData << >> /DCTDecode filter def
20 20 translate
572.00 378.52 scale
/DeviceRGB setcolorspace
{ << /ImageType 1
      /Width 745
      /Height 493
      /ImageMatrix [ 745 0 0 -493 0 493 ]
      /DataSource Data
      /BitsPerComponent 8
      /Decode [0 1 0 1 0 1]
   >> image
   Data closefile
   RawData flushfile
   showpage
   restore
} exec
s4IA0!"_al8O`[\!W`9l!([(is6UAP:hXchDf]T1E$-qh0E=(!8PK<Oz!-eJG!!!
....more JPEG image data...
]RVqe$GXrP`j@eEdFsS+PPZO8BRKL[QaRJ%C*Ls4I~>
%%EOF

restore

% construct a Form XObject which refers to the image
[/_objdef {myIcon} /type /stream /OBJ pdfmark
[ {myIcon}
<</Type /XObject
/Subtype /Form
/FormType 1
/Matrix [1 0 0 1 0 0]
/Resources << /XObject <</I0 {myImage} >> >>
/BBox [0 0 745 493]
/Filter /FlateDecode
 >>
/PUT pdfmark
[ {myIcon} (q 745 0 0 493 0 0 cm /I0 Do Q) /PUT pdfmark

% create the button
[ /T (myButton)
/Subtype /Widget
/FT /Btn
/Rect [ 100 400 500 700 ]
/F 4
/Ff 65540
/MK << /IF<</SW/A /S/P>>/TP 1>>
/AP << /N {myIcon} >>
/ANN pdfmark

showpage

_______________________________________________________________
Thomas Merz          tm@pdflib.com        http://www.pdflib.com
Personalize PDF: PDFlib Personalization Server and Block plugin
_______PDFlib - a library for generating PDF on the fly________

0
Reply Thomas 9/28/2004 11:09:52 AM


1 Replies
256 Views

(page loaded in 0.06 seconds)


Reply: