Got a weird question for you. Recently upleveled my old project from java 7(jdk1.7.0_10) to java 8(1.8.0.91.x86_64). In java 7 it printed the post script file with no issues and now it is printing the postscript file as plain text instead of converting the file. This is on a redhat linux environment. Simply I am trying to print a string containing a post script file of a file itself.
Here is my original code
DocFlavor flavor = DocFlavor.INPUT_STREAM.POSTSCRIPT;
PrintService pService = PrintServiceLookup.lookupDefaultPrintService();
// In a field environment, send to the printer
if (System.getenv("USER_DEFINED_RELTOP") == null || pfr.exists()) {
if (pService.getName().isEmpty()) {
LOGGER.error("No printer selected");
} else {
LOGGER.info("Printing to " + pService.getName());
DocPrintJob pj = pService.createPrintJob();
try {
InputStream is = new ByteArrayInputStream(data.getBytes("UTF8"));
Doc doc = new SimpleDoc(is, flavor, null);
PrintJobWatcher pjw = new PrintJobWatcher(pj);
pj.print(doc, null);
pjw.waitForDone();
is.close();
} catch (PrintException | IOException e) {
LOGGER.error(e);
} // try block
} // no printer selected
// Otherwise, send to a file
} else {
That worked fine in java 7, I updated it to the oracle spec found here for java 8.
https://docs.oracle.com/javase/8/docs/api/javax/print/PrintService.html#createPrintJob--
https://docs.oracle.com/javase/8/docs/technotes/guides/jps/spec/printing.fm6.html
DocFlavor psFlavor = DocFlavor.INPUT_STREAM.POSTSCRIPT;
PrintRequestAttributeSet attrs = new HashPrintRequestAttributeSet();
attrs.add(MediaSizeName.ISO_A4);
PrintService[] pservices = PrintServiceLookup.lookupPrintServices(psFlavor,
attrs);
File pfr = new File(PFR_INDICATOR);
// In a field environment, send to the printer
if (System.getenv("USER_DEFINED_RELTOP") == null || pfr.exists()) {
//Check we have a printer capable of post script
if (pservices.length > 0) {
LOGGER.info("Printing to " + pservices[0].getName());
DocPrintJob pj = pservices[0].createPrintJob();
try {
InputStream fis = new ByteArrayInputStream(data.getBytes("UTF8"));
//byte[] ba =data.getBytes("UTF8");
Doc doc = new SimpleDoc(fis, psFlavor, null);
LOGGER.info("Doc Flavor " + doc.getDocFlavor());
PrintJobWatcher pjw = new PrintJobWatcher(pj);
LOGGER.info("PrintJob Attributes : " + pj.getAttributes());
pj.print(doc, attrs);
pjw.waitForDone();
fis.close();
} catch (IOException e) {
LOGGER.error(e);
NotificationDialog.show(NotificationDialog.NOTICE_TYPE.ERROR, PRINT_ERROR);
} catch (PrintException e) {
LOGGER.error(e);
}
} else { // no printer selected
This gives me an error java.awt.print.PrinterIOException: java.io.IOException: /usr/bin/lpr: where it looks to not find lpr.
If I keep it the way it was originally (not write to file) it prints the postscript as plain text even if adding the check to check if the printer is post script capable. If I use the new way of printing file I get a lpr not found error. If I print the PS document using the command lpr it converts it as expected and prints fine. If I use lpr -l that doesn't format it prints it document as plain text as well.
Any suggestion/help would be great. I am lost on what to do. I really don't want to convert it to an image and print that.
At a guess I'd say that your printer is an HP or at least PCL + PS printer, not a pure PostScript-only printer.
In that case you generally need to prepend the PostScript with a language selection PJL string. If you don't do this then it usually defaults to PCL and if you don't send any PCL commands (which all begin with 0x1B) then everything is treated as plain ASCII text. That would explain why both your application and lpr -l end up writing text, but lpr itself doesn't (presumably it adds the PJL).
You could try prepending the PostScript file with something like:
%-12345X#PJL JOB
#PJL ENTER LANGUAGE=POSTSCRIPT
NB the first byte there, before the % should be a 0x1b ESC character, but I can't readily paste binary....
Try sending the file with lpr -l if that works then you could try your old printing method.
Related
This code works with VLC 2.2.8 but it does not with VLC 3.0.9.2
if (it->second.handle && it->second.fDump) {
// Video/audio + file dump -> duplicate stream
transcode = "#duplicate{ dst=file{ dst=" + string(it->second.fDump) + " }, dst=display }";
}
else if (it->second.handle == NULL) {
// No video + file dump -> single stream
transcode = "#standard{ access=file, dst='" + string(it->second.fDump) + "' }";
}
I am focusing on the second branch and I wish to receive suggestions, thanks.
UPDATE:
It does not work means that it does not throw any error nor warning but it does not create the file. It seems, it ignores the option.
UPDATE 2:
I suspect that the saving option is ignored because I see this line in the application log which is related to the GPU but I have no way to see the video output:
avcodec: Using OpenGL/VAAPI backend for VDPAU for hardware decoding
It is not required decoding the stream but simply saving.
UPDATE 3:
I do not use the graphic interface but the command line and this works:
vlc rtsp://172.18.2.60:554/Streaming/Channels/1 --rtsp-user=$user --rtsp-pwd=$passwd \
--sout="#file{dst=test.mp4}" --vout=dummy -Idummy --ignore-config --quiet \
--rtsp-frame-buffer-size=500000 --network-caching=4000
However, trying to send the same trough VLC library API, it does not save the file. Then the issue should be in this piece of code which works with VLC 2.2.8:
it->second.p_lib = libvlc_new((int)argsCount, p_args);
if (!it->second.p_lib) {
HVLog("Cannot initialize VLC engine");
return -1;
}
// Set up logging
libvlc_log_set(it->second.p_lib, s_vlc_logcb, nullptr);
libvlc_media_t *p_url = libvlc_media_new_location(it->second.p_lib, url.c_str());
it->second.p_player = libvlc_media_player_new_from_media(p_url);
libvlc_media_release(p_url);
if (it->second.handle)
libvlc_media_player_set_hwnd(it->second.p_player, it->second.handle);
if (libvlc_media_player_play(it->second.p_player) < 0) {
HVLog("HVPlayOpen(%p, %d): cannot play stream %s", p_cam, channel, url.c_str());
return -1;
}
return 0;
For testing, I used this code instead and it works, obviously.
char vlcstr[1024];
snprintf(vlcstr, 1024, "vlc %s --rtsp-user=%s --rtsp-pwd=%s --sout=#file{dst=%s} --vout=dummy -Idummy "
"--ignore-config --quiet --rtsp-frame-buffer-size=500000 --network-caching=4000 &",
ss.str().c_str(), p_camera->getUser().c_str(), p_camera->getPassword().c_str(), it->second.fDump);
HVLog("HVPlayOpen(%p, %d): %s", p_cam, channel, vlcstr);
system(vlcstr);
return 0;
However, I wish to use the library API not the system().
UPDATE 4:
This is the log https://pastebin.com/9zgMQiNL
SOLVED
The issue is addressed using the libvlc_media_add_option() function as show here:
https://forum.videolan.org/viewtopic.php?t=69933
I'm trying to print the document in a GeckoWebBrowser, but documentation is limited and to me, it's not at all clear.
I found some code on the internet that at least communicates with the printer (it starts beeping) but I think the printer is asking for a Letter size paper, but it requires the settings to be from print.GetGlobalPrintSettingsAttribute(), if I try my own settings, it gives me a NotImplementedException.
I suspect this is exception is raised on my Gecko.PrinterSettings, because when I swap ps in the print.Print(ps, null);
with the global settings, this exception isn't raised.
The code below:
var domWindow = browser.Window.DomWindow;
var print = Gecko.Xpcom.QueryInterface<Gecko.nsIWebBrowserPrint>(domWindow);
Gecko.PrintSettings ps = new Gecko.PrintSettings();
ps.SetPrintSilentAttribute(false);
ps.SetPrintToFileAttribute(false);
ps.SetShowPrintProgressAttribute(false);
ps.SetOutputFormatAttribute(1); //2 == PDF, so I assume 1 is actual printer
ps.SetPrintBGImagesAttribute(true);
ps.SetStartPageRangeAttribute(1);
ps.SetEndPageRangeAttribute(100);
ps.SetPrintOptions(2, true); // evenPages
ps.SetPrintOptions(1, true); // oddpages
ps.SetEffectivePageSize(768 * 20f, 1024 * 20f);
ps.SetShrinkToFitAttribute(true);
ps.SetScalingAttribute(1.0);
ps.SetPrintBGImagesAttribute(true);
print.Print(ps, null);
Managed to come up with a solution.
What was throwing an exception was
public void SetPersistMarginBoxSettingsAttribute(bool aPersistMarginBoxSettings)
{
throw new NotImplementedException();
}
The above is in PrinterSettings.cs, so it is hard-coded coded to throw a NotImplementedException on a number off attributes (the attribute above isn't the only one hard-coded to throw the exception) as it is not finished(?), so I cannot use it.
However, I can use the GetGlobalSettingsAttribute() as it uses the same interface as PrinterSettings (nsiPrintSettings), so therefore it will have the same attributes all populated for me.
So what can I do is:
I simply copy the GetGlobalPrintSettingsAttribute() into my own printer settings, and adjust them as necessary.
var mySettings = print.GetGlobalPrintSettingsAttribute();
mySettings.SetPrintSilentAttribute(true);
mySettings.SetPrintToFileAttribute(true);
mySettings.SetShowPrintProgressAttribute(false);
mySettings.SetOutputFormatAttribute(2); //2 == PDF
mySettings.SetToFileNameAttribute(#"c:\temp\temp.pdf");
mySettings.SetPrintBGImagesAttribute(true);
mySettings.SetStartPageRangeAttribute(1);
mySettings.SetEndPageRangeAttribute(100);
mySettings.SetPrintOptions(2, true); // evenPages
mySettings.SetPrintOptions(1, true); // oddpages
mySettings.SetShrinkToFitAttribute(true);
mySettings.SetScalingAttribute(1.0);
mySettings.SetPrintBGImagesAttribute(true);
print.Print(mySettings, new Gecko.WebProgressListener());
Please notice I reverted back to PDF for now, in the SetOutputFormatAttribute(2); //2 == PDF
Also changed the print.Print(ps, null); to print.Print(mySettings, new Gecko.WebProgressListener()); but I think having null or Gecko.WebProgressListener() won't make a difference.
Et voilĂ ! - Now, onto the next step, which is to print to a printer, and not as a PDF file.
Here's an example 204 I have made. It validates with a couple different validation tools (EDI Notepad and Altova), but when I try to use EDI fabric to parse it, it gets the ISA and GS data just fine, but then errors out with "Invalid Node Name: ST".
I can't figure out why, any ideas?
ISA*ZZ* *ZZ* *ZZ*XXXX *ZZ*YYYY *170130*1025*U*00401*485789958*0*P*~
GS*SM*YYYY*XXXX*20170130*1027*485790079*X*004010
ST*204*485790093
B2**YYYY**123456789**CC
B2A*00
L11*123456789*CR
S5*1*LD
G62*64*20160131*1*1351
SE*7*485790093
GE*1*485790079
IEA*1*485789958
Here is the code:
internal static void Parse204(FileStream file,
List<MyCompany.TruckRouteInfo> result)
{
var reader = EdiFabric.Framework.Readers.X12Reader.Create(file);
file.Flush();
var qEdiItems = reader.ReadToEnd();
var ediItems = qEdiItems.ToList();
var m204 = ediItems.OfType<M_204>().ToList();
foreach (var item in m204)
{
MyCompany.TruckRouteInfo stop = new MyCompany.TruckRouteInfo ();
foreach (var l11 in item.S_L11)
{
if (l11.D_128_2 == EdiFabric.Rules.X12004010204.X12_ID_128.CR)
{
stop.Reference1 = l11.D_127_1;
}
}
result.Add(stop);
}
}
I've just literally copied your example and pasted it to a file which was processed fine. Works on my machine :)
My best guess would be to open the file and inspect the line terminators for any discrepancies, which might have been sorted when I copied it\pasted it.
can't run the automated project in testcomplete when calls from jenkins.
In our continuous integration part ,the project is automated using testcomplete and it is calling through jenkins with the help of bat file.The scripts inside the bat file is
"C:\Program Files\Automated QA\TestComplete 7\Bin\TestComplete.exe " "D:\Test Complete7 Projects\ProjectInput_AllSamples\ProjecInputs.pjs" /r /p:Samples /rt:Main "iexplore" /e
It will open testcomplete and iexplorer ,but it is not filling the data(automation).
It is working perfectly when we directly call the bat file with out jenkins.Is there any solution
From your description it sounds like something in Windows stopping you from allowing your test application to work normally. It might be the fact that the second user could be a problem but I can't confirm that as I was not able find any definite explanations of how it works in Windows XP. I am pretty sure that this won't work on a Windows Vista, 7, 8 or server machine though because of the changes in architecture.
It sounds like the best solution is to make sure that your automated UI tests are started by an interactive user. When I was trying to add automated testing to our builds we used TestComplete 7 on a Windows XP SP2 virtual machine. In order to start our tests as an interactive user we:
Made an user log on when windows started, this way there was always an interactive user which means there was an actual desktop session which has access to the keyboard / mouse. I seem to remember (but can't find any links at the moment) that without an interactive user there is no active desktop that can access the keyboard / mouse.
We wrote a little app that would start when the interactive user logged on. This app would look at a specific file and when that file changed / was created it would read the file and start the application. The code for this app looked somewhat like this:
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
namespace ApplicationStarter
{
class Program
{
// The string used to indicate that the application should quit.
private const string ExitString = "exit";
// The path which is being watched for changes.
private static string s_LoadFilePath;
static void Main(string[] args)
{
try
{
{
Debug.Assert(
args != null,
"The arguments array should not be null.");
Debug.Assert(
args.Length == 1,
"There should only be one argument.");
}
s_LoadFilePath = args[0];
{
Console.WriteLine(
string.Format(
CultureInfo.InvariantCulture,
"Watching: {0}",
s_LoadFilePath));
}
if (File.Exists(s_LoadFilePath))
{
RunApplication(s_LoadFilePath);
}
using (var watcher = new FileSystemWatcher())
{
watcher.IncludeSubdirectories = false;
watcher.NotifyFilter =
NotifyFilters.LastAccess
| NotifyFilters.LastWrite
| NotifyFilters.FileName
| NotifyFilters.DirectoryName;
watcher.Path = Path.GetDirectoryName(s_LoadFilePath);
watcher.Filter = Path.GetFileName(s_LoadFilePath);
try
{
watcher.Created += OnConfigFileCreate;
watcher.EnableRaisingEvents = true;
// Now just sit here and wait until hell freezes over
// or until the user tells us that it has
string line = string.Empty;
while (!string.Equals(line, ExitString, StringComparison.OrdinalIgnoreCase))
{
line = Console.ReadLine();
}
}
finally
{
watcher.Created -= OnConfigFileCreate;
}
}
}
catch (Exception e)
{
Console.WriteLine(e);
}
}
private static void RunApplication(string configFilePath)
{
var appPath = string.Empty;
var arguments = string.Empty;
using (var reader = new StreamReader(configFilePath, Encoding.UTF8))
{
appPath = reader.ReadLine();
arguments = reader.ReadLine();
}
// Run the application
StartProcess(appPath, arguments);
}
private static void StartProcess(string path, string arguments)
{
var startInfo = new ProcessStartInfo();
{
startInfo.FileName = path;
startInfo.Arguments = arguments;
startInfo.ErrorDialog = false;
startInfo.UseShellExecute = true;
startInfo.RedirectStandardOutput = false;
startInfo.RedirectStandardError = false;
}
Console.WriteLine(
string.Format(
CultureInfo.InvariantCulture,
"{0} Starting process {1}",
DateTime.Now,
path));
using (var exec = new Process())
{
exec.StartInfo = startInfo;
exec.Start();
}
}
private static void OnConfigFileCreate(
object sender,
FileSystemEventArgs e)
{
Console.WriteLine(
string.Format(
CultureInfo.InvariantCulture,
"{0} File change event ({1}) for: {2}",
DateTime.Now,
e.ChangeType,
e.FullPath));
// See that the file is there. If so then start the app
if (File.Exists(e.FullPath) &&
string.Equals(s_LoadFilePath, e.FullPath, StringComparison.OrdinalIgnoreCase))
{
// Wait for a bit so that the file is no
// longer locked by other processes
Thread.Sleep(500);
// Now run the application
RunApplication(e.FullPath);
}
}
}
}
This app expects the file to have 2 lines, the first with the app you want to start and the second with the arguments, so in your case something like this:
C:\Program Files\Automated QA\TestComplete 7\Bin\TestComplete.exe
"D:\Test Complete7 Projects\ProjectInput_AllSamples\ProjecInputs.pjs" /r /p:Samples /rt:Main "iexplore" /e
You should be able to generate this file from Jenkins in a build step.
Finally you may need to watch the TestComplete process for exit so that you can grab the results at the end but I'll leave that as an exercise to reader.
If you are running Jenkins (either master or slave) as a windows service, ensure it is running as a user and not as Local System.
We also do the same as Gentlesea's recommends, we run TestExecute on our Jenkins Slaves and keepo the TestComplete licenses for the people designing the TestComplete scripts.
I'm using the RawPrinterHelper class from Microsoft, http://support.microsoft.com/kb/322091, to print to a Zebra KR403 printer from C# code, and everything is working fine.
I wish to monitor the status of the printer for paper jams and paper outages. I've found a query that I can send to the printer, "~HQES" or "esc eng 6", that will return everything I need. The problem is that I can not figure out how to send this query to the printer that will allow the printer to respond. The WritePrinter in the RawPrinterHelper class only seems to return a bool or long type.
I also tried using a Win32_printer object to find the PrinterStatus/PrinterState/Errors of the printer. using the following method:
public static string PrinterStateCheck(string szPrinterName)
{
string query = string.Format("SELECT * from Win32_Printer WHERE Name LIKE '%{0}%'", szPrinterName);
ManagementObjectSearcher searcher = new ManagementObjectSearcher(query);
ManagementObjectCollection collection = searcher.Get();
string errorName = "";
foreach (ManagementObject printer in collection)
{
int state = Convert.ToInt32(printer["PrinterState"]);
errorName = state.ToString();
}
return errorName;
Utilizing this method, I tried getting the PrinterState, PrinterStatus, and DetectedErrorState, but none of these respond with the information I need. PrinterState always returns a 1024, PrinterStatus always returns a 4, and DetectedErrorState always returns a 2. Though PrinterState did return a 0 on a proper printing and 1024 on a paperjam or media out event for a few prints, now it just returns 1024 on every call.
I have also found that Zebra created their own software for monitoring printers on a network. The problem is our printers are not on a network and are only connected to the client computer via USB. Also, we are hoping to check the status of the printer prior to or after each receipt is printed.
I am hoping there is something from the winspool.Drv that I can use to send raw data to the printer and receive data back from the printer.
Now I'm using the ReadPrinter function of the winspool.Drv, but the function is returning 0 which means that a response from the printer cannot be accessed. This usually means that the printer is not setup for bidirectional communication, but I'm sure that it is. The "Enable bidirectional support" check box is checked in the "Ports" tab of the Printer Properties. Also, the Zebra Setup Utilities can correctly query the printer and receive a response in its Direct Communication window.
Thanks for any advice,
Jeremy
I've done something very similar and i can tell you that there is almost no way at all to monitor print jobs in .NET.
I've gotten close though, doing the following:
Create a "PrinterDiagnosticsFacade" that queries both the .NET PrintQueue object's status and WMI. Neither are always accurate. Merge the data from both to decide the printer's true status.
Adjust the printer's settings so that print jobs stay in the queue. That way you can accurately read the print job's status by doing a WMI query for the print spool jobs. (You can match against the print filename)
Thats how i got close to getting at printer status.
Adding in code to show how its done using the .NET print queue object:
See http://msdn.microsoft.com/en-us/library/system.printing.printqueue.aspx for the printqueue object that starts the code off
PrintQueue me = Queue;
if (me != null)
{
me.Refresh();
//in this if else,
//i purposefully put the ones that error out first
//so that if multiple can be true at the same time
//the errors will definitely take precedence
if (me.HasPaperProblem)
{
_SystemDotPrintingStatus = new PrinterStatus(PrinterStatusType.Error, "Error: Has paper problem");
}
else if (me.IsDoorOpened)
{
_SystemDotPrintingStatus = new PrinterStatus(PrinterStatusType.Error, "Error: Door is open");
}
else if (me.IsManualFeedRequired)
{
_SystemDotPrintingStatus = new PrinterStatus(PrinterStatusType.Error, "Error: Printer needs manually fed");
}
else if (me.IsNotAvailable)
{
_SystemDotPrintingStatus = new PrinterStatus(PrinterStatusType.Error, "Error: Printer not available");
}
else if (me.IsOutOfMemory)
{
_SystemDotPrintingStatus = new PrinterStatus(PrinterStatusType.Error, "Error: Printer is out of memory");
}
else if (me.IsOutOfPaper)
{
_SystemDotPrintingStatus = new PrinterStatus(PrinterStatusType.Error, "Error: Printer is out of paper");
}
else if (me.IsOutputBinFull)
{
_SystemDotPrintingStatus = new PrinterStatus(PrinterStatusType.Error, "Error: Printer output bin is full");
}
else if (me.IsPaperJammed)
{
_SystemDotPrintingStatus = new PrinterStatus(PrinterStatusType.Error, "Error: Paper jam");
}
else if (me.IsOffline)
{
_SystemDotPrintingStatus = new PrinterStatus(PrinterStatusType.Offline, "Offline");
}
else if (me.IsBusy)
{
_SystemDotPrintingStatus = new PrinterStatus(PrinterStatusType.Busy, "Busy");
}
else if (me.IsInitializing)
{
_SystemDotPrintingStatus = new PrinterStatus(PrinterStatusType.Busy, "Initializing");
}
else if (me.IsIOActive)
{
_SystemDotPrintingStatus = new PrinterStatus(PrinterStatusType.Busy, "Sending and recieving data");
}
else if (me.IsProcessing)
{
_SystemDotPrintingStatus = new PrinterStatus(PrinterStatusType.Busy, "Processing");
}
else if (me.IsWarmingUp)
{
_SystemDotPrintingStatus = new PrinterStatus(PrinterStatusType.Busy, "Warming up");
}
else if (me.IsPendingDeletion)
{
_SystemDotPrintingStatus = new PrinterStatus(PrinterStatusType.Busy, "Deleting a job");
}
else if (me.IsPaused)
{
_SystemDotPrintingStatus = new PrinterStatus(PrinterStatusType.Paused, "Paused");
}
else if (me.IsPrinting)
{
_SystemDotPrintingStatus = new PrinterStatus(PrinterStatusType.Printing, "Printing");
}
else if (me.IsPowerSaveOn)
{
_SystemDotPrintingStatus = new PrinterStatus(PrinterStatusType.Ready, "In power save mode");
}
else
_SystemDotPrintingStatus = new PrinterStatus(PrinterStatusType.Ready, "Ready");
}
The solution to the problem that we ended up utilizing was to create a WinUSB driver for the printer. This way the device is treated as a USB device. A ZebraUSB object was created using the driver and a method called WriteRead was created. Using the WriteRead method we sent the ~HQES query to the printer and received a response. Sometimes there is some lag time between the query and the response. To combat this, we set the response to a variable and retrieve it using a different method.
I'm not sure of the specifics of the code because I did not code the WinUSB driver, and I do not have access to its code.
The main point of this answer is that we had to create a WinUSB driver for the printer before any of the status queries could work.