How can I prevent the Print Progress dialog appearing when performing a print preview
I hate to answer my own question, but the solution was staring me in the face.
As I've already coded the ability to print a delivery note, my next step was to provide an on screen copy (i.e. no intention of printing a hard copy). The print preview dialog seemed like an easy way out.
In the end, I just created a custom form and painted directly on to it with no print preview control in sight.
Unfortunately, I got too focused on trying to get the print preview dialogue to behave as I wanted, rather than looking at the bigger problem.
PrinterToPrint without showing the print job Progress dialog
Update:
UIPrinterPickerController
comes from UIKit
and as such there is no way to push the "printing" process to the background and off the main UI thread.
In the current UIPrintInteractionController.PrintToPrinter
implementation (currently up to iOS 10.3 B4) there is no exposed way to disable the print progress (Connecting, Preparing, etc...) alart/dialog (w/ Cancel button) or to modify its appearance.
This interface is high level wrapper using AirPrint
and thus Internet Print Protocol (IPP) at a lower level to preform the actual printing, job queue monitoring on the printer, etc... IPP is not currently exposed as a publicly available framework within iOS...
Programs that allow background printing are not using UIPrintInteractionController
to do the printing. Most do use UIPrinterPickerController
to obtain a UIPrinter
selection from the user, but then use the UIPrinter.Url.AbsoluteUrl
to "talk" directly to the printer via HTTP/HTTPS Post/Get. Depending upon the printers used, TCP-based sockets are also an option vs. IPP and even USB/serial for direct connected printers.
Re: https://en.wikipedia.org/wiki/Internet_Printing_Protocol
Original:
Pick a Printer:
if (allowUserToSelectDifferentPrinter || printerUrl == null)
{
UIPrinter uiPrinter = printerUrl != null ? null as UIPrinter : UIPrinter.FromUrl(new NSUrl(printerUrl));
var uiPrinterPickerController = UIPrinterPickerController.FromPrinter(uiPrinter);
uiPrinterPickerController.Present(true, (printerPickerController, userDidSelect, error) =>
{
if (userDidSelect)
{
uiPrinter = uiPrinterPickerController?.SelectedPrinter;
printerUrl = uiPrinter.Url.AbsoluteUrl.ToString();
Console.WriteLine($"Save this UIPrinter's Url string for later use: {printerUrl}");
}
});
}
Print using UIPrintInteractionController
with an existing UIPrinter
:
if (printerUrl != null)
{
// re-create a UIPrinter from a saved NSUrl string
var uiPrinter = UIPrinter.FromUrl(new NSUrl(printerUrl));
var printer = UIPrintInteractionController.SharedPrintController;
printer.ShowsPageRange = false;
printer.ShowsNumberOfCopies = false;
printer.ShowsPaperSelectionForLoadedPapers = false;
var printInfo = UIPrintInfo.PrintInfo;
printInfo.OutputType = UIPrintInfoOutputType.General;
printInfo.JobName = "StackOverflow Print Job";
var textFormatter = new UISimpleTextPrintFormatter("StackOverflow Rocks")
{
StartPage = 0,
ContentInsets = new UIEdgeInsets(72, 72, 72, 72),
MaximumContentWidth = 6 * 72,
};
printer.Delegate = new PrintInteractionControllerDelegate();
printer.PrintFormatter = textFormatter;
printer.PrintToPrinter(uiPrinter, (printInteractionController, completed, error) =>
{
if ((completed && error != null))
{
Console.WriteLine($"Print Error: {error.Code}:{error.Description}");
PresentViewController(
UIAlertController.Create("Print Error", "Code: {error.Code} Description: {error.Description}", UIAlertControllerStyle.ActionSheet),
true, () => { });
}
printInfo?.Dispose();
uiPrinter?.Dispose();
uiPrinter.
});
}
else
{
Console.WriteLine("User has not selected a printer...printing disabled");
}
ProgressBar disappears when displaying print preview
It not a real solution to this problem but I fount a workaround. Instead of using ProgressBarRenderer
, I draw the rectangles.
The OnPaint
method is now :
protected override void OnPaint(PaintEventArgs e)
{
Rectangle rect = ClientRectangle;
using (SolidBrush brush = new SolidBrush(BackColor))
e.Graphics.FillRectangle(brush, rect);
e.Graphics.DrawRectangle(Pens.Black, rect.X, rect.Y, rect.Width - 2, rect.Height - 2);
rect.Inflate(-3, -3);
if (Value > 0)
{
Rectangle clip = new Rectangle(rect.X, rect.Y, (int)Math.Round(((float)Value / Maximum) * rect.Width), rect.Height);
using (SolidBrush brush = new SolidBrush(ForeColor))
e.Graphics.FillRectangle(brush, clip);
}
using (Font f = new Font(sgvDesigner.FontFamily, 12))
{
String text = getDisplayText();
SizeF len = e.Graphics.MeasureString(text, f);
Point location = new Point(Convert.ToInt32((Width / 2) - len.Width / 2), Convert.ToInt32((Height / 2) - len.Height / 2));
e.Graphics.DrawString(text, f, TextColor, location);
}
return;
}
The progressBar looks like this :
How do I remove the time from printpreview dialog?
Albo,
I think it might be useful to set a breakpoint at
'//draw the cell text
g.DrawString(PrintGrid.Cell(i, j).CText, PrintGrid.Cell(i, j).Font, New SolidBrush(PrintGrid.ForeColor), New RectangleF(CurrentX - PrintGrid.Cell(i, j).Width, CurrentY, PrintGrid.Cell(i, j).Width, PrintGrid.Cell(i, j).Height), sf)
To see exactly what's going on. Without running such a breakpoint, and from this resource here, my first guess might be something like this:
If j = PrintGrid.Columns - 1 Then
Dim pattern As String = "MM-dd-yy"
If DateTime.TryParseExact(PrintGrid.Cell(i, j).CText, pattern, Nothing, DateTimeStyles.None, PrintGrid.Cell(i, j).CText) Then
g.DrawString(PrintGrid.Cell(i, j).CText, PrintGrid.Cell(i, j).Font, New SolidBrush(PrintGrid.ForeColor), New RectangleF(CurrentX - PrintGrid.Cell(i, j).Width, CurrentY, PrintGrid.Cell(i, j).Width, PrintGrid.Cell(i, j).Height), sf)
Else
g.DrawString(PrintGrid.Cell(i, j).CText, PrintGrid.Cell(i, j).Font, New SolidBrush(PrintGrid.ForeColor), New RectangleF(CurrentX - PrintGrid.Cell(i, j).Width, CurrentY, PrintGrid.Cell(i, j).Width, PrintGrid.Cell(i, j).Height), sf)
End If
This attempts to parse the text of the column (in your case, the PrintGrid.Columns - 1th cell) as a date, if it succeeds, then it puts the newly formatted text back into the column before it sends it to the print sub. I highly doubt this code would work as-is, but with some debugging and application of correct string to datetime formatting...I think this is the right direction.
Flutter: Progress dialog is not hiding
Try with :
onTap: () async {
pr.show();
print('clicked custom category');
print(categorylist[index].catName);
print(categorylist[index].catId);
setState(() {
catId = categorylist[index].catId;
myinitlist.clear();
myinitlist = List.from(productList);
Future.delayed(Duration(seconds: 3)).then((value) {
pr.hide().whenComplete(() {
print(pr.isShowing());
});
});
});
},
or :
onTap: () async {
pr.show();
print('clicked custom category');
print(categorylist[index].catName);
print(categorylist[index].catId);
Future.delayed(Duration(seconds: 3)).then((value) {
setState(() {
catId = categorylist[index].catId;
myinitlist.clear();
myinitlist = List.from(productList);
pr.hide().whenComplete(() {
print(pr.isShowing());
});
});
});
},
Print Preview Control used in a custom Print Preview Dialog
I'm a bit puzzled by this line:
m_printPreviewControl = new PrintPreviewControl();
You don't seem to attach or position this control.
If you placed it with the Designer, this line should be removed, and you should use the name of the designtime control everywhere..
If you want to create it manually, you need atr least something like this.Controls.Add(m_printPreviewControl );
Related Topics
Automatic Enhancement of Scanned Images
How to Count Rows Within Entityframework Without Loading Contents
C# How to Check If a Url Exists/Is Valid
How to Add Json to Restsharp Post Request
Removing Text Between 2 Strings
Newtonsoft Json Dynamic Property Name
Reportviewer: Show Reports in Print Layout With Page Width Zoommode
C# Double - Tostring() Formatting With Two Decimal Places But No Rounding
Check If a File Is Real or a Symbolic Link
Post Byte Array to Web API Server Using Httpclient
How to Use a Class from One C# Project With Another C# Project
How to Store List of Data from Database to Arraylist or List in C#
Read and Parse a Json File in C#
How to Cast a List into a Type Which Inherits from List<T>
Securely Store a Password in the Application in C#
Find First Digit of a Number Using Only Integer Operations
Choosing the Default Value of an Enum Type Without Having to Change Values