2X faster development
The ultimate UWP UI toolkit to boost your development speed.
Syncfusion Essential DocIO Renderer is a .NET Core Word to PDF conversion library allows you to convert Word document to PDF in UWP application [C#]. Steps to convert Word document to PDF programmatically in UWP:
XAML <Page x:Class="WordToPDF.MainPage" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:local="using:WordToPDF" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" mc:Ignorable="d" Background="{ThemeResource ApplicationPageBackgroundThemeBrush}"> <Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}"> <Button x:Name="button" Content="Generate PDF" Click="OnButtonClicked" HorizontalAlignment="Center" VerticalAlignment="Center"/> </Grid> </Page>
C# using Syncfusion.DocIO.DLS; using Syncfusion.DocIORenderer; using Syncfusion.Pdf;
C# private async void OnButtonClicked(object sender, RoutedEventArgs e) { //Creates an instance of WordDocument Instance (Empty Word Document) WordDocument wordDocument = new WordDocument(); //Add a section and a paragraph in the empty document wordDocument.EnsureMinimal(); //Append text to the last paragraph of the document wordDocument.LastParagraph.Text = "Adventure Works Cycles, the fictitious company on which the" + " AdventureWorks sample databases are based, is a large, multinational manufacturing company. "; //Instantiation of DocIORenderer for Word to PDF conversion DocIORenderer render = new DocIORenderer(); //Converts Word document into PDF document PdfDocument pdfDocument = render.ConvertToPDF(wordDocument); //Releases all resources used by the Word document and DocIO Renderer objects render.Dispose(); wordDocument.Dispose(); //Saves the PDF file MemoryStream outputStream = new MemoryStream(); pdfDocument.Save(outputStream); //Closes the instance of PDF document object pdfDocument.Close(); outputStream.Position = 0; //Save the PDF file SavePDF(outputStream); } private async void SavePDF(Stream outputStream) { StorageFile stFile; if (!(Windows.Foundation.Metadata.ApiInformation.IsTypePresent("Windows.Phone.UI.Input.HardwareButtons"))) { FileSavePicker savePicker = new FileSavePicker(); savePicker.DefaultFileExtension = ".pdf"; savePicker.SuggestedFileName = "Sample"; savePicker.FileTypeChoices.Add("Adobe PDF Document", new List<string>() { ".pdf" }); stFile = await savePicker.PickSaveFileAsync(); } else { StorageFolder local = Windows.Storage.ApplicationData.Current.LocalFolder; stFile = await local.CreateFileAsync("Sample.pdf", CreationCollisionOption.ReplaceExisting); } if (stFile != null) { Windows.Storage.Streams.IRandomAccessStream fileStream = await stFile.OpenAsync(FileAccessMode.ReadWrite); Stream st = fileStream.AsStreamForWrite(); st.SetLength(0); st.Write((outputStream as MemoryStream).ToArray(), 0, (int)outputStream.Length); st.Flush(); st.Dispose(); fileStream.Dispose(); MessageDialog msgDialog = new MessageDialog("Do you want to view the Document?", "File created."); UICommand yesCmd = new UICommand("Yes"); msgDialog.Commands.Add(yesCmd); UICommand noCmd = new UICommand("No"); msgDialog.Commands.Add(noCmd); IUICommand cmd = await msgDialog.ShowAsync(); if (cmd == yesCmd) { // Launch the retrieved file bool success = await Windows.System.Launcher.LaunchFileAsync(stFile); } } }
A complete working example of how to convert Word document to PDF in UWP using .NET Core Word to PDF conversion library can be downloaded from Word to PDF in UWP.zip. Take a moment to peruse the documentation, where you can find basic Word document processing options along with features like mail merge, merge and split documents, find and replace text in the Word document and protect the Word documents with code examples. Explore more about the rich set of Syncfusion Word Framework features. See Also: Mail merge Word document in UWP Note:
|
2X faster development
The ultimate UWP UI toolkit to boost your development speed.
This page will automatically be redirected to the sign-in page in 10 seconds.