swftools icon indicating copy to clipboard operation
swftools copied to clipboard

PDF2SWF export does preserve alpha in swf

Open Pullusb opened this issue 2 years ago • 2 comments

Hi,

Exporting a multipage pdf to an animated swf works great. Using a command like: pdf2swf -s framerate=25 multi_page.pdf -o animated.swf

But the alpha is not preserved. When imported in After Effects, the white background is covering layers below. I looked at all available command flags in pdf2swf and I don't see any that will set background as transparent, it would be great to have one !

Here is a sample pdf multipage file with an animated shape: multi_page.pdf

Opening the pdf in inkscape, there is no white background shape object in there, it's just the canvas (the only existing shape is the animated one at bottom left).

Found this in the FAQ:

18.) How can I create transparent SWFs from PDFs? Run pdf2swf as usual, and then, on the resulting file, execute: swfextract -i 3- file.swf -o file.swf

But this does not work on the file, and it output only a fixed image instead of the initial animation (tested with and without -P as suggested by CLI warning) Maybe I'm missing something ?

Any help appreciated. Thank you for making this software.

Pullusb avatar Jul 18 '23 10:07 Pullusb

Don't know if it's best to tag someone. So I'll try with the author @matthiaskramm :smiley:

I just want to know if I'm not doing things right before looking at ways to clear the background on produced swf post-export with other tools out there. Cheers.

Pullusb avatar Jul 19 '23 09:07 Pullusb

Many thanks for your report, @Pullusb.

Let me tag your issue as question first.

As far as I know, PDF documents don't have totally transparent backgrounds (they don’t have any background, only the page dimensions).

In SWF, the SetBackgroundColor tag sets the background color for the animation (only a opaque value may be set, since only RGB values are allowed).

https://www.m2osw.com/swf_tag_setbackgroundcolor includes a trick for a fully transparent background:

To create a Flash animation that's transparent (so we can see the website gradient, for example) you use the wmode parameter in the HTML tag with the value "transparent", in which case the background color will be ignored and replaced by a fully transparent background. For example:

<embed width="440" height="241" type="application/x-shockwave-flash"
 pluginspage="http://www.macromedia.com/go/getflashplayer"
 src="/sites/linux.m2osw.com/files/images/indoor-comfort.swf"
 play="true" loop="true" menu="true" wmode="transparent"></embed>

There is no parameter you can set inside the Flash animation itself to make it transparent in your browser.

As for pdf2swf -i 3- -P file.swf -o file.swf seems to remove object 3 (which contains SetBackgroundColor tag).

It is only (an uneducated) guess, but the trick of removing the SetBackgroundColor may only work with static SWFs.

I think <embed wmode="transparent"> may work with your animation.

Sorry if I missed something from your explanation. Let me know if this was the case.

ousia avatar May 19 '24 12:05 ousia