How to list only printers in JavaFX Print Dialog? - printing

Is it possible to list only printers in the JavaFX Print Dialog ?
example for use of Print Dialog :
...
final PrinterJob printerJob = PrinterJob.createPrinterJob();
ret = printJob.showPrintDialog(owner);
...
Thank you in advance
Fabrice

Related

Preset output filename & Bypass 'Save As' dialogue after sending document to pdf printer VB6

Working on a legacy application. im looking for a way to preset the output filename & Bypass 'Save As' dialogue after sending document to pdf printer VB6. Im printing a report but i want to programmatically set the filename and avoid seeing the 'save as' common dialog. Pls help
'Determine Default Printer
Dim PrintData As Printer
Dim defprinterpos%
Lstprinter.Clear
For Each PrintData In Printers
' Add printer name and port to list
Lstprinter.AddItem PrintData.DeviceName '& " at: " & PrintData.Port
' Check for default printer
If PrintData.DeviceName = Printer.DeviceName Then defprinterpos = Lstprinter.NewIndex
Next
Lstprinter.ListIndex = defprinterpos%
frmmain.lblPrinter.Caption = Lstprinter.List(Lstprinter.ListIndex)
' SetPrinter ("Microsoft Print to PDF")
If Check4.Value = 1 Then
Dim PrinterName As String
PrinterName = "Microsoft Print to PDF" '"CutePDF Writer"
Dim w As New WshNetwork
w.SetDefaultPrinter (PrinterName)
Set w = Nothing
End If
' print the Sales Invoice
rptsales.printreport

Xojo Print Without Printer Dialog

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

How to get a JS script console output in TWebbrowser?

I want to run a javascript code in TWebbrowser and get the console output of it. For instance, if i run this code in the console :
var a = 2; var b = 3; var c = a +b ; console.log('The result is '+ c);
I get this output on console :
The result is 5
The code i use to run a JS script with TWebbrowser is this :
twebbrowser1.navigate('javascript:var a = 2; var b = 3; var c = a +b ; console.log('The result is '+ c);');
It works, but i don't know how to get the console output. Is there a way to do it ?
Thanks in advance !
According to MSDN, it looks like your (Delphi) app would need to implement the IDeveloperConsoleMessageReceiver interface.
Then you can connect an object instance of your IDeveloperConsoleMessageReceiver to the browser's current Document. Query the TWebBrowser.Document property for its IOleCommandTarget interface and then call its Exec() method to issue a IDM_ADDCONSOLEMESSAGERECEIVER command.
Try that, and if you get stuck, try asking again.

print A4 doc on letter us size using pdfbox

I would like to print a PDF document created with A4 format on a printer that is using US letter paper.
First, my method to print the doc on a printer with A4 format.
public static void printWithPdfBox(String strFilename) throws IOException, PrinterException
{
PrinterJob job = PrinterJob.getPrinterJob();
System.out.println("Printer name : "+ job.getPrintService().getName());
PDDocument doc = new PDDocument();
doc = PDDocument.load(strFilename);
PrintRequestAttributeSet attributes = new HashPrintRequestAttributeSet();
attributes.add(Sides.ONE_SIDED);
job.setPageable(new PDPageable(doc, job));
job.print(attributes);
}
I tried to add this attribute but it is not working :
attributes.add(MediaSizeName.NA_LETTER);
In the help of print method, it is mentionned :
Note that some attributes may be set directly on the PrinterJob by equivalent method calls, (for example), copies: setcopies(int), job name: setJobName(String) and specifying media size and orientation though the PageFormat object.
If someone has a solution, I'll apreciate his help ;o)

active reports always sends to default printer

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

Resources