Articles in this section
Category / Section

How to convert PDF document to Word document in WPF PDF library?

1 min read

The PDF document can be converted to Word document by exporting the PDF document pages as images using PDF library and then the exported images can be added to the WordDocument using the DocIO Library. Please find the code snippet and sample for the same from below link,

 

Code Snippet:

//Creates a new Word document.
WordDocument m_wordDocument = new WordDocument();
 
//Adds new section to the document.
IWSection section = m_wordDocument.AddSection();
 
//Sets the page margins to zero.
section.PageSetup.Margins.All = 0;
 
//Adds new paragraph to the section.
IWParagraph firstParagraph = section.AddParagraph();
 
SizeF defaultPageSize = new SizeF(m_wordDocument.LastSection.PageSetup.PageSize.Width, m_wordDocument.LastSection.PageSetup.PageSize.Height);
 
//Loads the PDF document from the given file path.
using (PdfLoadedDocument m_loadedDocument = new PdfLoadedDocument(m_filePath))
{
        for (int i = 0; I < m_loadedDocument.Pages.Count ; i++)
        {
              //Exports the PDF document page as image with the given size.
              using (Image image = m_loadedDocument.ExportAsImage(i, defaultPageSize,false))
              {
                   //Adds image to the paragraph
                   IWPicture picture = firstParagraph.AppendPicture(image);
 
                  //Sets width and height for the image.
                  picture.Width = image.Width;
                  picture.Height = image.Height;
              }
         }
};
 
//Saves the Word document
m_wordDocument.Save("Save.docx");
 
//Close the document.
m_wordDocument.Dispose();

 

Sample Link: https://www.syncfusion.com/downloads/support/directtrac/general/ze/PDFToWordSample-1317895491.zip

Note:

Since we have achieved the PDF document to Word document by exporting the images from the PDF document, we cannot edit the converted Word document.

 


Conclusion

I hope you enjoyed learning how to convert PDF document to Word document in WPF PDF library.

You can refer to WPF PDF library feature tour page to know about its other groundbreaking feature representations and documentation, and how to quickly get started for configuration specifications. You can also explore our WPF PDF library example to understand how to create and manipulate data.

For current customers, you can check out our components from the License and Downloads page. If you are new to Syncfusion, you can try our 30-day free trial to check out our other controls.

If you have any queries or require clarifications, please let us know in the comments section below. You can also contact us through our support forumsDirect-Trac, or feedback portal. We are always happy to assist you!

Did you find this information helpful?
Yes
No
Help us improve this page
Please provide feedback or comments
Comments (0)
Please sign in to leave a comment
Access denied
Access denied