I have a dynamic PDF that doesn't display correctly in Firefox, Chrome, or lower versions of Adobe. Is there a way to show blank page with error message when the user opens it with anything less than Acrobat version X?
I tried searching on this site and Googling but couldn't find anything..
Help much appreciated!!
This can be achieved with a PDF cover page but can also be achieved with your own subform combo and a bit of script. Creating a cover page that is hidden only to reveal your form content if a script executes correctly and is inside a full feature XFA form viewer is one way to tackle this.
function detect(){
//Sample platform detection
var viewerType = xfa.host.appType;
var versionNo = xfa.host.version;
var variation = xfa.host.variation;
var plugIns = app.plugIns;
var nplugIns = plugIns.length;
var msg = "";
if((viewerType == "Reader") && (nplugIns > 0)){
msg = "This PDF was opened in Reader " + versionNo + ", " + variation + ", and loaded " + nplugIns + " plug-ins.";
form1.Top.Cover.presence = "hidden";
form1.Top.Content.presence = "visible";
}
else if((viewerType == "Exchange") && (nplugIns > 0)){
msg = "This PDF was opened in Acrobat " + versionNo + ", " + variation + ", and loaded " + nplugIns + " plug-ins.";
form1.Top.Cover.presence = "hidden";
form1.Top.Content.presence = "visible";
}
else if((viewerType == "Exchange-Pro") && (nplugIns > 0)){
msg = "This PDF was opened in Acrobat Pro " + versionNo + ", " + variation + ", and loaded " + nplugIns + " plug-ins.";
form1.Top.Cover.presence = "hidden";
form1.Top.Content.presence = "visible";
}
else{
msg = "This PDF was opened in an unrecognized platform";
}
xfa.host.messageBox(msg); //Throw prompt.
form1.Top.Content.TextField1.rawValue = msg; //Write message to form.
}
Most of the function above relies on xfa.host.appType but some PDF viewers developped using the Adobe Acrobat code base will return valid platform values but will not load any plug-ins which is a way to detect and unsupported platform.
Related
I work on CVRP in combinatorial optimization, where the goal is to compare several models on several instances, using the OPL language. For this to e done, I first wrote and tested the said models; then I wrote an main flow control supposed to run each instance for a 2 hours duration.
My problem is that after 2 hours, and this for each model, the output file appears for some instances, containing the desired information; but for other instances, the output files do not appear, as if these instances do not exist. This problem persists even when you launch one or more of these instances in isolation.
below is the main flow control code, where BPF designates the name of the .mod file, which is simply modified in the code, when one wishes to switch to another model.
{string} datFiles=...;
main {
var source = new IloOplModelSource("BPF.mod");
var cplex = new IloCplex();
var def = new IloOplModelDefinition(source);
cplex.tilim=2*60*60;
cplex.threads=1;
for(var datFile in thisOplModel.datFiles)
{
var opl = new IloOplModel(def,cplex);
var data2= new IloOplDataSource(datFile);
opl.addDataSource(data2);
opl.generate();
var o=new IloOplOutputFile("BPF "+datFile+".txt");
if (cplex.solve()) {
if(cplex.getCplexStatus()==11){
o.writeln("instance : " + datFile
+" / opt = "
+ " / UB = " + cplex.getObjValue()
+ " / LB = " + cplex.getBestObjValue()
+" / time = " + " - "
+" / Gap = "+cplex.getMIPRelativeGap()*100+"%");
}
else {
o.writeln("instance : " + datFile
+ " / opt = " + cplex.getObjValue()
+ " / UB = " + cplex.getBestObjValue()+"*"
+" / time = " + cplex.getSolvedTime()
+ " / Gap : -");
}
o.close();
}
opl.end();
}
}
I am trying to upload file in a selenium test that is run on chrome browser on an android phone. The usual element.sendkeys(path) is not working.
Are there any known alternatives for android ?
It may help to upload the file:
public CorePage UploadHack(string fileInputId, string contentType, string fileContent, string fileName, string angularScopeVar)
{
UploadFile(_filePath);
var uploadHack =
"(function(){" +
"function convert(base64){" +
"var raw = atob(base64);" +
"var arr = new Uint8Array(new ArrayBuffer(raw.length));" +
"for (var i = 0; i < raw.length; i++){" +
"arr[i] = raw.charCodeAt(i);" +
"}" +
"return arr; " +
"}" +
$"var file = new Blob([convert('{fileContent}')], {{'type':'{contentType}'}}); " +
$"file.name = '{fileName}'; " +
$"angular.element('#{fileInputId}').scope().{angularScopeVar} = file;" +
"})()";
Driver.ExecuteJavaScript(uploadHack);
return this;
}
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.
I am trying to write a big project which involves of a lot of code. That's why I want to separate functionalities from different files.
the first file, dataJS, I make an AJAX call to get data from a JSON file.
the second file, showJS I want to display the data obtained from the dataJS file.
When it comes to implementation, I realise that AJAX call takes longer time and even though I include dataJS and showJS in order, showJS will still get a null data
therefore I made a function called continueFromDataJS() in showJS file
and call continueFromDataJS() at the end of the AJAX success function.
I think it's a rather makedo solution. Is there any standard way to do it?
In addition, all intellisense in my Visual Studio is gone. Despite separate files, is there any way to make visual studio get intellisense from the dataJS?
Thank you
sorry, I don't know how to add a follow up question
this is the code
for simplicity I rename some of the files and only take some part out of it. Hope that helps
code in html
code in dataJS.js
var planets = [];
var jsonData = null;
$(function () {
$.getJSON("Scripts/planetData.js", function (data) {
//planets[0] = new planet("uranus", "career", 45, 700, 400, 0.1, 5, 3);
jsonData = data;
for (var i = 0; i < data.planets.length; i++) {
var curPlanet = data.planets[i];
planets[i] = new planet(curPlanet.graphic, i, curPlanet.field, curPlanet.planetInitialAngle, curPlanet.distanceFromStar, curPlanet.planetRadius, curPlanet.planetRevolvingSpeed, curPlanet.planetRotationSpeed, curPlanet.contents.length);
$("#result").append("<p>" + curPlanet.graphic + " " + curPlanet.field + " " + curPlanet.planetInitialAngle + " " + curPlanet.distanceFromStar + " " + curPlanet.planetRadius + " " + curPlanet.planetRevolvingSpeed + " " + curPlanet.planetRotationSpeed + " " + curPlanet.contents.length + "</p>");
}
callDisplayScript(); //**continue from showJS.js file is that the way to do this?**
});
});
// more functions below in dataJS.js
showJS.js
function callDisplayScript() { **// this is the ugly part. What's the proper way to do it?**
$("#display #close").click(function () {
$("#display").fadeOut('slow');
});
$article = $("#display article");
$article.empty();
var data = jsonData.planets[pID].contents; // **this line won't get jsonData if it's out this curly brace.**
for (var i = 0; i < data.length; i++) {
$article.append(data[i].title);
$article.append(data[i].content);
}
$("#display").fadeIn('slow');
};
don't forget to answer my intellisense question. I want in datajs.js automatically hint planets and jsonData declared in datajs.js
is it possible?
The following is code I have used to try to record skeleton frame data
using (SkeletonFrame skeletonFrame = e.OpenSkeletonFrame())
{
if (skeletonFrame == null)
return;
this.Recorder.Record(skeletonFrame);
}
if the code above is run, what information is recorded?
If I were to save this information to an external file, what would I see?
Would there be coordinate information and a specific timestamp associated with each coordinate information?
Are you looking at recording the X, Y, Z data of the skeleton into a text file? It is generally easier to record the information separately in readable format. If you are looking at doing the aforementioned then this may help:
//save the XYZ of the skeleton data, but also save the XZ of depth data
private void saveCoordinates(Skeleton skeleton, string textFile)
{
StreamWriter coordinatesStream = new StreamWriter(newPath + "\\" + textFile);
foreach (Joint joint in skeleton.Joints)
{
coordinatesStream.WriteLine(joint.JointType + ", " + joint.TrackingState + ", " + joint.Position.X + ", " + joint.Position.Y + ", " + joint.Position.Z);
}
coordinatesStream.Close();
}