I have a simple C# utility that invokes PDFSharp to send a PDF file to a printer. However, it seems to behave inconsistently on a Windows 7 machine. Here's the code
PdfFilePrinter.AdobeReaderPath = "C:\\Program Files\\Adobe\\Reader 10.0\\Reader\\AcroRd32.exe";
PdfFilePrinter printer = new PdfFilePrinter(fileToPrint, printerName);
try
{
printer.Print();
When testing I launch the utility from the command line several times in a row processing a bunch of PDF files one file at a time. During some of these runs, a small Adobe window pops up. I don't have a link to what it looks like but it's a window with standard Adobe Reader X menus, a "Open a recent file" list on bottom left and "Acrobat.com services" on bottom right. Unless I manually close this window, printer.Print(); will never complete, which is a problem since I need to batch process hundreds of files at a time.
When this happens seems to be random. Sometimes it happens when the 1st test file is being processed and sometimes it's the 5th or the 7th.
How can I either ensure that this window does not appear or suppress it automatically if it does?
Any chance your printer supports PDF natively? If so, you could just send it directly to the printer either via LPR/RAW 9100 or through a Windows print queue: How to send raw data to a printer
Related
I have a batch file which launches other .bas files with the help of gwbasic.
Here is the code of the batch file:
graphics
cd basic
gwbasic menut-hp/d
cd \
Then I have the possibility by typing 1 or 2 etc + ENTER to choose which program i want to run. The programs are located in the same directory as my batch file. The programs are xxx.BAS files.
The problem is:
I have a piece of software written in GWBASIC that currently is set up to just print locally to LPT1.
When I disconnect the local printer, the software (gwbasic i guess) sends automatically the things to print to the network printer.
The result is that a lot of A4 papers come out with only a few lines written.
On the local printer, the printer only printed when i exited the batch program.
On the network printer, it's like its non stop synchronizing, and not only when i exit the batch program.
I see 2 solutions:
manage to put a tempo for the printing on the network printer (to refresh every 2 minutes for example)
or try to add a line in the .BAS files, to save the text in a .txt of .pdf file, instead of printing it.. or print it in a pdf file.
I have almost no idea how gwbasic works, even after some researches.
Moreover, i haven't managed to view (and modify) the code of the .BAS files
Sorry for my bad english,
If anyone has any idea, it would help me a lot!
Thank you very much :)
Maybe later, but I enjoy scripting with BASIC and CONSOLE APP.
I recommend you run a command BAT before you BAS code to get default printer
wmic printer get name,default | find "TRUE" > Printer.txt
With this linen you get the similar response into Printer.txt
TRUE Microsoft Print to PDF
After that, in your BAS code, read them and validate printer name or discard network printer before print.
Happy coding!
I am using ZebraDesigner to create labels and save them as .zpl, files, then manually editing the zpl code to customize it further, and then save it in the printer's directory in onboard flash memory.
I see the .zpl files, listed with their sizes, in the flash directory, but the files are blank when opened, or sometimes contain text belonging to another file. If I try to paste new code into the file in flash, I'm unable to save it; meaning, I click save, and the web pages merely changes the file extension from ".zpl" to "---", then if I save again, then I get an error the script could not be saved.
I've been unable to get sufficient information nor resolution by contacting Zebra or looking at the product documentation. Advice would be appreciated.
I have an app written in Lua with wxLua. While this app is running, I want to be able to send a (large) string to an external program so the user can view the string, search it, etc.
This external program can be notepad, notepad++, etc, or even a browser window, as long as the user can view and search the text.
I can open open an editor using
local handle = io.popen("notepad", "w") -- for example
but then
handle:write (myString)
doesn't show anything in the editor. And notepad++ doesn't even open a new window if I already have it running.
I can launch a browser using
wx.wxLaunchDefaultBrowser ("http://stackoverflow.com")
but I don't know how to pass the (100-200kb) string to the browser window.
Any help is very much appreciated, thank you!
Stomp
Print out text or HTML file and then open it in browser with wx.wxLaunchDefaultBrowser ("file://path/to/file") or use os.execute to run external editor with same file as argument.
See Oleg's post for the best solution, IMO.
Another solution would be to place your text on the clipboard, so the user could paste it wherever they like.
As for injecting text into apps that are already open, that's non-trivial and beyond the scope of what you can do with wxLua. You'd need to use COM interfaces or traverse the apps' control structures using Win32 API calls or something equally hairy and often app-specific.
I have an app that can optionally open PDF's after it creates them. If two reports are generated in succession with the same name, the second attempt fails if the first copy of acrobat still has the PDF open, so before I write the PDF I check (with FindWindow) for a window with the document name. If one is found I issue a SendMessage WM_Close.
This works OK, but I was doing some other tests and was using Word to "edit" the PDF, to hold it open so I could test the app's behaviour when it can't write the PDF file. Now, when my app tries to close the window, Word pops up a "do you want to save" dialog. If I click cancel, Word remains open, my app carries on and I can test that it behaves sensibly when it encounters a file that it can't write to.
All good, but it has alerted me to the fact that using SendMessage WM_CLOSE to close another app will snag my app if the other app pops up a modal dialog. Is there any way around this - i.e a more forceful (but not too forceful) way of closing the other app? Or a "Close and click on cancel if necessary". Or should I use asynchronous messages?
Do not force any application to close, there may be other documents open the user is viewing etc... You can use SendMessageTimeout to wait the return of WM_CLOSE a sensible amount of time, and then proceed with either failure or success..
var
Word: HWND;
msgResult: DWORD;
begin
...
SendMessageTimeout(Word, WM_CLOSE, 0, 0, SMTO_NORMAL, 5000, msgResult);
if IsWindow(Word) then begin
// bummer! Application is open...
I would not close the other application at all. I think it's better to delete the current file before generating the report. If it fails (DeleteFile), show a message to the user that the file cannot be overwritten (because it is opened by another program) and do not generate the report at all. This is much safer, because you leave the option to the user. Also this saves you from major headaches, what if the program is opened by another program that does not show the title in the window caption?
If you want to go one step further than WM_CLOSE you can only terminate the application. Everything else would be like lottery.
That said I am against both. What if your PDF opens in a MDI application already showing other documents? Forcing the application to close would make the user lose all changes to the other open documents. And sending a close message to this application would be annoying since the user still needs the other documents opened.
You cannot predict the behavior of every application. And you certainly don't know every application. If the report has the same name then you can tell the user to close the other one with the same name. Otherwise he won't get a new report. Think what would happen if Windows started closing your applications as soon as you try to overwrite a file which is currently in use.
All
I use CreateProcess and WaitForSingleObject in Delphi 2007 to open files and wait for them to be closed.
I have found that when I open two PDF files in a row, the second WaitForSingleObject returns immediately. I have also found that this happens for jpg and tif files but not txt files. Also the second PDF takes 10 seconds longer to open than if opened by itself!
It also happens on both Vista and XP, and on a range of computers.
Am I using CreateProcess incorrectly or is it something else?
Any help would be appreciated.
Regards
Bob
What happens depends on the application that is registered to open PDF or JPG files. If you open the documents in an SDI application, then every CreateProcess() call returns a process handle for an application, which you can wait for - this will return when the application editing the document closes.
If however an application is limited to a single instance, then every further call will return as soon as the new instance has passed the data to the first instance (which will usually open the document in a new frame), and then has exited. I think that is what happens in your case, probably you are using Acrobat Reader to open the PDF files?