More pre-defined zoom levels

Good morning,

I am wondering, if it is possible to expand the pre-defined zoom levels in the combobox for the PdfViewer. I searched the documentation, but was not able to find a guide in how to achieve it. There are instructions on how to set it programmatically. But that's not what I need.

ZoomLevelsPdfViewer.png

Our customer has some PDFs which are really big. And to get a better overview they would like to zoom out more then the combobox offers. I already set the minimum zoomlevel to 10% and the maximum zoom level to 600%.  But as soon as you reach 50% zoom level, the zoom out button gets disabled. You can further zoom to 10% via control + mouse wheel or by entering the number directly into the textfield, but it would be really great, if it is possible to expand the pre-defined zoom levels.


With regards



6 Replies 1 reply marked as answer

DD Divya Dhayalan Syncfusion Team November 19, 2021 12:24 AM UTC

Hi Jenny, 
 
Considering different PDF document page size, we are using the default minimum zoom percentage as 50 and maximum zoom percentage as 400. But we can achieve your requirement of setting zoom level from 10% by creating a customized combo box.  We have created a sample for your reference, and which can be downloaded from the below link, 
 
In this sample, we have removed the existing “Zoom Combo Box”, zoom increase and decrease button from the DocumentToolbar and added custom controls.  
1.       CustomZoomComboBox for zoom level – It’s a combo box with items starts from 10 to 600. In the ComboBox SelectionChanged event handler zooming to the selected value is handled using ZoomTo method. 
2.       ZoomOutBtn and ZoomInBtn for increase and decrease zoom value – In the button click event, based on the current zoom value the combo box is set to select particular index to change the PDF Viewer Zoom value 
Note:  We need to set the MinimumZoomPercentage value to 10 and MaximumZoomPercentage to 600. 
 
Please let us know if the provided sample and details helps to achieve your requirement. 
 
Regards, 
Divya 



JE Jenny Eichhorn November 19, 2021 07:10 AM UTC

Hello Divya,


the provided solution looks good so far. The only issue i have now is the mousewheel event. Using ctrl + mousewheel does not change the value of the CustomComboBox. Is there a way to overwrite or replace the default event, so that it influences the custom combobox instead?
Or maybe even unsubscribe all event so that ctrl + mousewheel doesn't zoom anymore?


With regards



DD Divya Dhayalan Syncfusion Team November 22, 2021 05:58 PM UTC

Hi Jenny, 
 
Thank you for the update. 
 
We are currently checking on this to achieve your requirement of changing the zoom level in custom zoom combo box based on mousewheel zooming or preventing the zoom while “ctrl + mousewheel” access. We will update further details on 25th November 2021. 
 
Regards, 
Divya  



DD Divya Dhayalan Syncfusion Team November 25, 2021 02:42 PM UTC

Hi Jenny, 
 
Thank you for your patience. 
 
We have modified the sample to achieve your requirement of changing the custom zoom combobox value based on zoom changes while using control + mouse wheel. The sample can be downloaded from the below link. 
 
We have achieved the requirement by making the below changes with the custom combo box. 
 
Step 1: Use the Combo box text value and set it as editable when initialization. 
CustomZoomComboBox.Text = "100%"; 
CustomZoomComboBox.IsEditable = true;             
 
Step 2: Rise the PdfViewer ZoomChanged event and set the combo box text value based on the PdfViewer current zoom percentage. 
 
//Rise the zoom changed value 
pdfViewer.ZoomChanged += PdfViewer_ZoomChanged; 
 
private void PdfViewer_ZoomChanged(object sender, ZoomEventArgs args) 
        { 
            int zoomValue = pdfViewer.ZoomPercentage; 
            if (zoomValue < pdfViewer.MinimumZoomPercentage) 
                zoomValue = pdfViewer.MinimumZoomPercentage; 
            if (zoomValue > pdfViewer.MaximumZoomPercentage) 
                zoomValue = pdfViewer.MaximumZoomPercentage; 
             
            //Set the custom zoom combobox value based on current zoom percentage of PDF Viewer 
            CustomZoomComboBox.Text = zoomValue.ToString() + "%";             
        } 
 
We have also done the implementation for, changing the combo box text value and PdfViewer Zoom value when is there any manual modification on the combo box value using combo box keyDown event 
//Rise ComboBox mouse down event 
CustomZoomComboBox.KeyDown += CustomZoomComboBox_KeyDown; 
 
private void CustomZoomComboBox_KeyDown(object sender, System.Windows.Input.KeyEventArgs e) 
        { 
            ComboBox zoomBox = sender as ComboBox; 
            if (e.Key == Key.Enter) 
            { 
                string zoomEntered = zoomBox.Text; 
                int magnificationValue; 
                if (zoomEntered.Contains("%")) 
                { 
                    int index = zoomEntered.IndexOf('%'); 
                    zoomEntered = zoomEntered.Substring(0, index); 
                } 
                int.TryParse(zoomEntered, out magnificationValue); 
                if (magnificationValue < pdfViewer.MinimumZoomPercentage) 
                    magnificationValue = pdfViewer.MinimumZoomPercentage; 
                if (magnificationValue > pdfViewer.MaximumZoomPercentage) 
                    magnificationValue = pdfViewer.MaximumZoomPercentage; 
 
                pdfViewer.ZoomTo(magnificationValue); 
                CustomZoomComboBox.Text = magnificationValue.ToString() + "%"; 
            } 
        } 
 
Please check the above details and sample and let us know if the above solution is helpful to achieve your requirement or if you need any further assistance on this. 
 
Regards, 
Divya 


Marked as answer

JE Jenny Eichhorn December 1, 2021 09:59 AM UTC

Hi Divya,


sorry for the delayed feedback, but I finally got to implement your solution and it looks solid.

I had to do a little bit of tweaking regarding the zoom in and zoom out buttons.


private void ZoomOutBtn_Click(object sender, RoutedEventArgs e)
{
int currentZoomLevel = GetCurrentZoomLevel();
int index = GetComboBoxItemIndex(string.Format("{0}%", currentZoomLevel));
if (index - 1 >= 0)
{
CustomZoomComboBox.SelectedIndex = index - 1;
}
else
{
for (int i = 0; i < CustomZoomComboBox.Items.Count; i++)
{
if (i + 1 < CustomZoomComboBox.Items.Count)
{
if (currentZoomLevel >= Convert.ToInt32(CustomZoomComboBox.Items[i]) && currentZoomLevel < Convert.ToInt32(CustomZoomComboBox.Items[i + 1]))
{
CustomZoomComboBox.SelectedIndex = i;
break;
}
}
}
}
ZoomBtnChanges();
}


The problem was, if you zoom via mouse wheel and then try to use the zoom buttons it would end up in the else-case which in turn throws an exception, because you can't convert "10%" to an int. I managed to avoid the exception by triming the % from the string:


string valueAtIndex = CustomZoomComboBox.Items[i].ToString().TrimEnd('%');
string valueAtNextIndex = CustomZoomComboBox.Items[i + 1].ToString().TrimEnd('%');
if (currentZoomLevel >= Convert.ToInt32(valueAtIndex) && currentZoomLevel < Convert.ToInt32(valueAtNextIndex))

Thank you very much for your help.

With kind tegards



DD Divya Dhayalan Syncfusion Team December 2, 2021 05:20 PM UTC

Hi Jenny, 
 
Sorry for the inconvenience caused. 
 
As mentioned in you update, we can avoid the exception while clicking the zoom in and zoom out button by trimming the “%” character. Please let us know if you need any further assistance on this. 
 
Regards, 
Divya  


Loader.
Up arrow icon