question

RezaJaferi1992 avatar image
0 Votes"
RezaJaferi1992 asked RezaJaferi1992 edited

Reverse printing problem from right to left in WPF (by C#)

First and foremost, I apologize for my grammatical errors; my first language is Persian (Iran).
I have a problem when I try to print from right to left, you can see my details and problem in this link:
printing-groupbox-without-using-printdialog-in-wpf.html
Thanks


dotnet-csharpwindows-wpfdotnet-wpf-xaml
· 5
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Hi,@ RezaJafery. How do you print from right to left? Please show me the relevant code. And could you show me the specific string of Persian you want to print?

0 Votes 0 ·

Hi, I use the code you gave me in this link: printing-groupbox-without-using-printdialog-in-wpf.html
126063-reverse-image.png
126017-true-image.png


0 Votes 0 ·
reverse-image.png (22.3 KiB)
true-image.png (22.3 KiB)

when I print in Persian (with your code) the output is first image "This is an inverted image", I changed the second image by rotating it horizontally.

0 Votes 0 ·
Show more comments
RezaJaferi1992 avatar image
0 Votes"
RezaJaferi1992 answered RezaJaferi1992 edited

I found the solution. To solve this problem, we can use ScaleTransform class.
First: we must use this <ElementName.RenderTransform> <ScaleTransform ScaleX="{Binding}"/> <ElementName.RenderTransform/> in XAML.
For example:

                  <Grid x:Name="PrintPreview_Grid" Height="206" Width="398" Margin="1,0,1,0">
                    <Grid.RenderTransform>
                      <ScaleTransform ScaleX="{Binding}"/>
                    </Grid.RenderTransform>
                  </Grid>

Then I used the following code for printing:

     private void PrintButton_PreviewMouseLeftButtonDown(object sender, MouseButtonEventArgs e)
     {
         switch (App.EnumLanguage)
         {
             //For left to right languages
             case AllLanguage.English:
                 (PrintPreview_Grid.RenderTransform as ScaleTransform).ScaleX = 1;
                 break;
             //For right to left languages
             default:
                 (PrintPreview_Grid.RenderTransform as ScaleTransform).ScaleX = -1;
                 break;
         }
         PrintDialog PD = new PrintDialog();
         var Printer = new LocalPrintServer().GetPrintQueues();
         //We can change the name of the printer we want
         var SelectedPrinter = Printer.FirstOrDefault(P => P.Name == "Microsoft Print to PDF");
         PD.PrintQueue = SelectedPrinter;
         var Size = new Size(PD.PrintableAreaHeight, PD.PrintableAreaWidth);
         PrintPreview_Grid.Measure(Size);
         PrintPreview_Grid.Arrange(new Rect(new Point(29, 0), Size));
         PD.PrintVisual(PrintPreview_Grid, "Print");
         //To return to the default state
         (PrintPreview_Grid.RenderTransform as ScaleTransform).ScaleX = 1;
     }

Result for left-to-right languages:
127352-left-to-right.gif
Result for right-to-left languages:
127361-right-to-left.gif
Thanks



left-to-right.gif (2.5 MiB)
right-to-left.gif (2.0 MiB)
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

HuiLiu-MSFT avatar image
0 Votes"
HuiLiu-MSFT answered

Your print result is the same as the window display. To print the result from right to left, we can set the window content from right to left.
I added FlowDirection="RightToLeft" to the GroupBox and the code is as follows:
The updated code is as follows:

 <GroupBox x:Name="PrintPreview_GroupBox" Header="Preview" Width="400" Height="250" Background="Transparent" 
                       HorizontalAlignment="Left" Visibility="Visible" Margin="14,228,0,14" FlowDirection="RightToLeft"  >
 Your code…
 </GroupBox>

The print result is as shown in the figure:
126221-2.png


For the flow direction of specific strings, you could refer to here.


If the response is helpful, please click "Accept Answer" and upvote it.
 Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread. 


2.png (67.8 KiB)
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.