Skip to content

Conversation

@Nandhakumar-SF4686
Copy link
Collaborator

@Nandhakumar-SF4686 Nandhakumar-SF4686 commented Aug 4, 2025

This sample shows how to include the save and open options in the built-in toolbar in .NET MAUI PDF Viewer.

using System.Runtime.Versioning;
using UIKit;

namespace InsertToolbarItems
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you avoid the duplicate codes in mac and iOS by ignoring one file or grouping it?
image

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We have done it platform wise.

Copy link
Collaborator

@Deepak1799 Deepak1799 Aug 11, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it not possible to optimize or use the same iOS.cs in mac?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have optimized it

1. A .NET MAUI project set up.
2. The [Syncfusion.Maui.PdfViewer](https://www.nuget.org/packages/Syncfusion.Maui.PdfViewer) package is installed.

## To Include open and save option in built-in toolbar
Copy link
Collaborator

@Deepak1799 Deepak1799 Aug 11, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

image

Before defining a clicked event, its event handler should not be exposed.

I have previously asked you to implement logic for Open and Save document. You may create as separate method under the topic. Later, call the method in the event handler later.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have followed the outline and changed the content sir


## To Include open and save option in built-in toolbar

To insert an item at a specific index in the toolbar in [SfPdfViewer](https://help.syncfusion.com/cr/maui/Syncfusion.Maui.PdfViewer.SfPdfViewer.html), begin by creating the desired UI element. Next, convert that element into a [ToolbarItem](https://help.syncfusion.com/cr/maui/Syncfusion.Maui.PdfViewer.ToolbarItem.html#Syncfusion_Maui_PdfViewer_ToolbarItem__ctor_Microsoft_Maui_Controls_View_System_String) using the ToolbarItem method. Finally, add the newly created ToolbarItem to the toolbar using the [Insert](https://help.syncfusion.com/cr/maui/Syncfusion.Maui.PdfViewer.ToolbarItemCollection.html#Syncfusion_Maui_PdfViewer_ToolbarItemCollection_Insert_System_Int32_Syncfusion_Maui_PdfViewer_ToolbarItem_) or [Add](https://help.syncfusion.com/cr/maui/Syncfusion.Maui.PdfViewer.ToolbarItemCollection.html#Syncfusion_Maui_PdfViewer_ToolbarItemCollection_Add_Syncfusion_Maui_PdfViewer_ToolbarItem_) method. Here we are using [Insert](https://help.syncfusion.com/cr/maui/Syncfusion.Maui.PdfViewer.ToolbarItemCollection.html#Syncfusion_Maui_PdfViewer_ToolbarItemCollection_Insert_System_Int32_Syncfusion_Maui_PdfViewer_ToolbarItem_) method to include the open and save button in the toolbar item.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is add-on (out of topic), you can better ignore this in readme and implementation
image

Copy link
Collaborator Author

@Nandhakumar-SF4686 Nandhakumar-SF4686 Aug 12, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @Deepak1799 sir,
In the task description, they mentioned to include the DocumentSaveInitiated event sir.
image
So only I have added the DocumentSaveInitiated event topic sir

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have removed the content

this.DocumentSaveInitiated += MainPage_DocumentSaveInitiated;
```

### Step 5: Invoke DocumentSaveInitiated event in the save button event handler.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have changed the content with the outline given sir

options.FileTypes = pdfFileType;
#endif

// Call the method to pick the file and return the result.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use proper null condition instead of null escape operator.
image

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have changed it sir

xmlns:syncfusion="clr-namespace:Syncfusion.Maui.PdfViewer;assembly=Syncfusion.Maui.PdfViewer"
x:Class="InsertToolbarItems.MainPage">


Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove unwanted extra line

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have removed it sir

stream.Seek(0, SeekOrigin.Begin);
}

await stream.CopyToAsync(fileStream).ConfigureAwait(false);
Copy link
Collaborator

@Deepak1799 Deepak1799 Aug 22, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why this copy is required instead of directly used?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have optimized the code sir

Copy link
Collaborator Author

@Nandhakumar-SF4686 Nandhakumar-SF4686 Aug 25, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For optimization I have created a method and used in three platforms sir

Copy link
Collaborator Author

@Nandhakumar-SF4686 Nandhakumar-SF4686 Sep 8, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need to copy the input stream into the file for saving

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

3 participants