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
Related
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 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
I have a requirement to Print a bunch of existing PDF files every day to a network Ricoh MP 4000 Printer. I need to print these using "HoldPrint" job type option. I am able to print it directly but I want it to do a hold print which does not mix up with other user's printing. I am using GhostScript 9.10
The one that directly prints (through function call from "Maciej"'s post):
" -dPrinted -dBATCH -dNOPAUSE -dNOSAFER -qQUIET -sjobtype=holdprint -suserid=abc -dNumCopies=1 -sDEVICE=ljet4 -sOutputFile=\"\\spool\PrinterName\" \"C:\Printing\mypdffile.pdf\" "
Looks like I am overwriting the jobtype switch but not sure how to get it.
I tried different combinations but it simply does not work. Any help is greatly appreciated.
-dPrinted -dBATCH -dNOPAUSE -dNumCopies=1 -sDEVICE=ljet4 -sOutputFile=%printer%printerName "C:\Printing\mypdffile.pdf"
Update: Here is the version that worked for me.
/*
* Printer used: Ricoh Aficio MP 4000
* Purpose: To print PDF files as a scheduled job to a network printer.
* The files will be queued under a specific user id.
* The user prints the files under his account.
* Pre-requisite: Install the network printer on the job server
* Manually configure Printer Job settings with user id
* and Job type set to "Hold Print"
*/
string _sourceFolder = “PDFFilesFolderPath”;
DirectoryInfo di = new DirectoryInfo(_sourceFolder);
var files = di.GetFiles().OrderBy(f => f.Name);
string _printer = "BMIS"; // Printer name as seen in the Devices and Printers section
foreach (var f in files)
{
PrintPDF(#"C:\Program Files\gs\gs9.10\bin\gswin32c.exe", 1, _printer, f.FullName);
}
/// <summary>
/// Print PDF.
/// </summary>
/// <param name="ghostScriptPath">The ghost script path. Eg "C:\Program Files\gs\gs9.10\bin\gswin32c.exee"</param>
/// <param name="numberOfCopies">The number of copies.</param>
/// <param name="printerName">Exact name of the printer as seen under Devices and Printers.</param>
/// <param name="pdfFileName">Name of the PDF file.</param>
/// <returns></returns>
public bool PrintPDF(string ghostScriptPath, int numberOfCopies, string printerName, string pdfFullFileName )
{
try
{
ProcessStartInfo startInfo = new ProcessStartInfo();
startInfo.Arguments = " -dPrinted -dNoCancel=true -dBATCH -dNOPAUSE -dNOSAFER -q -dNumCopies=" + Convert.ToString(numberOfCopies) + " -sDEVICE=mswinpr2 -sOutputFile=%printer%" + printerName + " \"" + pdfFullFileName + "\"";
startInfo.FileName = ghostScriptPath;
startInfo.UseShellExecute = false;
startInfo.WindowStyle = ProcessWindowStyle.Hidden;
Process process = Process.Start(startInfo);
process.WaitForExit(30000);
if (process.HasExited == false) process.Kill();
return process.ExitCode == 0;
}
catch (Exception ex)
{
System.Diagnostics.EventLog.WriteEntry("Application", ex.Message, EventLogEntryType.Error);
throw;
}
}
Ghostscript doesn't have a 'jobtype' switch, nor a suserid switch, so its not surprising that they have no effect. Possibly the post you reference has some more information, but I can't find any such post, maybe you can point to it (URL)
[later]
Setup.ps needs to be a PostScript file (because that's what Ghostscript understands, its a PostScript interpreter). From the documentation you want to set DocumentName, which is a member of the User Settings dictionary, so:
mark
/UserSettings <<
/DocumentName (My name goes in here)
>>
(mswinpr2) finddevice
putdeviceprops
setdevice
The white space is just for clarity. This is lifted pretty much verbatim from the example.
So, you need to modify the 'setup.ps' you send for each job. You can either write a custom setup.ps for each one, or use the 'PostScript input' capability of GS and supply the whole content of setup.ps on the command line using the -c and -f switches. All setup.ps does is run the PostScript in there before you run your own PostScript program (assuming you put setup.ps before your PostScript program on the command line).
This is pretty nasty actually, its not the way devices are normally configured, but the mswinpr2 device was originally written by someone outside the Ghostscript team, and presumably adopted wholesale.
stdin.readByteSync has recently been added to Dart.
Using stdin.readByteSync for data entry, I am attempting to allow a default value and if an entry is made by the operator, to clear the default value. If no entry is made and just enter is pressed, then the default is used.
What appears to be happening however is that no terminal output is sent to the terminal until a newline character is entered. Therefore when I do a print() or a stdout.write(), it is delayed until newline is entered.
Therefore, when operator enters first character to override default, the default is not cleared. IE. The default is "abc", data entered is "xx", however "xxc" is showing on screen after entry of "xx". The "problem" appears to be that no "writes" to the terminal are sent until newline is entered.
While I can find an alternative way of doing this, I would like to know if this is the way readByteSync should or must work. If so, I’ll find an alternative way of doing what I want.
// Example program //
import 'dart:io';
void main () {
int iInput;
List<int> lCharCodes = [];
print(""); print("");
String sDefault = "abc";
stdout.write ("Enter data : $sDefault\b\b\b");
while (iInput != 10) { // wait for newline
iInput = stdin.readByteSync();
if (iInput == 8 && lCharCodes.length > 0) { // bs
lCharCodes.removeLast();
} else if (iInput > 31) { // ascii printable char
lCharCodes.add(iInput);
if (lCharCodes.length == 1)
stdout.write (" \b\b\b\b chars cleared"); // clear line
print ("\nlCharCodes length = ${lCharCodes.length}");
}
}
print ("\nData entered = ${new String.fromCharCodes(lCharCodes).trim()}");
}
Results on Command screen are :
c:\Users\Brian\dart-dev1\test\bin>dart testsync001.dart
Enter data : xxc
chars cleared
lCharCodes length = 1
lCharCodes length = 2
Data entered = xx
c:\Users\Brian\dart-dev1\test\bin>
I recently added stdin.readByteSync and readLineSync, to easier create small scrips reading the stdin. However, two things are still missing, for this to be feature-complete.
1) Line mode vs Raw mode. This is basically what you are asking for, a way to get a char as soon as it's printed.
2) Echo on/off. This mode is useful for e.g. typing in passwords, so you can disable the default echo of the characters.
I hope to be able to implement and land these features rather soon.
You can star this bug to track the development of it!
This is common behavior for consoles. Try to flush the output with stdout.flush().
Edit: my mistake. I looked at a very old revision (dartlang-test). The current API does not provide any means to flush stdout. Feel free to file a bug.
I have written an Outlook plugin that basically allows emails being received through Outlook to be linked with a website so that the email can also be view in the communications feature of the website. I store additional details within the ItemProperties of a MailItem, these details are basically things like the id of the user the email relates to within a website.
The problem I'm having is any ItemProperties I add to a MailItem are being printed when the email is printed. Does anyone know how to exclude custom ItemProperties when printing an email?
Here is the code that is creating the custom ItemProperty:
// Try and access the required property.
Microsoft.Office.Interop.Outlook.ItemProperty property = mailItem.ItemProperties[name];
// Required property doesnt exist so we'll create it on the fly.
if (property == null) property = mailItem.ItemProperties.Add(name, Microsoft.Office.Interop.Outlook.OlUserPropertyType.olText);
// Set the value.
property.Value = value;
I'm working on Outlook extension and sometimes ago we had the same issue.
One of our team members found a solution. You can create some method which is responsible for disable printing. You can see peace of our code below:
public void DisablePrint()
{
long printablePropertyFlag = 0x4; // PDO_PRINT_SAVEAS
string printablePropertyCode = "[DispID=107]";
Type customPropertyType = _customProperty.GetType();
// Get current flags.
object rawFlags = customPropertyType.InvokeMember(printablePropertyCode , BindingFlags.GetProperty, null, _customProperty, null);
long flags = long.Parse(rawFlags.ToString());
// Remove printable flag.
flags &= ~printablePropertyFlag;
object[] newParameters = new object[] { flags };
// Set current flags.
customPropertyType.InvokeMember(printablePropertyCode, BindingFlags.SetProperty, null, _customProperty, newParameters);
}
Make sure that _customProperty it is your property which you created by the following code: mailItem.ItemProperties.Add(name,Microsoft.Office.Interop.Outlook.OlUserPropertyType.olText);
On the low (Extended MAPI) level, each user property definition has a flag that determines whether it is printable (namely, PDO_PRINT_SAVEAS). That flag however is not exposed through the Outlook Object Model.
You can either parse the user properties blob and manually set that flag (user properties blob format is documented, and you can see it in OutlookSpy (I am its author) if you click the IMessage button) or you can use Redemption (I am also its author) and its RDOUserProperty.Printable property.
The following script (VB) will reset the printable property for all user propeties of the currently selected message:
set Session = CreateObject("Redemption.RDOSession")
Session.MAPIOBJECT = Application.Session.MAPIOBJECT
set Msg = Session.GetMessageFromID(Application.ActiveExplorer.Selection(1).EntryID)
for each prop in Msg.UserProperties
Debug.Print prop.Name
prop.Printable = false
next
Msg.Save