Spire.Doc is a professional Word .NET library specifically designed for developers to create, read, write, convert and print Word document files. Get free and professional technical support for Spire.Doc for .NET, Java, Android, C++, Python.

Thu Oct 03, 2019 3:04 pm

I am converting a word document to PDF in my project. I can open this PDF (either from download or email attachment) in Microsoft Edge without any issues.

However, when I attempt to preview it in Outlook when it is an email attachment, or open the download with Adobe Acrobat Reader, I receive an error that the file is corrupted.

Here's some of my code:

Code: Select all
private string CopyWordDocToDirectoryAsPDF(Report report)
        {
            if (this.fileStream != null)
            {
                this.fileStream.Dispose();
            }

            this.fileStream = new FileStream(report.TempPath, FileMode.Open);
            this.fileStream.Seek(0, SeekOrigin.Begin);

            var doc = new Document();
            doc.LoadFromStream(this.fileStream, FileFormat.Docx);

            var salesSpecPath = Path.Combine(this.outputSettings.SalesSpecDocNetworkPath);
            var engSpecPath = Path.Combine(this.outputSettings.EngSpecDocNetworkPath, this.projTool.OutputValues.IPN);

            Directory.CreateDirectory(salesSpecPath);
            Directory.CreateDirectory(engSpecPath);

            var fileName = report.Filename.Replace(FileExtensions.DOCX, FileExtensions.PDF);

            this.fileStream.Seek(0, SeekOrigin.Begin);
            doc.SaveToFile(Path.Combine(salesSpecPath, fileName), FileFormat.PDF);
            this.fileStream.Seek(0, SeekOrigin.Begin);
            doc.SaveToFile(Path.Combine(engSpecPath, fileName), FileFormat.PDF);

            return Path.Combine(engSpecPath, fileName);
        }

EKMconvertDoc
 
Posts: 6
Joined: Wed Sep 04, 2019 8:13 pm

Fri Oct 04, 2019 3:12 am

Hi,

Thanks for your inquiry.
After an initial test with the latest Spire.Doc Pack(hot fix) Version:7.9.9, I didn't find the issue you mentioned. Please try to use this version. If the issue still exists, please provide your input Word file and the output PDF for further investigation.

Sincerely,
Betsy
E-iceblue support team
User avatar

Betsy.jiang
 
Posts: 3099
Joined: Tue Sep 06, 2016 8:30 am

Fri Oct 04, 2019 1:24 pm

Hi Betsy,

We were already using version 7.9.9 when encountering this error.

I will send the input file and the output PDF file via email soon to support@e-iceblue.com for your team to analyze.

Thank you for helping us with this issue.

EKMconvertDoc
 
Posts: 6
Joined: Wed Sep 04, 2019 8:13 pm

Fri Oct 04, 2019 2:48 pm

FYI, I fixed the issue.

The original file was in a TMP format and that appeared to be the crux of some of these issues. When I convereted the TMP file to a DOCX file (on disk, not in the file stream) then the conversion to PDF was flawless.

Thanks for sparking the troubleshooter in me to solve this issue!

EKMconvertDoc
 
Posts: 6
Joined: Wed Sep 04, 2019 8:13 pm

Mon Oct 07, 2019 1:19 am

Hi,

Sorry for late reply as weekend and I'm delighted to hear that your issue has been resolved.
If you have other question related to our products in the future, please feel free to contact us.
Wish you a nice day :D

Sincerely,
Nina
E-iceblue support team
User avatar

Nina.Tang
 
Posts: 1187
Joined: Tue Sep 27, 2016 1:06 am

Return to Spire.Doc