<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0" xml:base="https://mg.to" xmlns:dc="https://purl.org/dc/elements/1.1/">
<channel>
 <title>mg.to - Ajax-style PDF part 1: fading highlight setup - Comments</title>
 <link>https://mg.to/2005/06/28/ajax-pdf-fading-highlight-setup</link>
 <description>Comments for &quot;Ajax-style PDF part 1: fading highlight setup&quot;</description>
 <language>en</language>
<item>
 <title>no AJAX?</title>
 <link>https://mg.to/2005/06/28/ajax-pdf-fading-highlight-setup#comment-6172</link>
 <description>&lt;p&gt;I thought by AJAX you meant we have some kind of asynchronous javascript request to some server, sending some data to a back-end server or retrieving some data from the back-end server.. 
Do you know a tutorial that could show us how to do some AJAX from inside a PDF page?&lt;/p&gt;</description>
 <pubDate>Thu, 21 Jan 2010 02:14:57 +0000</pubDate>
 <dc:creator>Yudhi</dc:creator>
 <guid isPermaLink="false">comment 6172 at https://mg.to</guid>
</item>
<item>
 <title>Michael - This part 1 is very interesting...</title>
 <link>https://mg.to/2005/06/28/ajax-pdf-fading-highlight-setup#comment-69</link>
 <description>&lt;p&gt;Michael - This part 1 is very interesting&amp;#8230; Is part 2 in the works? Will our hero be able to time the link hilites to the Flash piece, without having to alter the Flash source? Stay tuned sports fans&amp;#8230;&lt;/p&gt;</description>
 <pubDate>Sun, 21 Aug 2005 05:49:00 +0000</pubDate>
 <dc:creator>Jon Ashley</dc:creator>
 <guid isPermaLink="false">comment 69 at https://mg.to</guid>
</item>
<item>
 <title>Ajax-style PDF part 1: fading highlight setup</title>
 <link>https://mg.to/2005/06/28/ajax-pdf-fading-highlight-setup#comment-68</link>
 <description>&lt;p&gt;&lt;strong&gt;Ajax-style PDF part 1: fading highlight setup&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;[Source: mg.to - Michael Geary to Earth (and vice versa)] quoted: With our narrator in a Flash movie and the links being PDF buttons, is there a way to connect the two? We can write some JavaScript code in the PDF to fade a highlight on and off for a l&amp;#8230;&lt;/p&gt;</description>
 <pubDate>Mon, 01 Aug 2005 01:19:16 +0000</pubDate>
 <dc:creator>Graphic Design Blog</dc:creator>
 <guid isPermaLink="false">comment 68 at https://mg.to</guid>
</item>
<item>
 <title>Ajax-style PDF part 1: fading highlight setup</title>
 <link>https://mg.to/2005/06/28/ajax-pdf-fading-highlight-setup</link>
 <description>&lt;p&gt;If you haven&amp;#8217;t already seen it, take a look at &lt;a href=&quot;https://www.adobe.com/&quot;&gt;Adobe&amp;#8217;s&lt;/a&gt; &lt;a href=&quot;https://www.adobe.com/products/acrobat/pdfs/a7_tryme_gb.pdf&quot;&gt;walking talking PDF&lt;/a&gt; tour of &lt;a href=&quot;https://www.adobe.com/products/acrobatpro/main.html&quot;&gt;Acrobat 7.0&lt;/a&gt;. It&amp;#8217;s one of the most creative PDF files I&amp;#8217;ve ever seen. (Don&amp;#8217;t stop after the first few pages; there are some funny bits near the end.)&lt;/p&gt;

&lt;p&gt;&lt;img id=&quot;product-id-img&quot; src=&quot;https://www.adobe.com/products/acrobatpro/images/acrobatid.jpg&quot; alt=&quot;Adobe Acrobat Professional&quot; height=&quot;215&quot; width=&quot;350&quot; usemap=&quot;#acrobatid1566507&quot; border=&quot;0&quot;/&gt;
&lt;map name=&quot;acrobatid1566507&quot;&gt;
    &lt;area shape=&quot;rect&quot; coords=&quot;8,10,342,163&quot; href=&quot;https://www.adobe.com/products/acrobat/pdfs/a7_tryme_gb.pdf&quot; alt=&quot;&quot;&gt;
    &lt;/area&gt;&lt;area title=&quot;Get Adobe Reader&quot; shape=&quot;rect&quot; coords=&quot;119,198,277,210&quot; href=&quot;https://www.adobe.com/products/acrobat/readstep2.html&quot; alt=&quot;Get Adobe Reader&quot;&gt;
&lt;/area&gt;&lt;/map&gt;&lt;/p&gt;

&lt;p&gt;Obviously, a lot of work went into making this PDF, but the technical side of it is actually pretty simple. We can add some scripting magic to make it even better.&lt;/p&gt;

&lt;p&gt;Take page 11, where our narrator explains the links he&amp;#8217;s standing next to, pointing to each one as he describes it:&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;https://mg.to/images/a7tryme-p11-before.png&quot; /&gt;&lt;/p&gt;

&lt;p&gt;The links just sit there when he points at them. It would look good, and be a nice usability touch, if we could apply an &lt;a href=&quot;https://en.wikipedia.org/wiki/AJAX&quot;&gt;Ajax&lt;/a&gt;-style fading highlight to each link as he points to it:&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;https://mg.to/images/a7tryme-p11-hilite.png&quot; /&gt;&lt;/p&gt;

&lt;p&gt;First we need to find out how the existing page works. If you have Acrobat Professional, you can see it by using the &lt;strong&gt;Select Object&lt;/strong&gt; tool on the &lt;strong&gt;Advanced Editing&lt;/strong&gt; toolbar. That&amp;#8217;s a Flash movie on the right with the narrator in it. Right click it and open its &lt;strong&gt;Properties&lt;/strong&gt; to see the &lt;strong&gt;Page Enter&lt;/strong&gt; event and a .swf &lt;strong&gt;rendition&lt;/strong&gt; (Acrobat&amp;#8217;s term for a media clip and its associated settings):&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;https://mg.to/images/a7tryme-p11-rendition.png&quot; /&gt;&lt;/p&gt;

&lt;p&gt;Each page is like this, with a Flash movie embedded in the page that runs on the Page Enter event.&lt;/p&gt;

&lt;p&gt;The links on the left are (no surprise) PDF pushbutton form fields.&lt;/p&gt;

&lt;p&gt;With our narrator in a Flash movie and the links being PDF buttons, is there a way to connect the two? We can write some JavaScript code in the PDF to fade a highlight on and off for a link, but how do we trigger that code at the right time as the movie plays?&lt;/p&gt;

&lt;p&gt;Well, one thing at a time. It would be fun to just see the fading highlight in action, so we&amp;#8217;ll write that bit of code first and hook it up to a temporary button to test it. The code will use &lt;code&gt;doc.getField(name)&lt;/code&gt; to get a JavaScript &lt;code&gt;Field&lt;/code&gt; object, and then it can set the field&amp;#8217;s &lt;code&gt;fillColor&lt;/code&gt; property to change its background color. If we do that on a repeating fast timer we&amp;#8217;ll have the fading highlight effect.&lt;/p&gt;

&lt;p&gt;For a quick test before we write any code, we can right click one of the buttons and open its Properties to change its fill color manually:&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;https://mg.to/images/a7tryme-p11-badfill.png&quot; /&gt;&lt;/p&gt;

&lt;p&gt;Oops. That worked, but it didn&amp;#8217;t do what we want. We got the fill color but the icon and text went away. Let&amp;#8217;s Undo it and try something else. (And note that the fill color doesn&amp;#8217;t extend all the way to the right end of the field. That&amp;#8217;s because the Flash movie overlaps the field. Hopefully this won&amp;#8217;t cause any problem.)&lt;/p&gt;

&lt;p&gt;We can create a separate field that is a solid rectangle, and if we get the &lt;a href=&quot;https://en.wikipedia.org/wiki/Z-order&quot;&gt;Z-order&lt;/a&gt; right it should do what we want. A text field with no text in it will do the trick. Let&amp;#8217;s try it without worrying about the exact layout first:&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;https://mg.to/images/a7tryme-p11-textfill-1.png&quot; /&gt;&lt;/p&gt;

&lt;p&gt;I guess that&amp;#8217;s some kind of progress. Maybe changing the Z-order will fix it. The tool to change that is tucked away in Acrobat&amp;#8217;s &lt;strong&gt;Advanced&lt;/strong&gt;/&lt;strong&gt;Forms&lt;/strong&gt;/&lt;strong&gt;Fields&lt;/strong&gt;/&lt;strong&gt;Set&amp;nbsp;Tab&amp;nbsp;Order&lt;/strong&gt; menu command:&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;https://mg.to/images/a7tryme-p11-textfill-order.png&quot; /&gt;&lt;/p&gt;

&lt;p&gt;Now we can click on the fields in order to set their tab order (which is also their Z-order), and if we put the text field in the tab order before the button, we get the transparent background highlight we were looking for:&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;https://mg.to/images/a7tryme-p11-textfill-order2.png&quot; /&gt;&lt;/p&gt;

&lt;p&gt;Finally, we move and resize the text field and we have our field highlight, at least in static form. Here&amp;#8217;s the page after a &lt;strong&gt;Select All&lt;/strong&gt; (Ctrl+A) to show all the field rectangles:&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;https://mg.to/images/a7tryme-p11-selectall.png&quot; /&gt;&lt;/p&gt;

&lt;p&gt;Creating a separate text field for the highlight was a minor nuisance, but does have one benefit: we were able to fine tune the highlight position relative to the button icon and text:&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;https://mg.to/images/a7tryme-p11-closeup.png&quot; /&gt;&lt;/p&gt;

&lt;p&gt;The blue outline is the pushbutton field that we tried to work with originally. As you can see, the pushbutton field rectangle doesn&amp;#8217;t have consistent margins around the icon and text (and no margin on the left). With a separate text field&amp;#8212;the red outline&amp;#8212;we can adjust it so the highlight is positioned nicely:&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;https://mg.to/images/a7tryme-p11-hilite.png&quot; /&gt;&lt;/p&gt;

&lt;p&gt;Now that we have a highlighter field, we should be able to write some code to control it. While I was editing the field I changed its name from the default &lt;code&gt;Text1&lt;/code&gt; to &lt;code&gt;Hilite&lt;/code&gt;, so we should be able to use &lt;code&gt;getField&lt;/code&gt; and set its &lt;code&gt;fillColor&lt;/code&gt;. Let&amp;#8217;s try it in the JavaScript console first:&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;https://mg.to/images/a7tryme-p11-console1.png&quot; /&gt;&lt;/p&gt;

&lt;p&gt;Looks good! We got a reference to the field in the &lt;code&gt;hilite&lt;/code&gt; variable and looked at its current &lt;code&gt;fillColor&lt;/code&gt; property. Then we changed the &lt;code&gt;fillColor&lt;/code&gt; and the visible field changed as expected.&lt;/p&gt;

&lt;p&gt;The last statement in the JavaScript console (not yet executed in the screen shot) hides the field, so we can save the file and it looks normal. It doesn&amp;#8217;t matter that we left the field the wrong color; we&amp;#8217;ll take care of that in the code that makes it visible again. For now, it&amp;#8217;s time to save the file and take a break. In the next installment we&amp;#8217;ll write some code to create the fading highlight effect.&lt;/p&gt;

&lt;p&gt;p.s. Here&amp;#8217;s an Acrobat editing tip: Open the General tab of Acrobat&amp;#8217;s Preferences dialog and turn on the &lt;strong&gt;single-key accelerators&lt;/strong&gt;. Then you can use the H key for &amp;#8220;hand&amp;#8221; (normal) mode in Acrobat, R for the object selector, and so on. Hover the mouse over a toolbar button to see its shortcut key. It makes this kind of editing a lot easier where you switch tools so often.&lt;/p&gt;

&lt;p&gt;&lt;i&gt;Disclaimer:&lt;/i&gt; I work for Adobe, but this is my own summer vacation project, not any kind of offical Adobe code.&lt;/p&gt;
</description>
 <comments>https://mg.to/2005/06/28/ajax-pdf-fading-highlight-setup#comments</comments>
 <category domain="https://mg.to/topics/programming/acrobat">Acrobat</category>
 <category domain="https://mg.to/topics/programming/flash">Flash</category>
 <category domain="https://mg.to/topics/programming/javascript">JavaScript</category>
 <pubDate>Tue, 28 Jun 2005 15:54:09 +0000</pubDate>
 <dc:creator>Michael Geary</dc:creator>
 <guid isPermaLink="false">82 at https://mg.to</guid>
</item>
</channel>
</rss>
