I have used using Spire.Doc; but it does not chnage more than 3 pages?
private void btnSave_Click(object sender, EventArgs e)
{
//initialize word object
document = new Document();
document.LoadFromFile(samplePath);
//Save doc file.
document.SaveToFile(docxPath, FileFormat.Docx);
//Convert to PDF
document.SaveToFile(pdfPath, FileFormat.PDF);
MessageBox.Show("pdf ", "Message", MessageBoxButtons.OK, MessageBoxIcon.Information);
document.Close();
}
Tuhin PaulPosted Apr 28, 2023, 2:07 AM
Part 2:
Another approach is the OpenXML SDK is a free library from Microsoft that allows you to work with Office documents without requiring Office to be installed on the computer. You can use this library to convert Word documents to PDF.
The C# method converts a Word document (`.docx`) to a PDF file using the `DocumentFormat.OpenXml` and `PdfSharp` libraries.
1. The method takes two parameters, the path to the source Word document (`sourcePath`) and the path to the target PDF file (`targetPath`).
2. The `using` statement is used to create a new `WordprocessingDocument` object and open the source Word document in read-only mode. This ensures that the original Word document is not modified during the conversion process.
3. A new `PdfDocument` object is created to hold the converted PDF content.
4. A new `PdfDocumentRenderer` object is created and initialized with the `WordprocessingDocument`.
5. The `RenderDocument()` method is called on the `PdfDocumentRenderer` object to convert the Word document to PDF.
6. The resulting PDF content is saved to the `targetPath` using the `PdfDocument.Save()` method.
7. The `using` statement closes and disposes of the `WordprocessingDocument`, ensuring that any resources used by the object are properly released.
8. This approach may not work for all Word documents, especially if they contain complex formatting or features that are not supported by the `PdfSharp` library.
Tuhin PaulPosted Apr 28, 2023, 2:04 AM
Part 1:
Why not try Microsoft's Office Interop library. Microsoft.Office.Interop.Word library requires Microsoft Word to be installed on the machine where your app is running. If Word is not installed, this approach won't work. This approach is not supported in non-Windows environments. Make sure to add a reference to the Microsoft.Office.Interop.Word library in your project.
See if this works for you?
Marvin ReidPosted Apr 27, 2023, 8:39 PM
You can convert all the pages of the word file using the DocumentConverter. Here is an example you can try:
https://www.leadtools.com/help/sdk/tutorials/dotnet-fx-winforms-convert-files-with-the-document-converter.html
Naimish MakwanaPosted Feb 13, 2023, 4:03 AM
Hello NURU,
You can try some alternet solution for the same. Please refer below link:
https://www.gemboxsoftware.com/document/examples/c-sharp-convert-word-to-pdf/304
https://products.aspose.com/pdf/
https://stackoverflow.com/a/55334441/3054222
Thanks
Naimish Makwana
Leon DPosted Feb 13, 2023, 1:30 AM
The free version of Spire.Doc only allows you to convert the first 3 pages to PDF. If you want to convert more than 3 pages, you have to use the commercial version, and you can request a free temporary license file by yourself through the link below to remove the evaluation watermark.
https://www.e-iceblue.com/Download/download-word-for-net-now.html
https://www.e-iceblue.com/TemLicense.html