I would like to print directly to an attached label printer without showing the print dialog.
I have searched to see if such a thing is possible but it seems it is not. So, I thought I would ask here in case someone knows a way to do it.
You have to save the Printer SetupString. Then the next time you go to print use that SetupString to initialize the PrinterSetup object. See actual code copied from working project below:
'Now print the mail barcode
dim ps as PrinterSetup
dim page as Graphics
ps = LabelPrinter //See below
if ps<>nil then
page = OpenPrinter(ps)
if page<>nil then
//send stuff to the printer here
Public Function LabelPrinter() as PrinterSetup
if gLabelSetup<>"" then //gLabelSetup is saved in preferences
dim ps as new PrinterSetup
ps.SetupString = gLabelSetup
return ps
else
return nil
end if
End Function
Related
While trying to automate android native application , Appium is not identify or focus on any single element on second page of native application after automating first page login functionality successfully .I have tried with all wait method and driver. context method but it is now working .I have tried to debug the code with so many wait time but it is not working .When i put a break point after automating first page and tried to debug the application then i observed that if i put any manual action on second page (open window and close same window )then appium is allowing to identify the second page also but i didn't understand why it is happening .By automation script, i am unable to do anything on second page .Could any team help me for the same? Page source code for second page :- "
i have tried with below method for identify the second page..
driver.Manage().Timeouts().ImplicitlyWait(TimeSpan.FromSeconds(30));
ICapabilities caps = driver.Capabilities;
String context = driver.Context;
Console.WriteLine("Current context", context);
driver.Context = ("NATIVE_APP");
String afterloginsource = driver.PageSource;
Console.WriteLine("After loginv page source :- ", afterloginsource);
TouchAction t = new TouchAction(driver);
t.Tap(100, 100).Perform();
driver.Manage().Timeouts().ImplicitlyWait(TimeSpan.FromSeconds(2400));
String loginsource = driver.PageSource;
Console.WriteLine("Befor login page source :- ",loginsource);
driver.HideKeyboard();
//enter valid account
driver.FindElementById("com.Testing:id/userid").SendKeys("00229715");//uat02
// driver.HideKeyboard();
/////driver.FindElement(By.XPath("//android.widget.EditText[#index='1']")).SendKeys("17765919"); ////upn02
///enter valid password
driver.FindElementById("com.Testing:id/password").SendKeys("1");
///click login button
driver.FindElementById("com.Testing:id/login").Click();
driver.Manage().Timeouts().ImplicitlyWait(TimeSpan.FromSeconds(30));
driver.Manage().Timeouts().ImplicitlyWait(TimeSpan.FromSeconds(200));
ICapabilities caps = driver.Capabilities;
String context = driver.Context;
Console.WriteLine("Current context", context);
driver.Context = ("NATIVE_APP");
String afterloginsource = driver.PageSource;
Console.WriteLine("After loginv page source :- ", afterloginsource);
TouchAction t = new TouchAction(driver);
t.Tap(100, 100).Perform();
AndroidElement expandList = driver.FindElementById("com.Testing:id/btn_more_options");
expandList.Click(); Or //((IJavaScriptExecutor)driver).ExecuteScript("mobile: scroll", scrollObject);
//IJavaScriptExecutor js = (IJavaScriptExecutor)driver;
//IWebElement hiddenButton = driver.FindElementById("com.Testing:id/enableNotify");
//String script = "arguments[0].click();";
//js.ExecuteScript(script, hiddenButton);
it is giving error as nosuchelement exception for any element on second page.
NoSuchElement states for inability to find the element. It strongly seems for me that xpath locators to webelements on the page are incorrect.
I do recommend to try out remote debugging just to ensure the locators are organized correctly. And using remote debugging tool - You may also check the locators on-the-fly there.
As an option B) - I could also recommend to take a quick glance towards SeeTest automation tool. The link above guide on how to set up project from scratch, and here is public documentation for SeeTest.
I want to print Notes-documents directly to an pdf-printer. The documents are selected in a view. I do not want to open the printer dialog form.
Using the "NotesUIView.Print"- method works in principle, however, the generated pdf-documents sometimes look not exactly like the Notes-documents (especially regarding tables).
Therefore I tried to use the "NotesUIDocument.Print" - method:
Option Public
Option Explicit
Const pdfAppName = "PDF-XChange Standard"
Dim dc As NotesDocumentCollection
Dim curDoc As NotesDocument
Dim uidoc As NotesUIDocument
Dim workspace As New NotesUIWorkspace
...
Set dc = curDB.UnprocessedDocuments
...
Set curdoc = dc.GetFirstDocument
Call workspace.EditDocument(False,curDoc)
Set uidoc = workspace.Currentdocument
Call uidoc.Print(1,0,0,False,pdfAppName)
...
Dispite the first parameter in "uidoc.print" is set to "1" the printer dialog form opens. In the printer dialog form the printer "PDF-XChange Standard" is selected correctly. Selecting the "OK"-Button prints the document correctly.
Many thanks in advance for hints.
If PROMPT calsue is used in report
REPORT FORM xxx to PRINT PROMPT
User can select printer where report is printed.
How to get this printer name for logging?
https://support.microsoft.com/en-us/help/162798/how-to-use-the-set-printer-to-name-command-to-print-to-a-specified-printer-in-visual-foxpro
Show hot to use GetPrinter() for this. This requires removing PROMPT clause from REPORT
How to get printer where report was printed using PROMPT clause:
REPORT FORM xxx TO PRINT PROMPT
If this possbible, maybe thereis some sys() function or somethis other or is it possible to get printer name during report print ?
Or should this command re-factored not to use PROMPT clause like:
cPrinter = getprinter()
set printer to name (cPrinter)
REPORT FORM xxx TO PRINT
insert into logfile (PrinterUsedForPrinting) values (cPrinter)
I would suggest using your solution of calling GETPRINTER prior to running the report (without the PROMPT clause). In my long experience using FoxPro/VFP I don't think I've come across a way to determine the printer via REPORT FORM...PROMPT.
Here's an example wrapper function that you may find useful. I typically call "PickPrinter" prior to running a report. If PickPrinter returns an empty string, I abort the report run.
FUNCTION PickPrinter
IF APRINTERS(a_printers) < 1
MESSAGEBOX("No printers defined.")
RETURN ""
ELSE
lcPrnChoice = ""
lcPrnChoice = GETPRINTER()
IF EMPTY(lcPrnChoice)
RETURN ""
ELSE
*** Include quotes around the printer name
*** in case there are spaces in the name
lcPrnChoice = "NAME [" + lcPrnChoice + "]"
SET PRINTER TO &lcPrnChoice
RETURN lcPrnChoice
ENDIF
ENDIF
ENDFUNC
I need help with opening the result of my mail merge operations directly in an new writer document.
Object mailMergeService = mcf.createInstanceWithContext(mailMergePackage, context);
XPropertySet mmProperties = UnoRuntime.queryInterface(XPropertySet.class, mailMergeService);
mmProperties.setPropertyValue("DocumentURL", templatePath);
mmProperties.setPropertyValue("DataSourceName", dbName);
mmProperties.setPropertyValue("CommandType", mmCommandType);
mmProperties.setPropertyValue("Command", mmCommand);
mmProperties.setPropertyValue("OutputType", mmOutputType);
// mmProperties.setPropertyValue("OutputURL", templateDirectory);
// mmProperties.setPropertyValue("FileNamePrefix", mmFileNamePrefix);
// mmProperties.setPropertyValue("SaveAsSingleFile", mmSaveAsSingleFile);
The mmOutputType is set as MailMergeType.SHELL
The LibreOffice API documentation says
"The output is a document shell.
The successful mail marge returns a XTextDocument based component."
So I've tried something like this
XJob job = UnoRuntime.queryInterface(XJob.class, mailMergeService);
Object mergedTextObject = job.execute(new NamedValue[0]);
String url = "private:factory/swriter";
loader.loadComponentFromURL(url, "_blank", 0, new PropertyValue[0]);
XTextDocument mergedText = UnoRuntime.queryInterface(XTextDocument.class, mergedTextObject);
XTextCursor cursor = mergedText.getText().createTextCursor();
cursor.setString(mergedText.getText().getString());
I guess I have to pass the XTextDocument component to the url-argument of the loadComponentFromURL method but I didnt find the right way to do that.
When I change the OutputType to MailMergeType.FILE the result is generated in a given directory and I can open the file and see that the mail merge succeeded. But this is not what my application should do.
Does someone know how I can open the result of the mail merge directly in an new writer document without saving the result to the hard drive?
Sincerly arthur
Hey guys I've found a simple way to open the result of my mail merge process directly.
The relevant snippets are these
XJob job = UnoRuntime.queryInterface(XJob.class, mailMergeService);
Object mergedTextObject = job.execute(new NamedValue[0]);
XTextDocument mergedText = UnoRuntime.queryInterface(XTextDocument.class, mergedTextObject);
mergedText.getCurrentController().getFrame().getContainerWindow().setVisible(true);
The last line of code made the window appear with the filled mail merge result.
I also don't need this line anymore
loader.loadComponentFromURL("private:factory/swriter", "_blank", 0, new PropertyValue[0]);
The document opens as a new instance of a swriter document. If you want to save the result as a file you can do this
mergedText.getCurrentController().getFrame().getContainerWindow().setVisible(true);
XStorable storeMM = UnoRuntime.queryInterface(XStorable.class, mergedText);
XModel modelMM = UnoRuntime.queryInterface(XModel.class, mergedText);
storeMM.storeAsURL(outputDirectory + outputFilename, modelMM.getArgs());
Sincerly
Arthur
What version of LO are you using? The SHELL constant has only been around since LO 4.4, and it is not supported by Apache OpenOffice yet, so it could be that it isn't fully implemented. However this code seems to show a working test.
If it is returning an XTextDocument, then normally I would assume the component is already open. However it sounds like you are not seeing a Writer window appear. Did you start LO in headless mode? If not, then maybe the process needs a few seconds before it can display.
Object mergedTextObject = job.execute(new NamedValue[0]);
Thread.sleep(10000);
Anyway to me it looks like your code has a mistake in it. These two lines would simply insert the text onto itself:
XTextCursor cursor = mergedText.getText().createTextCursor();
cursor.setString(mergedText.getText().getString());
Probably you intended to write something like this instead:
XTextDocument mergedText = UnoRuntime.queryInterface(XTextDocument.class, mergedTextObject);
String url = "private:factory/swriter";
XComponent xComponent = loader.loadComponentFromURL(url, "_blank", 0, new PropertyValue[0]);
XTextDocument xTextDocument = (XTextDocument)UnoRuntime.queryInterface(XTextDocument.class, xComponent);
XText xText = (XText)xTextDocument.getText();
XTextRange xTextRange = xText.getEnd();
xTextRange.setString(mergedText.getText().getString());
One more thought: getString() might just return an empty string if the entire document is in a table. If that is the case then you could use the view cursor or enumerate text content.
EDIT:
To preserve formatting including tables, you can do something like this (adapted from https://blog.oio.de/2010/10/27/copy-and-paste-without-clipboard-using-openoffice-org-api/):
// Select all.
XController xMergedTextController = mergedText.getCurrentController();
XTextViewCursorSupplier supTextViewCursor =
(XTextViewCursorSupplier) UnoRuntime.queryInterface(
XTextViewCursorSupplier.class, xMergedTextController);
XTextViewCursor oVC = supTextViewCursor.getViewCursor();
oVC.gotoStart(False) // This would not work if your document began with a table.
oVC.gotoEnd(True)
// Copy and paste.
XTransferableSupplier xTransferableSupplier = UnoRuntime.queryInterface(XTransferableSupplier.class, xMergedTextController);
XTransferable transferable = xTransferableSupplier.getTransferable();
XController xController = xComponent.getCurrentController();
XTransferableSupplier xTransferableSupplier_newDoc = UnoRuntime.queryInterface(XTransferableSupplier.class, xController);
xTransferableSupplier_newDoc.insertTransferable(transferable);
I want to print to a network printer from active reports but it always prints to default printer without throwing error.
Once I try to print with the .net printdocument library it print to specified printer.
I don't know why it is printing to default printer when using activereports.
Set the PrinterName property of the Printer object. Something like the following:
viewer.Document.Printer.PrinterName = "TheNetworkPrinterName";
viewer.Print();
The value of the PrinterName property should be the exact name from windows. To get a list of the valid printer names on a given system you can enumerate the list of printers using PrinterSettings.InstalledPrinters. An example of enumerating the available printers is in the MSDN documentation here.
If you try something and find it doesn't work give us more detailed information and we'll try to help you.
Change printer in end user designer.
Grapecityteam answer:
For a SectionReport, you could inject a Script to change the default printer when the report is loaded, in the LayoutChanged event of the Designer as given below:
private void OnLayoutChanged(object sender, LayoutChangedArgs e)
{
if (e.Type == LayoutChangeType.ReportLoad || e.Type == LayoutChangeType.ReportClear)
{
reportToolbox.Reorder(reportDesigner);
reportToolbox.EnsureCategories();
reportToolbox.Refresh();
RefreshExportEnabled();
CreateReportExplorer();
splitContainerMiddle.Panel2Collapsed = reportDesigner.ReportType == DesignerReportType.Section;
if (reportDesigner.ReportType == DesignerReportType.Section)
{
string script = string.Empty;
script += "public void ActiveReport_ReportStart()";
script += "{";
script += "rpt.Document.Printer.PrinterSettings.PrinterName = System.Drawing.Printing.PrinterSettings.InstalledPrinters[3];";
script += "}";
(reportDesigner.Report as SectionReport).ScriptLanguage = "C#";
(reportDesigner.Report as SectionReport).Script = script;
}
}
thanks to Grapecity Sales and Support