Same Script works in cmd command ,but faied in GhostScript.net - ghostscript

my Evironment is Windows10 64bit ,VS2015 ,GhostScript9.27,
Language is C#
And i using GhostScript.net to invoke GhostScript
here is my code
string inputFile = "D:\\112.pdf";
string outputFile = "D:\\output.pdf";
GhostscriptProcessor ghostscript = new GhostscriptProcessor();
List<string> switches = new List<string>();
switches.Add("-o");
switches.Add(outputFile);
switches.Add("-dNoOutputFonts");
switches.Add("-sDEVICE=pdfwrite");
switches.Add(inputFile);
ghostscript.Process(switches.ToArray());
and i try the script by the windows CMD Window
"gswin64.exe -o D:\output.pdf -dNoOutputFonts -sDEVICE=pdfwrite D:\112.pdf"
it works,
but when i run it in C# by GhostScript.net , it always give error
"An error occured when call to 'gsapi_init_with_args' is made: -100"
did anybody knows? thanks a lot for your help

Related

Browser Version Detection using Command line method using java

I know the commands to get the browser version of Edge, Firefox and Chrome in mac using command line which is working properly on my system.
Edge=/Applications/"Microsoft Edge.app"/Contents/MacOS/"Microsoft Edge" -version
FireFox=/Applications/Firefox.app/Contents/MacOS/firefox -v
Chrome=/Applications/Google\ Chrome.app/Contents/MacOS/Google\ Chrome --version
Chrome1=/Applications/"Google Chrome.app"/Contents/MacOS/"Google Chrome" --version
When I try with Firefox it successfully returns me the Firefox version.
but when I try for the Edge or the chrome it throws error in the java program.
Cannot run program "/Application/"Google" error=2 no such file or directory
I tried the escaping the query as /Applications/\"Microsoft Edge.app\"/Contents/MacOS/\"Microsoft Edge\" -version.I am printing the same before passing as a query and I am exactly getting the same query which works if I directly copy paste it on the terminal.
below is the code snippet
Am I missing something?
String line;
Process process;
String msEdgeVersion = null;
/*process = Runtime.getRuntime().exec("/Applications/Firefox.app/Contents/MacOS/firefox -v");*/
process = Runtime.getRuntime().exec(/Applications/"Microsoft Edge.app"/Contents/MacOS/"Microsoft Edge" -version);
// process = Runtime.getRuntime().exec("where notepad");
BufferedReader br = new BufferedReader(new InputStreamReader(process.getInputStream()));
while ((line = br.readLine()) != null) {
if (!StringUtils.isBlank(line)) {
msEdgeVersion = line;
System.out.println(line);
}
}
process.waitFor();
process.destroy();
According to the related api Runtime.getRuntime().exec(String command), you need to know that the parameter passed in is a valid String, so you need to pay attention to the format of the String parameter type.
Edit:
I reproduced your problem and got the same problem. After searching, I found the same problem. This is because the Process is different from the terminal process. You have to add -l to run the command as logged in user.
This is my test:

Adobe Illustrator: Run python file from Extendscript in Windows

I am facing issue while running this script(time.jsx):
var timeStr = system.callSystem("cmd.exe /c \"time /t\"");
alert("Current time is " + timeStr); Documentation of AE
it works in Adobe After Effects but I want to use it specifically in illustrator. Basically, i want to run my Python script from Extendscript(.jsx). But I couldn't find any solution to do so yet.
Your help is appreciated.
Thanks in Advance.
i have found a way to execute Python or other scripts in Extendscripts(*.jsx), and that is it, there is named File object in documentation which has a function named execute(); which executes the scripts according to their statement. For example, you want to execute hello world in python through .jsx file, you need to make a py file including print("hello world"). After that, add these lines in the script.jsx script:
var pyHello = new File("<path of py file>");
var bool = pyHello.execute();
alert(bool);
If script executed, it would be true, otherwise, false,

Java 8 Acces Denied while running process with arguments

In my program i need to run exe file in process. I'm doing it with ProcessBuilder. When i'm putting to code only directory and exe name, process is running normally, but i want to put arguments. When i'm trying it i'm getting exception with Acces Denied message.
It's my code:
Process process = new ProcessBuilder("C:\\Directory", "file.exe", argument1).start();
What is wrong with it?
My earlier code, that worked but without arguments was:
String folder = "C:\\Directory";
String exe = "File.exe";
ProcessBuilder pb = new ProcessBuilder();
pb.command(folder + exe);
pb.start();
With this code i was able to see started process in ProcessManager.
Your code is trying to execute C:\\Directory which is not allowed.
The full path of the executable must be in the first argument to the constructor, so:
Process process = new ProcessBuilder("C:\\Directory\\file.exe", argument1).start();
This is assuming C:\Directory\file.exe is the program you are trying to run.
Update: In your original code you have:
String folder = "C:\\Directory";
String exe = "File.exe";
so 'folder + exe' is C:\DirectoryFile.exe so you the equivalent code is:
Process process = new ProcessBuilder("C:\\DirectoryFile.exe", argument1).start();

Book rating predication using lenskit

I read this website : http://lenskit.org/documentation/evaluator/quickstart/ I first tried to run it using the script " $ lenskit eval " and I just created a new groovy file in my hello-lenskit example and run it using the command line but nothing happened. Then I tried to use it in Java program(hello-lenskit.java).
I run into some errors.
File dataFile = new File("ml-100k/u.data");
PreferenceDomain domain = new PreferenceDomain(1.0,5.0,1.0);
DataSource data = new CSVDataSource("ml-100k",dataFile,"\t",domain);//give me an error CSVDataSource is not public and can not be accessed from the outside package.
CrossfoldTask cross = new CrossfoldTask();
LenskitConfiguration config1 = new LenskitConfiguration();
config1.bind(ItemScorer.class)
.to(UserMeanItemScorer.class);
AlgorithmInstance alg1 = new AlgorithmInstance("PersMean",config1);
evl.addAlgorithm(alg1);
LenskitConfiguration config2 = new LenskitConfiguration();
config2.bind(ItemScorer.class)
.to(ItemItemScorer.class);
config2.bind(UserVectorNormalizer.class)
.to(BaselineSubtractingUserVectorNormalizer.class);
config2.within(UserVectorNormalizer.class)
.bind(BaselineScorer.class,ItemScorer.class)
.to(ItemMeanRatingItemScorer.class);
AlgorithmInstance alg2 = new AlgorithmInstance("ItemItem",config2);
evl.addAlgorithm(alg2);
evl.addMetric(RMSEPredictMetric.class);
File file = new File("eval-results.csv");
evl.setOutput(file);
What should I do next? How could I generate the overall rating error?
Using the LensKit evaluation commands manually is difficult, undocumented, and not recommended.
The SimpleEvaluator is the best way to get overall accuracy from a LensKit recommender in a Java application.
For further assistance in debugging LensKit runs, I recommend e-mailing the mailing list with exactly the commands you are running and the output or errors you are getting.

Adding image from URL in Word 2011 for Mac OSX using VBA

I am working on porting a project in Windows over to OSX. I have overcome issues with VBA for OSX Word 2011 not allowing you to send POSTs to a server and have figured out how to return a string result from an external script. Now I have to insert an image in my Word file from a URL that is built using the return of my external script.
The current attempt is as follows, and works in Windows but crashes Word in OSX:
Selection.InlineShapes.AddPicture FileName:=File_Name, _
LinkToFile:=False, SaveWithDocument:=True
After doing some research, it looks like MS may have disabled this functionality in OSX as a "security risk". I still need to make it work. Does anybody know of a way within VBA for Office 2011 to make this work, or barring that a workaround? I am trying to avoid writing the image file to the disk if possible.
UPDATE: I have created a Python script for getting the image file from a URL, but I still do not know how to get this image from the Python script into VBA, and from there into the Word document at the location of the cursor. The important bits of the script are below. The image is read in as a PIL object and I can show it using img.show() just fine, but I am not sure what filetype this is or how to get VBA to accept it.
# Import the required libraries
from urllib2 import urlopen, URLError
from cStringIO import StringIO
from PIL import Image
# Send request to the server and receive response, with error handling!
try:
# Read the response and print to a file
result = StringIO(urlopen(args.webAddr + args.filename).read())
img = Image.open(result)
img.show()
except URLError, e:
if hasattr(e, 'reason'): # URL error case
# a tuple containing error code and text error message
print 'Error: Failed to reach a server.'
print 'Reason: ', e.reason
elif hasattr(e, 'code'): # HTTP error case
# HTTP error code, see section 10 of RFC 2616 for details
print 'Error: The server could not fulfill the request.'
print 'Error code: ', e.code
Note that in the above, args.webAddr and args.filename are passed to the script using the argparse library. This script works, and will show the image file that I expect. Any ideas on how to get that image into Word 2011 for OSX and insert it under the cursor?
Thanks a lot!
Edit: updated the link to the project since migrating to github.
Old question, but no answer, and I see the same crash here when the image is at an http URL. I think you can use the following workaround
Sub insertIncludePictureAndUnlink()
' Put your URL in here...
Const theImageURL As String = ""
Dim f As Word.Field
Dim r As Word.Range
Set f = Selection.Fields.Add(Range:=Selection.Range, Type:=wdFieldIncludePicture, Text:=Chr(34) & theImageURL & Chr(34), PreserveFormatting:=False)
Set r = f.Result
f.Unlink
Set f = Nothing
' should have an inlineshape in r
Debug.Print r.InlineShapes.Count
' so now you can do whatever you need, e.g....
r.Copy
Set r = Nothing
End Sub

Resources