I am implementing the JFX Printing API using Brother QL720NW Printer with the 62mm Wide Paper size, for some reason I get the "Bad Margins" Exception. How do I go round this here is the code:
try
{
Printer printer = Printer.getDefaultPrinter();
Paper photo = PrintHelper.createPaper("LabelPrinter", 62.0, 89.8, Units.MM);
PageLayout pageLayout = printer.createPageLayout(photo, PageOrientation.LANDSCAPE, Printer.MarginType.HARDWARE_MINIMUM);
PrinterAttributes attr = printer.getPrinterAttributes();
PrinterJob job = PrinterJob.createPrinterJob();
double scaleX = pageLayout.getPrintableWidth() / node.getBoundsInParent().getWidth();
double scaleY = pageLayout.getPrintableHeight() / node.getBoundsInParent().getHeight();
Scale scale = new Scale(scaleX, scaleY);
node.getTransforms().add(scale);
JobSettings jobsettings = job.getJobSettings();
jobsettings.setPageLayout(pageLayout);
if (job != null) {
boolean success = job.printPage(node);
if (success) {
job.endJob();
}
}
node.getTransforms().remove(scale);
}
catch(Exception e)
{
System.out.println(e.getMessage());
}
The Node used to Print is a simple Label that I am using for testing purposes. After I get a print out then I will implement a bigger node to print exact parameters required.
Let me know if this code is ok. or needs some refactoring.
thanks in advance
The Answer was in the printing settings of the actual printer for anyone seeking the answer here is a link for a solution:
https://forum.sambapos.com/t/how-to-change-the-printer-size-paper/10442/11
Related
I'm developing a Codename One app for iOS.
I gave the user the option to take pictures or to load them from the gallery of the device. After that, the app shows pictures in labels (encapsulated in a BoxLayout).
When I take pictures in portrait mode, everything perfectly works, but when I take pictures in landscape mode, that picture is shown rotated (a 90° rotation).
Here is the code:
String filePath = Capture.capturePhoto();
if (filePath != null) {
try {
Image img = Image.createImage(filePath);
if (img != null){
setImageToContainer(img);
}
}
catch (IOException err) {
ToastBar.showErrorMessage("Problemi con le immagini: " + err.getMessage());
completeImageName = null;
fileImageName = null;
}
}
private void setImageToContainer(Image img){
Label imgLbl = new Label();
Style s = UIManager.getInstance().getComponentStyle("Button");
FontImage p = FontImage.createMaterial(FontImage.MATERIAL_PORTRAIT, s);
EncodedImage placeholder = EncodedImage.createFromImage(p.scaled(p.getWidth() * 3, p.getHeight() * 4), false);
imgLbl.setIcon(placeholder);
list.add(imgLbl);
//Scalo l'immagine
if(img.getWidth() > imgLbl.getParent().getWidth())
img = img.scaledWidth(imgLbl.getParent().getWidth());
if(img.getHeight()> imgLbl.getParent().getHeight())
img = img.scaledHeight(imgLbl.getParent().getHeight());
imgLbl.setIcon(img);
list.repaint();
}
Reading that answer, I understood Image.createImage(filePathToImage) method takes in account EXIF data, in order to properly rotate the image.
How can I solve my problem? Is there a way to get EXIF data?
With the help of this question I was able to figure out how I can display a link inside a StyledText widget in SwT. The color is correct and even the cursor changes shape when hovering over the link.
So far so good, but the link is not actually clickable. Although the cursor changes its shape, nothing happens if clicking on the link. Therefore I am asking how I can make clicking the link to actually open it in the browser.
I thought of using a MouseListener, tracking the click-location back to the respective text the click has been performed on and then deciding whether to open the link or not. However that seems way too complicated given that there already is some routine going on for changing the cursor accordingly. I believe that there is some easy way to do this (and assuring that the clicking-behavior is actually consistent to when the cursor changes its shape).
Does anyone have any suggestions?
Here's an MWE demonstrating what I have done so far:
public static void main(String[] args) throws MalformedURLException {
final URL testURL = new URL("https://stackoverflow.com/questions/1494337/can-html-style-links-be-added-to-swt-styledtext");
Display display = new Display();
Shell shell = new Shell(display);
shell.setLayout(new GridLayout(1, true));
StyledText sTextWidget = new StyledText(shell, SWT.READ_ONLY);
final String firstPart = "Some text before ";
String msg = firstPart + testURL.toString() + " some text after";
sTextWidget.setText(msg);
sTextWidget.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
StyleRange linkStyleRange = new StyleRange(firstPart.length(), testURL.toString().length(), null, null);
linkStyleRange.underline = true;
linkStyleRange.underlineStyle = SWT.UNDERLINE_LINK;
linkStyleRange.data = testURL.toString();
sTextWidget.setStyleRange(linkStyleRange);
shell.open();
while(!shell.isDisposed()) {
display.readAndDispatch();
}
}
Okay I was being a little too fast on posting this question... There's a snippet that deals with exactly this problem and it shows, that one indeed has to use an extra MouseListener in order to get things working.
The snippet can be found here and this is the relevant part setting up the listener:
styledText.addListener(SWT.MouseDown, event -> {
// It is up to the application to determine when and how a link should be activated.
// In this snippet links are activated on mouse down when the control key is held down
if ((event.stateMask & SWT.MOD1) != 0) {
int offset = styledText.getOffsetAtLocation(new Point (event.x, event.y));
if (offset != -1) {
StyleRange style1 = null;
try {
style1 = styledText.getStyleRangeAtOffset(offset);
} catch (IllegalArgumentException e) {
// no character under event.x, event.y
}
if (style1 != null && style1.underline && style1.underlineStyle == SWT.UNDERLINE_LINK) {
System.out.println("Click on a Link");
}
}
}
});
I'm trying to add barcode scanner feature to my xamarin.ios app. I'm developing from visual studio and I've added the Zxing.Net.Mobile component from xamarin components store.
I've implemented it as shown in the samples:
ScanButton.TouchUpInside += async (sender, e) => {
//var options = new ZXing.Mobile.MobileBarcodeScanningOptions();
//options.AutoRotate = false;
//options.PossibleFormats = new List<ZXing.BarcodeFormat>() {
// ZXing.BarcodeFormat.EAN_8, ZXing.BarcodeFormat.EAN_13
//};
var scanner = new ZXing.Mobile.MobileBarcodeScanner(this);
//scanner.TopText = "Hold camera up to barcode to scan";
//scanner.BottomText = "Barcode will automatically scan";
//scanner.UseCustomOverlay = false;
scanner.FlashButtonText = "Flash";
scanner.CancelButtonText = "Cancel";
scanner.Torch(true);
scanner.AutoFocus();
var result = await scanner.Scan(true);
HandleScanResult(result);
};
void HandleScanResult(ZXing.Result result)
{
if (result != null && !string.IsNullOrEmpty(result.Text))
TextField.Text = result.Text;
}
The problem is that when I tap the scan button, the capture view is shown correctly but if I try to capture a barcode nothing happens and it seems the scanner doesn't recognize any barcode.
Someone has experienced this issue? How can I made it work?
Thanks in advance for your help!
I answered a similar question here. I couldn't get barcodes to scan because the default camera resolution was set too low. The specific implementation for this case would be:
ScanButton.TouchUpInside += async (sender, e) => {
var options = new ZXing.Mobile.MobileBarcodeScanningOptions {
CameraResolutionSelector = HandleCameraResolutionSelectorDelegate
};
var scanner = new ZXing.Mobile.MobileBarcodeScanner(this);
.
.
.
scanner.AutoFocus();
//call scan with options created above
var result = await scanner.Scan(options, true);
HandleScanResult(result);
};
And then the definition for HandleCameraResolutionSelectorDelegate:
CameraResolution HandleCameraResolutionSelectorDelegate(List<CameraResolution> availableResolutions)
{
//Don't know if this will ever be null or empty
if (availableResolutions == null || availableResolutions.Count < 1)
return new CameraResolution () { Width = 800, Height = 600 };
//Debugging revealed that the last element in the list
//expresses the highest resolution. This could probably be more thorough.
return availableResolutions [availableResolutions.Count - 1];
}
In this the error being displayed is mentioned below. I have searched online for the right answer none is applicable so far. I am trying to toast a simple message upon detecting a sudden change in the accelerometer readings so as to detect a fall. I don't think there is any other mistake in the code, if there is you are most welcome to rectify it.
Error: cannot find symbol method maketext(MainActivity,String,int)
This is my Code:
#Override
public void onSensorChanged(SensorEvent event) {
if (started) {
double x = event.values[0];
double y = event.values[1];
double z = event.values[2];
long timestamp = System.currentTimeMillis();
Data data = new Data(timestamp, x, y, z);
sensorData.add(data);
}
if(event.sensor.getType()==Sensor.TYPE_ACCELEROMETER){
double gacc=SensorManager.STANDARD_GRAVITY;
double a=event.values[0];
double b=event.values[1];
double c=event.values[2];
long mintime=System.currentTimeMillis();
boolean min = false;
boolean max = false;
int m = 0;
double xyz=Math.round(Math.sqrt(Math.pow(a,2)+Math.pow(b,2)+Math.pow(c,2)));
if(xyz<=3.0){
min = true;
}
if(min==true){
m++;
if(xyz>=14){
max=true;
}
}
if(min && max==true){
Toast.maketext(MainActivity.this,"FALL DETECTED!",Toast.LENGTH_LONG).show();
m=0;
min=false;
max=false;
}
if (m>4) {
m=0;
min=false;
max=false;
}
}
}
You are calling maketext instead of makeText. Note that camelCase.
Replace with:
Toast.makeText(MainActivity.this,"FALL DETECTED!",Toast.LENGTH_LONG).show();
After you correct it, make sure that you are using the android.widget.Toast.
I am using Label printer QL-700 from Brother and trying to print a label with image on it.
I am using the following test code :
string templatePath = TEMPLATE_DIRECTORY;
// None decoration frame
if (cmbTemplate.SelectedIndex == 0)
{
templatePath += TEMPLATE_SIMPLE;
}
// Decoration frame
else
{
templatePath += TEMPLATE_FRAME;
}
bpac.DocumentClass doc = new DocumentClass();
if (doc.Open(templatePath) != false)
{
try
{
//doc.GetObject("objCompany").Text = txtCompany.Text;
//doc.GetObject("objName").Text = txtName.Text;
// doc.SetMediaById(doc.Printer.GetMediaId(), true);
doc.SetPrinter("Brother QL-700", true);
bpac.Object ob = doc.GetObject("Photo");
//ob.SetData(0, #"C:\Photo\635466380534236711.png", 4);
doc.StartPrint("", PrintOptionConstants.bpoDefault);
doc.PrintOut(1, PrintOptionConstants.bpoDefault);
doc.EndPrint();
doc.Close();
}
catch(Exception ex)
{
}
}
I have a template and at the runtime I set the image. But the thing is its printing the image too dark. Can anybody suggest how can I fix it ?
I tried
- Changing the brightness of the Printer Properties
- Tried changing the Brightness of the image in the Default image on the Template.
Nothing worked.
Anybody, anything - please suggest.