PhantomJS won't send to stdout - phantomjs

I have the following script that I'm trying to run with PhantomJS v 1.9.8.
var page = require('webpage').create();
page.content =
"<!DOCTYPE html>" +
"<html> " +
" <head></head> " +
" <body> " +
" <h1>Test</h1> " +
" </body> " +
"</html>";
page.onLoadFinished = function(status) {
//page.render('C:\\PDFTemp\\test.pdf', { format: 'pdf' }); // <-- Works
page.render('/dev/stdout', { format: 'pdf' }); // <- Gives me 0 bytes
phantom.exit();
};
When I run the page.render to write as a file, it works perfectly. However, rendering to stdout gives me nothing.
Note: I'm running version 1.9.8. Version 2.0 doesn't like to play nice with ASP.Net, but 1.9.8 works great.
What am I doing wrong here?

Related

Trying to print pdf through iframe in firefox

Trying to print PDF through iframe
WebDriverWait wait_iframe = new WebDriverWait(driver, 20000);
wait_iframe.until(ExpectedConditions.visibilityOfElementLocated((By.id("printpdf"))));
Expected result is bill pdf print should be visible on the screen, but actual output it is throwing an error message i.e Error: Permission denied to access property "print"
Browser code:
var urlBase = url + '?title=' + escape(data.url);
var iframe = '<iframe id="printpdf" src="' + urlBase + '" frameborder="0" width="100%" height="100%"></iframe>';
$("#loadPdf").empty().html(iframe);
$('#printpdf').on("load", function() {
printPDF();
});
function printPDF() {
var frame = document.getElementById("printpdf");
frame.focus();
frame.contentWindow.print();
}

Acrobat DC preflight processes non-PDF files

I want to process and verify that PDFs within a folder are valid PDF/A files. The problem is that I need to process a folder with piles of files including word and excel among others that preflight converts to PDFs, processes, and then hangs for user input to discard the temperary file. There are some hundred files, so waiting for user input isn't doable.
Perhaps I'm not using the correct phrases when I search, but I can't find out how to force Adobe Acrobat DC to only process PDF files. I've found that in Acrobat X you can specify source files https://www.evermap.com/ActionWizardX.asp, but I've not found an equivalent in DC.
Is there a way to force an action to only process PDF files?
Edit:
Following #Joel Geraci's suggestion and finding this post, I've created the following script that runs in an action. At this point, It seems to run the profile, but I don't know if it actually modifies the document, since the call to this.closeDoc() doesn't prompt to save the document, and the resulting document doesn't seem to be saved as a PDF/A file.
/* Convert PDF/A-3a */
try
{
if(this.path.split('.').pop() === 'pdf')
{
var oProfile = Preflight.getProfileByName("Convert to PDF/A-3a");
if( oProfile != undefined )
{
var myPreflightResult = this.preflight( oProfile);
console.println( "Preflight found " + myPreflightResult.numErrors + " Errors.");
console.println( "Preflight found " + myPreflightResult.numWarnings + " Warnings.");
console.println( "Preflight found " + myPreflightResult.numInfos + " Infos.");
console.println( "Preflight fixed " + myPreflightResult.numFixed + " Errors.");
console.println( "Preflight not fixed " + myPreflightResult.numNotFixed + " Errors.");
this.closeDoc();
}
}
}
catch(theError)
{
$error = theError;
this.closeDoc( {bNoSave : true} );
}
Edit 2:
I ended up settling on using the saveAs function. I'm not sure how to export the XML data to a file, but this seems to be sufficient.
/* Convert PDF/A-3a */
try
{
if(this.path.split('.').pop() === 'pdf')
{
var oThermometer = app.thermometer;
var oProfile = Preflight.getProfileByName("Convert to PDF/A-3a");
if( oProfile != undefined )
{
var myPreflightResult = this.preflight( oProfile, false, oThermometer );
console.println( "Preflight found " + myPreflightResult.numErrors + " Errors.");
console.println( "Preflight found " + myPreflightResult.numWarnings + " Warnings.");
console.println( "Preflight found " + myPreflightResult.numInfos + " Infos.");
console.println( "Preflight fixed " + myPreflightResult.numFixed + " Errors.");
console.println( "Preflight not fixed " + myPreflightResult.numNotFixed + " Errors.");
if(myPreflightResult.numErrors > 0) {
var cXMLData = myPreflightResult.report(oThermometer);
console.println(cXMLData);
}
this.saveAs(path,"com.callas.preflight.pdfa");
}
}
}
catch(theError)
{
$error = theError;
this.closeDoc( {bNoSave : true} );
}
Edit 3:
So the problem is that non-PDF files are converted and read before my JavaScript is executed, which means that the this.path.split('.').pop() === 'pdf' doesn't actually filter out anything. I found that the requiresFullSave property of the Doc class specifies whether the document is a temp file or not. I have, however, found that I am still asked if I want to save the temp file, which doesn't help.
Edit 4
Calling Doc.closeDoc(true) on a temporary file causes Acrobat to crash and there doesn't seem to be another way to close a document without saving. I've found there is no clear way (that I've found) to close a temp document without prompting the user to save and have resorted to deleting all non-PDF files.
Final script:
/* Convert PDF/A-3a */
try
{
console.println(path + " is temp: " + requiresFullSave);
if(!requiresFullSave)
{
var oThermometer = app.thermometer;
var oProfile = Preflight.getProfileByName("Convert to PDF/A-3a");
if( oProfile != undefined )
{
var myPreflightResult = this.preflight( oProfile, false, oThermometer );
console.println( "Preflight found " + myPreflightResult.numErrors + " Errors.");
console.println( "Preflight found " + myPreflightResult.numWarnings + " Warnings.");
console.println( "Preflight found " + myPreflightResult.numInfos + " Infos.");
console.println( "Preflight fixed " + myPreflightResult.numFixed + " Errors.");
console.println( "Preflight not fixed " + myPreflightResult.numNotFixed + " Errors.");
if(myPreflightResult.numErrors > 0) {
var cXMLData = myPreflightResult.report(oThermometer);
console.println(cXMLData);
}
this.saveAs(path,"com.callas.preflight.pdfa");
}
}
else{
// As noted in the documentation found [here][2]
// Note:If the document is temporary or newly created, setting dirty to false has no effect. That is, the user is still asked to save changes before closing the document. See requiresFullSave.
// this.dirty = false;
// this.closeDoc(true);
}
}
catch(theError)
{
}
Rather than creating an action that runs preflight, try creating an action that runs some JavaScript. The JavaScript would test for the file extension of the file being processed and then execute preflight via JavaScript if it's a PDF, skipping it if not.

Is there a working sample of the Google custom search rest API?

I need to create a screen which automates Google search.
I know JavaScript and I'm trying to get GSE works.
I have a search engine and an API key.
The problem is Google's documentation is cyclic i.e. pages point to each other.
There is no working sample from where I can start my research.
Please help if you know of a working sample.
The documents I have read are:
cselement-devguide
introduction
I know this is an old question, but here is what I did to make the API results formatted like the Google Site Search used to give since they are ending the paid accounts and will have ads now. The API way has an option to pay still for over 100 searches per day, so going with that but had to format the results still, and used the existing one to build the css to do similar styling also.
Search form going to this page is just a simple:
<form action="search-results.htm" id="cse-search-box">
<div>
<input class="" name="q" type="text">
<input class="" type="submit">
</div>
</form>
and then the search results page:
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<title>JSON/Atom Custom Search API Example</title>
<!--<link href="default.css" rel="stylesheet" type="text/css">-->
<link href="google.css" rel="stylesheet" type="text/css">
</head>
<body>
<div class="gsc-result-info" id="resInfo-0"></div>
<hr/>
<div id="googleContent"></div>
<script>
//Handler for response from google.
function hndlr(response) {
if (response.items == null) {
//Sometimes there is a strange thing with the results where it says there are 34 results/4 pages, but when you click through to 3 then there is only 30, so page 4 is invalid now.
//So if we get to the invalid one, send them back a page.
window.location.replace("searchresults.htm?start=" + (start - 10) + "&q=" + query);
return;
}
//Search results load time
document.getElementById("resInfo-0").innerHTML = "About " + response.searchInformation.formattedTotalResults + " results (" + response.searchInformation.formattedSearchTime + " seconds)";
//Clear the div first, CMS is inserting a space for some reason.
document.getElementById("googleContent").innerHTML = "";
//Loop through each item in search results
for (var i = 0; i < response.items.length; i++) {
var item = response.items[i];
var content = "";
content += "<div class='gs-webResult gs-result'>" +
"<table class='gsc-table-result'><tbody><tr>";
//Thumbnail image
if (item.pagemap.cse_thumbnail != null)
content += "<td class='gsc-table-cell-thumbnail gsc-thumbnail'><div class='gs-image-box gs-web-image-box gs-web-image-box-portrait'><a class='gs-image' href='" + item.link + "'>" +
"<img class='gs-image' class = 'gs-image-box gs-web-image-box gs-web-image-box-portrait' src='" + item.pagemap.cse_thumbnail[0].src + "'></a></td>";
//Link
content += "<td><a class='gs-title' href='" + item.link + "'>" + item.htmlTitle + "</a><br/>";
//File format for PDF, etc.
if (item.fileFormat != null)
content += "<div class='gs-fileFormat'><span class='gs-fileFormat'>File Format: </span><span class='gs-fileFormatType'>" + item.fileFormat + "</span></div>";
//description text and URL text.
content += item.htmlSnippet.replace('<br>','') + "<br/><div class='gs-bidi-start-align gs-visibleUrl gs-visibleUrl-long' dir='ltr' style='word-break:break-all;'>" + item.htmlFormattedUrl +"</div>" +
"<br/></td></tr></tbody></table></div>";
document.getElementById("googleContent").innerHTML += content;
}
//Page Controls
var totalPages = Math.ceil(response.searchInformation.totalResults / 10);
console.log(totalPages);
var currentPage = Math.floor(start / 10 + 1);
console.log(currentPage);
var pageControls = "<div class='gsc-results'><div class='gsc-cursor-box gs-bidi-start-align' dir='ltr'><div class='gsc-cursor'>";
//Page change controls, 10 max.
for (var x = 1; x <= totalPages && x<=10; x++) {
pageControls += "<div class='gsc-cursor-page";
if (x === currentPage)
pageControls += " gsc-cursor-current-page";
var pageLinkStart = x * 10 - 9;
pageControls+="'><a href='search-results.htm?start="+pageLinkStart+"&q="+query+"'>"+x+"</a></div>";
}
pageControls += "</div></div></div>";
document.getElementById("googleContent").innerHTML += pageControls;
}
//Get search text from query string.
var query = document.URL.substr(document.URL.indexOf("q=") + 2);
var start = document.URL.substr(document.URL.indexOf("start=") + 6, 2);
if (start === "1&" || document.URL.indexOf("start=") === -1)
start = 1;
//Load the script src dynamically to load script with query to call.
// DOM: Create the script element
var jsElm = document.createElement("script");
// set the type attribute
jsElm.type = "application/javascript";
// make the script element load file
jsElm.src = "https://www.googleapis.com/customsearch/v1?key=yourApikeyhere&cx=yoursearchengineidhere&start="+start+"&q=" +query +"&callback=hndlr";
// finally insert the element to the body element in order to load the script
document.body.appendChild(jsElm);
</script>
</body>
</html>

Alert does not stay open

When I execute an alert, the alert shows and disappears too quickly. I want it to stay open. What is problem?
After I submit form:
newAlert('success', 'saved');
function newAlert(type, message) {
$('#alert-area').append($("<div class='alert " + type + "'><p> "
+ message + "
</p></div>"));
}
<div id="alert-area"></div>
Im not good at jquery, so I try your question with js, its ok. The "alert-area" div did not disappear. This is my code :
<html>
<head></head>
<body>
<div id="alert-area"></div>
<script type="text/javascript">
window.onload = newAlert('success', 'saved');
function newAlert(type, message) {
document.getElementById('alert-area').innerHTML="<div class='alert " + type + "'><p> " + message + "</p></div>";
}
</script>
</body>
<html>

MediaElement.js dynamic content not working in IE9

I'm trying to use MediaElement.js on a site and everything works great in every browser but IE, most specifically IE9 (I'm not too concerned with supporting below IE9 at the moment). I'm populating the ME dynamically which I've read can cause problems in IE specifically, but I'm just not sure if there is a workaround. The reason I'm doing it this way is because this is a portfolio site where all project data gets loaded through a getJSON call and once loaded all projects get populated with their appropriate data and created on the fly. There are several video projects. I've dumbed the code down to an example outside of my project which essentially goes through this same behavior. If I just write the HTML out and control in JS it works but when I create the HTML through JS and then try to play I get the error log (in the creation of ME player in the code). Here is the code:
$(function() {
var details = {
width: 640,
height: 480,
src: 'work/television/1'
},
$body = $('body'),
$vid = $('<video width="' + details.width + '" height="' + details.height + '" preload="none" id="vidPlayer1"></video>'),
$mp4 = $('<source src="' + details.src + '.mp4" type="video/mp4" title="mp4">'),
$webm = $('<source src="' + details.src + '.webm" type="video/webm" title="webm">'),
$ogg = $('<source src="' + details.src + '.ogv" type="video/ogg" title="ogg">'),
$flash = $('<object width="' + details.width + '" height="' + details.height + '" type="application/x-shockwave-flash" data="swf/flashmediaelement.swf"><param name="movie" value="swf/flashmediaelement.swf"><param name="flashvars" value="controls=true&file=' + details.src + '.mp4"></object>'),
$error = $('<p>The available video formats are not supported by your browser. :(</p>'),
$controls = $('<div class="videoControls playBtn"></div>');
$body.append($controls);
$vid.append($mp4);
$vid.append($webm);
$vid.append($ogg);
$vid.append($flash);
$vid.insertAfter($controls);
var vidPlayer = new MediaElementPlayer('#vidPlayer1', {
features: [],
// mode: 'shim',
pluginPath: 'swf/',
success: function(mediaElement) {
console.log('success', mediaElement);
},
error: function() {
console.log('Error loading player. Please try again.');
}
});
$body.on('click', function(evt) {
vidPlayer.play();
});
});
Any help would be tremendously appreciated.
problem solved. for anyone interested, had to combine my appends into one call so $vid became:
$vid = $('<video width="' + details.width + '" height="' + details.height + '" preload="none" id="vidPlayer-' + row + '-' + slide + '"><source src="' + details.src + '.mp4" type="video/mp4" title="mp4"><source src="' + details.src + '.webm" type="video/webm" title="webm"><source src="' + details.src + '.ogv" type="video/ogg" title="ogg"><p>The available video formats are not supported by your browser. :(</p></video>')
just had to put it all in one statement and IE9 recognized it properly. The issue was by appending as I was doing the source variables never got appended and thus IE didn't know what the source of my video was.
Hope this helps someone in the future.