It works fine when document is opened in Acrobat, but does not work properly when the same PDF document is opened in web browser such as Google Chrome. this.closeDoc() is not getting executed in the Browser.
string path2 = #"D:\test\input.pdf";
string output = #"D:\test\output.pdf";
if (File.Exists(path2))
{
iText.Kernel.Pdf.PdfWriter writer = new iText.Kernel.Pdf.PdfWriter(output);
iText.Kernel.Pdf.PdfDocument pdfDocument = new iText.Kernel.Pdf.PdfDocument(new iText.Kernel.Pdf.PdfReader(path2) ,writer);
pdfDocument.AddNewPage();
String js = "var rightNow = new Date();"
+ "var endDate = new Date('2017-07-13');"
+ "if(rightNow.getTime() > endDate){"
+ "app.alert('This Document has expired, please contact us for a new one.',1);"
+ "this.closeDoc();}"
+ "else{}";
pdfDocument.GetCatalog().SetOpenAction(iText.Kernel.Pdf.Action.PdfAction.CreateJavaScript(js));
pdfDocument.Close();
}
Are you try "window.close()" ?
String js = "var rightNow = new Date();"
+ "var endDate = new Date('2017-07-13');"
+ "if(rightNow.getTime() > endDate){"
+ " app.alert('This Document has expired, please contact us for a new one.',1);"
+ " this.closeDoc(); "
+ " if(window){ window.close(); } "
+ "}"
+ "else{}";
Related
Trying to get records from Chrome's IndexedDB launching script using selenium's IJavaScriptExecutor in C# code, but always getting empty result.
The same script executed in browser console returns records.
//_webDriver is an initialized instance of ChromeDriver
var jsDriver = (IJavaScriptExecutor)_webDriver;
var metrics = jsDriver.ExecuteScript(
"function getAllEvents() {" +
"var t_events = [];" +
"var connection = window.indexedDB.open('metrics', 1);" +
"connection.onsuccess = (e) => {" +
"var database = e.target.result;" +
"var transaction = database.transaction(['events'], 'readonly');" +
"var objectStore = transaction.objectStore('events');" +
"request = objectStore.openCursor();" +
"request.onerror = function(event) {" +
"throw new Error('error fetching data!');" +
"};" +
"request.onsuccess = function(event) {" +
"let cursor = event.target.result;" +
"if (cursor) {" +
"let key = cursor.primaryKey;" +
"let value = cursor.value;" +
"t_events.push(value);" +
"cursor.continue();" +
"}" +
"else {" +
// no more results
"}" +
"};" +
"};" +
"connection.onerror = (e) => {" +
"throw new Error('error opening connection to database!');" +
"};" +
"return tip_events;" +
"} return getAllEvents();");
Working script string in browser console looks like this (removed last return command):
function getAllEvents() {var t_events = [];var connection = window.indexedDB.open('metrics', 1);connection.onsuccess = (e) => {var database = e.target.result;var transaction = database.transaction(['events'], 'readonly');var objectStore = transaction.objectStore('events');request = objectStore.openCursor();request.onerror = function(event) {throw new Error('error fetching data!');};request.onsuccess = function(event) {let cursor = event.target.result;if (cursor) {let key = cursor.primaryKey;let value = cursor.value;t_events.push(value);cursor.continue();}else {}};};connection.onerror = (e) => {throw new Error('error opening connection to database!');};return t_events;} getAllEvents();
What am I doing wrong?
I'm to figure out how to code so that the link opens into a new window? Is this the correct way to do that?
<script>
var copyright = "© ";
var d = new Date();
var n = d.getFullYear();
var db = " Doing Business";
var str = new String(" Link");
document.write(copyright + n + str.link("https://www.google.com"));
document.write(db);
</script>
Please stop using String.link. It's old, deprecated, and smelly. It also doesn't support what you are trying to do.
You can construct a link with the appropriate target attribute (read more) to open in a new tab as follows:
var myLink = "<a target='_blank' href='https://www.google.com'>Link</a>";
document.write(copyright + n + " " + myLink);
Everything is in the question. I just want to execute another process from a Photoshop Script (coded in ExtendScript) without the console appearing, or at least finding a way to put back in the front the Photoshop application.
Thx for your help !
function Main()
{
if (app.documents.length == 0)
{
return;
}
var tmpFolder = $.getenv("TEMP");
var exeFile = "convertor.exe";
/** Save a temporary copy of the current document. **/
var tmpPng = new File(tmpFolder + "\\" + app.activeDocument.name + ".png");
var saveOpts = new PNGSaveOptions;
app.activeDocument.saveAs(tmpPng, saveOpts, true, Extension.LOWERCASE);
/** Convert the file to a MP4 video. **/
var tmpMp4 = new File(tmpFolder + "\\" + app.activeDocument.name + ".mp4");
var conversionLog = new File(logFolder + "\\" + "conversion.log");
var command = exeFile + " -inputPng=\"" + tmpPng.fsName + "\" -outputMp4=\"\" -logPath=\"" + conversionLog.fsName + "\"";
app.system(command);
tmpPng.remove();
}
Main();
I am having a problem when attempting to echo data in a php file to mobile Safari in iOS 7.1.2. Here is the php code:
function swapFlights()
{
var url;
redirect = 1;
airline = <?php echo 'PDT'; ?>;
url = "swap.php?date_one=" + date1 + "&flight_number_one=" + flight1 + "&dep_station_one=" + city1 + "&date_two=" + date2 + "&flight_number_two=" + flight2 + "&dep_station_two=" + city2 + "&redirect=" + redirect + "&airline=" + airline;
window.location.href = url;
}
In mobile Safari on iPhone 5S, the output is the following:
function swapFlights()
{
var url;
redirect = 1;
airline =
2cc1
PDT;
url = "swap.php?date_one=" + date1 + "&flight_number_one=" + flight1 + "&dep_station_one=" + city1 + "&date_two=" + date2 + "&flight_number_two=" + flight2 + "&dep_station_two=" + city2 + "&redirect=" + redirect + "&airline=" + airline;
window.location.href = url;
}
The seemingly random "2cc1" is interjected, and I cannot for the life of me figure out why. It causes a SyntaxError in the parsing of the JavaScript, rendering all of the JavaScript on the page unusable. In every other browser I've tried (desktop Safari, Firefox), the code is output correctly as one would expect:
function swapFlights()
{
var url;
redirect = 1;
airline = PDT;
url = "swap.php?date_one=" + date1 + "&flight_number_one=" + flight1 + "&dep_station_one=" + city1 + "&date_two=" + date2 + "&flight_number_two=" + flight2 + "&dep_station_two=" + city2 + "&redirect=" + redirect + "&airline=" + airline;
window.location.href = url;
}
Any ideas, or is this more likely a bug in mobile Safari itself? I've searched all over the internet, but can't seem to find any other instances of this problem.
Changing the php to:
redirect = 1;
<?php echo 'airline = PDT'; ?>;
results in the unknown characters being slightly different, and appearing earlier in the output:
redirect = 1;
2ccb
airline = PDT;
I should have specified that my goal is the replace the 'PDT' with the string variable $airline. I changed the variable to the literal 'PDT' thinking I may have had a problem with the datatype of the variable, but that wasn't the case.
I created this method to create a text file as log for a page that has different buttons that call functions with parameters from different textfields:
function WriteToFile(data) {
var currentdate = new Date();
var datetime = "Time: " + currentdate.getDate() + "/" + (currentdate.getMonth()+1) + "/" + currentdate.getFullYear() + " # " + currentdate.getHours() + ":" + currentdate.getMinutes() + ":" + currentdate.getSeconds();
var fso = new ActiveXObject("Scripting.FileSystemObject");
var a = fso.OpenTextFile("C:\\logs\\log.txt", 8);
a.WriteLine(datetime);
a.WriteLine(data + "\n");
a.Close();
}
And it works perfectly fine when I'm using the C: drive. Unfonrtunately, this is to be used in production in a Z: drive so other people can use the page as well. When I copy it to the Z: drive and change this line:
var a = fso.OpenTextFile("C:\\logs\\log.txt", 8);
to the following:
var a = fso.OpenTextFile("Z:\\logs\\log.txt", 8);
it gives me an error saying:
Automation server can't create object
I am using IE8. Any ideas on what I'm doing wrong and how I can fix this?