By default embedded (using an IFRAME) Youtube videos will be displayed as a black rectangle in the resulting PDF. To display the Youtube preview image you can use s simple JavaScript workaround (see script.txt). This script extracts the video ID from the URL and uses it to retrieve the preview image of the video. This image will be used as background image and the original URL will be removed. Finally the IFRAME will be enclosed by a link which points to the original video on Youtube.
The script can be used as follows in your PDFreactor integration:
Java
config.setAddLinks(true); config.setUserScripts(new Resource().setUri("URL/to/script.txt").setBeforeDocumentScripts(true));
C#
config.AddLinks = true; config.UserScripts = new List<Resource> { new Resource { Uri: "URL/to/script.txt", BeforeDocumentScripts: true } };
PHP
$config["addLinks"] = true; $config["userScripts"] = array( array( uri => "URL/to/script.txt", beforeDocumentScripts => true ) );
JavaScript
config.addLinks = true; config.userScripts = [{ uri: "URL/to/script.txt", beforeDocumentScripts: true }];
Python
config["addLinks"] = True config["userScripts"] = [{ "uri": "URL/to/script.txt", "beforeDocumentScripts": True }]
Ruby
config["addLinks"] = true config["userScripts"] = [{ uri: "URL/to/script.txt", beforeDocumentScripts: true }]
Perl
$config["addLinks"] = true; $config["userScripts"] = [{ "uri" => "URL/to/script.txt", "beforeDocumentScripts => true }];
CLI
--addLinks -j "URL/to/script.txt"
REST
{ "addLinks": true, "userScripts": [{ "uri": "URL/to/script.txt", "beforeDocumentScripts": true }]}
The beforeDocumentsScripts property should be set to true, as this decreases the conversion time.
Please note: This script will only work with YouTube videos which are embedded using an IFRAME.