When printing to PDF using C# + Excel Interop what is the best practice for detecting when the file has successfully printed or if there was a problem?
I need to know so that my app can take the generated PDF file, rename it, move it to a shared network drive, email it, etc. (Perhaps I should build a dedicated SSIS app to handle that part... hmmm... then I have an excuse to learn SSIS/BIDS)
Simply polling the directory until File.Exists() or we reach some maxTries cap is not a very satisfying way to handle it.
I am using VS 2008 Pro, Excel 2003 (11.0 Object Library), and Adobe Acrobat 7.0 Pro. Running on WinXP SP3.
I think the polling technique is fine. Its a common technique. I do agree that it'd be nice to have an AfterPrint(StatusCode) to match BeforePrint, but the Automation API doesn't provide for that, so poll away!!! It works for almost every process on linux, many windows services, and applications.
Related
I am developing asp.net core application that downloads some excel files and executing macro on it.
Macro is performing some data validation and data formatting and generating new excel file. I need to save this file in a specific folder on the server.
I have hosted this application on centos 7 so obviously Microsoft interop service will not work. So, I have to execute macro using open office.
If anyone can help then it will be very much appreciated.
As you said, COM interop will not work on CentOS, so you probably want to use Java or Python instead.
However, it may work to do a C# system call and execute a Basic macro. An example from https://ask.libreoffice.org/en/question/150565/execute-macro-in-calc-from-terminal/:
soffice "macro:///Standard.Module1.Ora(2,3)" "/home/lim/Scrivania/Test.ods"
With this setup, much of the code will be in Basic. If you are not familiar with the language, a good place to start is http://www.pitonyak.org/oo.php.
A have a question for CATIA customization experts!
I'm intend to develop a web application able to perfoms the following tasks:
Modify some parameters into CATIA files. eg.: change the diameter or length of a part;
Convert theses CATIA files to STEP files.
So, I possible do these things using CATIA API and without have CATIA software instaled on my web server?
I did some research on the WEB and I found some APIs, like "CAD.ai" that I think solve these questions. But, these APIs look so sophisticated for my purpose and I looking for develop my own code.
Any suggestion?
Catvbs code can be incorporated in web pages and "talk' with CATIA, check Dassault Systems automation documentation which is in the installation folder of CATIA (be aware that there are differences between releases and versions of CATIA- v5, v6, 3DEx). You don't need to have CATIA but you need to check if CATIA is opened or not on client PC (and convince CATIA user to run your code from web).
By the way, from DS chm automation file you can run their codes directly in CATIA...
I want to interact with a Photoshop file and create images using its actions and smart objects.
Is there any php or C# API to can do it?
First of all, I would like you to reflect on the legality of such a thing. Would Adobe let you practically just proxy their application to the web? I see they have a lot of licenses so maybe one of them actually grants you permission to do this (however, there could still be caveats so I suggest you read up on that). As that's not the question, I won't talk about this anymore, I just wanted to to mention it as it should be relevant.
Now, for the actual question - if you look at Microsoft Office Interop, Microsoft states that it is unsupported in a server-side environment. Go to this Microsoft page and read Problems using server-side Automation of Office in the More information section.
There are several issues if you decide to run a regular client application server-side, as stated on the mentioned page, but one of the most significant issues is the following:
Interactivity with the desktop:
Office applications assume that they are being run under an interactive desktop. In some circumstances, applications may need to be made visible for certain Automation functions to work correctly. If an unexpected error occurs, or if an unspecified parameter is needed to complete a function, Office is designed to prompt the user with a modal dialog box that asks the user what the user wants to do. A modal dialog box on a non-interactive desktop cannot be dismissed. Therefore, that thread stops responding (hangs) indefinitely. Although certain coding practices can help reduce the likelihood of this issue, these practices cannot prevent the issue entirely. This fact alone makes running Office Applications from a server-side environment risky and unsupported.
While this is written by Microsoft for their product, these are more or less applicable to any regular client application. And even if you still decided to go with this approach, as Neville K already suggested, it would be a very resource-hungry task.
Considering the above, I would maybe ask a different question, along the lines of "What library or server-side app to use for doing whatever you need to do with images".
Based on this link, you can do this things with Photoshop SDK:
"With the Photoshop SDK, you can enable your apps to drive and/or communicate with Photoshop CS6 (version 13.0.0 or later) via a TCP connection. It’s now possible to create an eBook of Photoshop tutorials that allows users to drive actions in Photoshop CS6 from within the eBook"
This sound like hard but some companies seems to make it work. Xee can read PSD too (and has an epic comment about this format in the source code).
But to quote someone over at HN:
PSD was never intended to be a data interchange format: it is the
serialization format of a single program that has more individual
unrelated features that actual people rely on than almost any other
piece of software and has maintained striking amounts of backwards
compatibility and almost unbroken forwards compatibility during its
over two decades of existence. This product's "file format" needs to
be critiqued in this context, along with similar mega-programs like
Office. I am thereby having a difficult time fathoming why anyone
would think that a PSD file is thereby going to be some well-organized
file format that they should easily be able to parse from their own
application is just naively wishful thinking: even other products
from Adobe have limitations while opening these files; to truly
manipulate these files you really need to be highly-compatible with
Photoshop's particular editing model (hence the conceptual
difference between these two classes of file format).
I would recommand to look at Xee for a server side utility.
Good luck.
You can use the scripting interface to kick off "Shell" tasks from any web language if you really want to.
However, I'd seriously worry about this approach - the memory requirements for Photoshop are such that you could only support a couple of users, and you'd need a fairly complex polling mechanism to check for the results of the "shell" task. Photoshop was simply not designed to power web sites in this way.
Consider using graphics libraries instead - I've used ImageMagick with great effect in the past.
Heed the warnings that you really can't process more than 1 or 2 images at a time with photoshop without crashing your server, so just putting it on your webserver is a non-starter. A lighter weight image library is much better for most tasks.
But you could queue up jobs from your web application and then process them on another computer, or limit it to just one at a time.
Adobe has macros and a full action/javascript based scripting environment that you could kick off from commandline or com.
Adobe Scripting Guide
http://wwwimages.adobe.com/www.adobe.com/content/dam/Adobe/en/devnet/photoshop/pdfs/photoshop_cs5_scripting_guide.pdf
For older versions of photoshop you can use the macro functionality to Record an action. Then, create a droplet from the action. Call the droplet from the command line with an image file as the sole parameter. The path to the image file probably needs to be an absolute one.
I'm trying to create an excel file from ASP.NET. I assume this file is created somewhere temporary right? How can I get this location?
What are you using to create the Excel file? Since you have an ASP.NET tag I hope you are not trying to do this with Office COM Automation, it is not supported and trust me it is very very unreliable. See this link from Microsoft http://support.microsoft.com/kb/257757
Key message from the link
Microsoft does not currently recommend, and does not support, Automation of Microsoft Office applications from any unattended, non-interactive client application or component (including ASP, ASP.NET, DCOM, and NT Services), because Office may exhibit unstable behavior and/or deadlock when Office is run in this environment.
I would suggest that you take a look at using NPOI library, it is very fast and works reliably on the server side. And you can then control where the file is generated.
If you are using a temp path or a temp file you should not care about where it is. If you need to care you should use a concrete path with a concrete file. You can also use a MemoryStream to do this all without HardDisk.
EDIT:
Additional to the comment I recommend you to use Open XML to create a Excel Sheet. If this is an option let me know than will I post more on that.
I must say I didn't know this article from Chris Taylors post and if I had found this one last year it had saved me a lot of time. But what I must say at this point; it is possible to get a serverside solution running which uses interop and I need it last year. But it was a pain till it work and if anyone want to give it a try here are some advices:
you should not use interop directly
from a ASP apllication
you can't use impersonation (it may
fail unexpected)
you will need a service which runs as
System
you need a executable that runs the
interop
you have to manage the the execution
through the service (and I mean
manage, not just starting)
And again; I don't recommend to do this. Use any other solution if you. (MS Supports automation services with SharePoint2010)
I have a asp.net web site. I want to invoke MS word on a Client machine. Is there any easy way to do this with VS2008, C#3.0?
I can do this with Qt and with an ActiveX control but trying to avoid going this way...
would silverlight be a way to go?
You want to execute an application from the browser (without the evil ActiveX things, of course)?! If you could do that, probably you could wipe off the whole disk too.
And no, Silverlight runs in a partially trusted sandbox. It won't run unmanaged executables on the client machine.
If you are just trying to get Word open to view a document, you could just give your user a link to the .doc/.docx file and their browser would take care of opening the file. If you want to interact with Word, you're going to have a hard time doing that from the browser without using ActiveX.
Silverlight has the same locked down sandbox environment that the web browser has, so that won't help you get around this security limitation.
What are you trying to do with Word? Even if you could launch the app, I don't think you could do any kind of COM interaction from within your web page.
An easy way to merely launch Word would be to have the user download a Word file, but I don't think that's what you're asking and they might not open the file -- they could choose to save it instead.