C# UWP Printing "Keine installierten Komponenten gefunden. (Exception from HRESULT: 0x800F1000)" (No installed components found.)
I want to print in my UWP App. I create a SortedList of RelativePanels which i fill with controls. The PrintPreview appears correct with the first RelativePanel of the SortedList. But when i want to switch to next PrintPage, this means the next RelativPanel in the SortedList, the following Error appeears:
Message "Keine installierten Komponenten gefunden. (Exception from HRESULT: 0x800F1000)"
What can be the reason?
.NET
Universal Windows Platform (UWP)
-
Junjie Zhu - MSFT 15,211 Reputation points • Microsoft Vendor
2023-02-06T03:15:43.4+00:00 Hello @Markus Schertler ,
Welcome to Microsoft Q&A!
Could you provide a code sample that can reproduce the problem?
-
Markus Schertler 41 Reputation points
2023-02-06T06:23:52.55+00:00 Hello Junjie,
the error came because I was aligning the individual elements relative to each other in the RelativePanel. To do this, I remember the last element added and then align a new one with it.
So far I had no page break and only printed one page. Of course, when changing pages, an element in the new RelativePanel must not be aligned with an element of the RelativePanel on the previous page. Therefore came the error message.
But now there is a new problem:
I take 1000 as the page size for DIN A4 and add the FontSize and the Margin to the PageSizeFilled variable each time an element is added. If adding a element would make the PageSizeFilled larger than 1000 I do a page break. I.e. I add a new Relative Panel to the SortedList and continue with it.
But now it is the case that the last lines of the previous page appear again on the next page???
-
Markus Schertler 41 Reputation points
2023-02-06T06:24:06.31+00:00 Here is my Print Class. The method PrintPagesAdd is called to add Elements to the PrintPages.
namespace P19.Print { public class Print_Cls { // [XmlIgnore] // public PrintManager printMan; [XmlIgnore] public PrintDocument printDoc; [XmlIgnore] public IPrintDocumentSource printDocSource; private int print_page_size_height = 1000; private int print_page_size_widht = 794; private SortedList<int, RelativePanel> printpage_List = new SortedList<int, RelativePanel>(); private RelativePanel printpage_m = new RelativePanel(); int printpage_m_filled = 0; // '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' public void PrintPages_Clear() // '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' { printpage_List.Clear(); PrintPage_Add(); } // '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' public void PrintPage_Add() // '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' { printpage_m = new RelativePanel(); printpage_m_filled = 0; printpage_m.Height = print_page_size_height; printpage_m.Width = print_page_size_widht; printpage_m.Padding = new Thickness(35, 35, 25, 20); printpage_List.Add(printpage_List.Count + 1, printpage_m); } // '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' public void PrintPages_Add(FrameworkElement frameworkelement_p, bool new_line_to_last_add, ref bool printpage_new_added) // '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' { // Called before Printing. // // frameworkelement_p: Input Parameter. The element to add to the PrinPage. // // new_line_to_last_add: Input Parameter. frameworkelement_p // would be aligned in the same line if false. // // printpage_new_added: Output parameter. If true frameworkelement_p // is on a new page. double d_size; printpage_new_added = false; if (new_line_to_last_add) { if (frameworkelement_p.GetType() == typeof(Control)) { d_size = ((Control)frameworkelement_p).FontSize; } else if (frameworkelement_p.GetType() == typeof(TextBlock)) { d_size = ((TextBlock)frameworkelement_p).FontSize; } else { throw new ArgumentException(nameof(PrintPages_Add) + " argument has wrong type."); } d_size += frameworkelement_p.Margin.Top; if ((printpage_m_filled + (int)d_size) > print_page_size_height) { PrintPage_Add(); printpage_new_added = true; } // Im Paginate ist noch Initialize der PrintPage List printpage_m_filled += (int)d_size; } printpage_m.Children.Add(frameworkelement_p); } public void OnNavigatedTo_For_Print() { // Register for PrintTaskRequested event PrintManager printMan = PrintManager.GetForCurrentView(); printMan.PrintTaskRequested += PrintTaskRequested; // Build a PrintDocument and register for callbacks printDoc = new PrintDocument(); printDocSource = printDoc.DocumentSource; printDoc.Paginate += CreatePrintPreviewPages; ; printDoc.GetPreviewPage += GetPrintPreviewPage; printDoc.AddPages += AddPrintPages; } public void OnNavigatedFrom_For_Print() { if (printDoc == null) { return; } printDoc.Paginate -= CreatePrintPreviewPages; printDoc.GetPreviewPage -= GetPrintPreviewPage; printDoc.AddPages -= AddPrintPages; // Remove the handler for printing initialization. PrintManager printMan = PrintManager.GetForCurrentView(); printMan.PrintTaskRequested -= PrintTaskRequested; } public async void Print_Click() { await Print(); } private async Task Print() { // Initialize. if (PrintManager.IsSupported()) { try { // Show print UI // Es wird PrintTaskRequested aufgerufen. await PrintManager.ShowPrintUIAsync(); } catch { // Printing cannot proceed at this time ContentDialog noPrintingDialog = new ContentDialog() { Title = "Printing error", Content = "\nSorry, printing can' t proceed at this time.", PrimaryButtonText = "OK" }; await noPrintingDialog.ShowAsync(); } } else { // Printing is not supported on this device ContentDialog noPrintingDialog = new ContentDialog() { Title = "Printing not supported", Content = "\nSorry, printing is not supported on this device.", PrimaryButtonText = "OK" }; await noPrintingDialog.ShowAsync(); } } private void PrintTaskRequested(PrintManager sender, PrintTaskRequestedEventArgs args) { // Create the PrintTask. // Defines the title and delegate for PrintTaskSourceRequested var printTask = args.Request.CreatePrintTask("Print", PrintTaskSourceRequested); // Handle PrintTask.Completed to catch failed print jobs printTask.Completed += PrintTaskCompleted; } private void PrintTaskSourceRequested(PrintTaskSourceRequestedArgs args) { // Set the document source. args.SetSource(printDocSource); } private void CreatePrintPreviewPages(object sender, PaginateEventArgs e) { // Wird vom Paginate Event aufgerufen. // Ermittelt die Anzahl der Seiten die im Preview Fenster angezeigt werden. int printPages; // Get the PrintTaskOptions PrintTaskOptions printingOptions = ((PrintTaskOptions)e.PrintTaskOptions); // Get the page description to deterimine how big the page is // PrintPageDescription pageDescription = printingOptions.GetPageDescription(0); //var k = pageDescription.PageSize.Height; //var j = pageDescription.PageSize.Width; //printLines_Count = 25; // printLines_Count = 5500; printPages = printpage_List.Count; // As I only want to print one Rectangle, so I set the count to 1 printDoc.SetPreviewPageCount(printPages, PreviewPageCountType.Intermediate); } private void GetPrintPreviewPage(object sender, GetPreviewPageEventArgs e) { //GetPrintPage(ref this.Entries_Current_List_ListView_Index_GetPreviewPage, // e.PageNumber, // ref this.PrintPage); //printDoc.SetPreviewPage(e.PageNumber, printpage_List[e.PageNumber]); //printDoc.SetPreviewPage(e.PageNumber, printpage_List[e.PageNumber]); Exception p_ex = null; try { PrintDocument printDoc1 = (PrintDocument)sender; printDoc1.SetPreviewPage(e.PageNumber, printpage_List[e.PageNumber]); } catch (Exception ex) { p_ex = ex; } } private void AddPrintPages(object sender, AddPagesEventArgs e) { for (int i = 1; i <= printpage_List.Count; i++) { printDoc.AddPage(printpage_List[i]); } // Indicate that all of the print pages have been provided printDoc.AddPagesComplete(); } private async void PrintTaskCompleted(PrintTask sender, PrintTaskCompletedEventArgs args) { // Notify the user when the print operation fails. if (args.Completion == PrintTaskCompletion.Failed) { //await CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, async () => { ContentDialog noPrintingDialog = new ContentDialog() { Title = "Printing error", Content = "\nSorry, failed to print.", PrimaryButtonText = "OK" }; await noPrintingDialog.ShowAsync(); //}); } } } } }
-
Junjie Zhu - MSFT 15,211 Reputation points • Microsoft Vendor
2023-02-06T07:29:55.8566667+00:00 Could you please provide details on using
PrintPages_Add
andPrint_Click
. -
Markus Schertler 41 Reputation points
2023-02-07T06:17:15.79+00:00 // Betriebskostenabrechnung_fuer_Mietvertrag_erstellen fills the RelativePanel PrintPage // Collection. // The Call of Print Click is after the filling of the RelativePanel PrintPage Collection. if (entry_m_abrechnung_p != null) { Entry_M_Abrechnung.Entry_M_Abrechnung.Betriebskostenabrechnung_fuer_Mietvertrag_erstellen (entry_m_abrechnung_p, entry_m_mietvertrag_p, ref error_Message_p); entry_m_mietvertrag_p.Print_Cls.Print_Click(); } // Part of Code in // Entry_M_Abrechnung.Entry_M_Abrechnung.Betriebskostenabrechnung_fuer_Mietvertrag_erstellen: Entry_Add_To(BA_Entry_Abrechnung_Title); Align_Options_Set(uiElement_BA_Abrechnung_Entry_M_Abrechnung_Title, relative_panel_alignement_enum_m_1_standard, relative_panel_alignement_enum_m_2_standard); Print_Text(ba_entry_m_objekt_m.Strasse + ", " + ba_entry_m_objekt_m.Postleitzahl + " " + ba_entry_m_objekt_m.Ort); UIElement uiElement_BA_Abrechnung_Adresse = ctr_Align_to_m; Entry_Add_To(BA_Entry_Abrechnung_Title); Align_Options_Set(ctr_Align_to_m, RelativePanel_Alignment_Enum.RightOf, RelativePanel_Alignment_Enum.AlignTopWith); Print_Text(" - " + Objekt_Einheit.Title); Entry_Add_To(BA_Entry_Abrechnung_Title); Align_Options_Set(ctr_Align_to_m, RelativePanel_Alignment_Enum.AlignRightWithPanel, RelativePanel_Alignment_Enum.AlignTopWith); Print_Text(DateTime.Now.Date.ToString("d")); // The Call of Print_Cls.PrintPages_Add: static void Print_Text(string text_p, string text_align_right = "") { bool printpage_new_added_t1 = false; bool printpage_new_added_t2 = false; bool new_line_to_last_add = true; Entry_Add_To_Entry_New_Out_M.Title = text_p; if (Betriebskostenabrechnung_Mietvertrag_m != null) { if (Betriebskostenabrechnung_Mietvertrag_Current_m.ID == Betriebskostenabrechnung_Mietvertrag_m.ID) { t1 = new TextBlock(); // t1 = new TextBox(); t1.Text = text_p; t1.Foreground = new Windows.UI.Xaml.Media.SolidColorBrush(Windows.UI.Colors.Blue); t1.Margin = Margin_m; t1.FontSize = FormatOption_FontSize_m; t1.FontWeight = FormatOption_Font_Weight_m; t1.TextWrapping = TextWrapping.Wrap; t1.MaxWidth = 650; if (relative_panel_alignement_enum_m_1 == RelativePanel_Alignment_Enum.AlignRightWithPanel || relative_panel_alignement_enum_m_1 == RelativePanel_Alignment_Enum.RightOf) { new_line_to_last_add = false; } else { new_line_to_last_add = true; } Betriebskostenabrechnung_Mietvertrag_m.Print_Cls.PrintPages_Add(t1, new_line_to_last_add, ref printpage_new_added_t1); if (printpage_new_added_t1) { Align_Options_Initialize(); } else { if (ctr_Align_to_m != null) { if (relative_panel_alignement_enum_m_1 != RelativePanel_Alignment_Enum.Not_Set) { Relative_Panel_Align(relative_panel_alignement_enum_m_1, t1, ctr_Align_to_m); } if (relative_panel_alignement_enum_m_2 != RelativePanel_Alignment_Enum.Not_Set) { Relative_Panel_Align(relative_panel_alignement_enum_m_2, t1, ctr_Align_to_m); } } } if (text_align_right != "") { t2 = new TextBlock(); // t2 = new TextBox(); t2.Text = text_align_right; t2.Foreground = new Windows.UI.Xaml.Media.SolidColorBrush(Windows.UI.Colors.Blue); t2.Margin = Margin_m; t2.FontSize = FormatOption_FontSize_m; t2.FontWeight = FormatOption_Font_Weight_m; //t1.BorderThickness = new Thickness(0); //t1.AcceptsReturn = true; t2.TextWrapping = TextWrapping.Wrap; // t1.MaxWidth = 550; Betriebskostenabrechnung_Mietvertrag_m.Print_Cls.PrintPages_Add(t2, false, ref printpage_new_added_t2); Relative_Panel_Align(RelativePanel_Alignment_Enum.AlignRightWithPanel, t2, t1); Relative_Panel_Align(RelativePanel_Alignment_Enum.AlignTopWith, t2, t1); } //t1_Before = t1; ctr_Align_to_m = t1; } } }
-
Markus Schertler 41 Reputation points
2023-02-07T06:17:51.9066667+00:00 Following is the Printout. It's just unrealistic test data. I print the data 3 times to create a page feed. This means i call the Method that make the Printout three times.
The last two lines of page 1 also appear on page 2. The first line of Printpage2 should be Radebachweg...
Printpage1:
PrintPage2:
-
Markus Schertler 41 Reputation points
2023-02-07T06:18:07.6133333+00:00 When i change the line in PrintPagesAdd from:
printpage_m_filled += (int)d_size;
to
printpage_m_filled += (int)d_size + 10;
the Printing is ok. I did not found a way to get the position of the new Element in the RelativePanel. This
is what i need to decide if a new page is necessary. -
Junjie Zhu - MSFT 15,211 Reputation points • Microsoft Vendor
2023-02-07T09:08:03.61+00:00 I tried the code you provided, but because there are many controls, I can't reproduce your problem directly, could you reproduce your problem in a new blank project, and share this project without any personal privacy in GitHub.
-
Markus Schertler 41 Reputation points
2023-02-08T12:05:50.0733333+00:00 I need a way to get the position of the new Element, for example a TextBlock, in the RelativePanel. This
is what i need to decide if a new page is necessary. Otherwise i can only appreciate and this is not exact.
-
Junjie Zhu - MSFT 15,211 Reputation points • Microsoft Vendor
2023-02-10T10:18:35.95+00:00 "The position of the new Element"
Could you please explain how this position is calculated, and what position value is valid for your calculation?
It would be better if there are screenshots to explain.
-
Markus Schertler 41 Reputation points
2023-02-10T12:15:16.0433333+00:00 How the position is calculated is now the question.
I want to print in UWP a SortedList of RelativePanel Controls. For each page to print there is one RelativePanel object.
I want to get the position of a control in the RelativePanel. The RelativePanel Control has the size of a printpage. So when i know where a new assigned Control would be in the relative panel then i know when i have to add a new print page.
Here is test data. In a foreloop i print 50 lines of numbers to generate a page break. A new page. For each line
to print there is a new TextBlock filled with the text and added to the relative panel.
I want to know how i can get the position (x, y, the coordinates) which the new textblock will have in the relative
panel. If this is greater then the size (minus the footer) of the printpage a new printpage must bei added.
Fr now i'm just guessing this.
Page 2:
-
Junjie Zhu - MSFT 15,211 Reputation points • Microsoft Vendor
2023-02-15T07:10:48.01+00:00 Hi @Markus Schertler ,
I discussed your question with the team engineers today. In Q&A, it is suggested that there is only one problem in one thread. I suggest you ask the current question again and attach a code sample that can reproduce the problem so that we can better troubleshoot for you.
Thank you.
Sign in to comment
1 answer
Sort by: Most helpful
-
Deleted
This answer has been deleted due to a violation of our Code of Conduct. The answer was manually reported or identified through automated detection before action was taken. Please refer to our Code of Conduct for more information.
Comments have been turned off. Learn more