2015-05-13 4 views
2

У меня возникли проблемы с преобразованием Word Document в PDF. В моем документе слова, шрифт это (Times New Roman):Как сохранить свойства шрифта текстовых документов при преобразовании в PDF

enter image description here

но при преобразовании в PDF, он стал:

enter image description here

Я использовал следующий код:

 Word._Application oWord = new Word.Application(); 

     // Make this instance of word invisible (Can still see it in the taskmgr). 
     oWord.Visible = false; 

     // Interop requires objects. 
     object oMissing = System.Reflection.Missing.Value; 
     object isVisible = true; 
     object readOnly = false; 
     object oInput = Application.StartupPath+"\file.docx"; 
     object oOutput = Application.StartupPath+"\file.docx".Replace(".docx", ".pdf"); 
     object oFormat = Word.WdSaveFormat.wdFormatPDF; 

     // Load a document into our instance of word.exe 
     Word._Document oDoc = oWord.Documents.Open(ref oInput, ref oMissing, ref readOnly, 
      ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, 
      ref oMissing, ref oMissing, ref isVisible, ref oMissing, ref oMissing, ref oMissing, ref oMissing); 

     // Make this document the active document. 
     oDoc.Activate(); 

     // Save this document in Word 2003 format. 
     oDoc.SaveAs(ref oOutput, ref oFormat, ref oMissing, ref oMissing, ref oMissing, 
      ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, 
      ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing); 

     // Always close Word.exe. 
     oWord.Quit(ref oMissing, ref oMissing, ref oMissing); 

Что я буду делать, чтобы преобразовать документ Word в PDF, сохраняя его свойства шрифта?

ответ

2

У меня недавно была аналогичная проблема. Мой шрифт не изменится, но другие элементы форматирования Word будут потеряны/изменены при использовании метода Word.Interop SaveAs. Вот метод, который я использовал, который исправил проблему для меня. В приведенном ниже примере используются приложение и документ вместо вашего _Application и _Document. Я не знаком с различиями в них, но думаю, что он должен работать с любым методом.

bool _OpenAfterExport = false; 
bool _KeepIRM = true; 
int _From = 1; 
int _To = 1; //I thought this was odd, setting From and To to 1, but it exported all pages of the document 
bool _IncludeDocProps = true; 

Word.Document oDoc = oWord.Documents.Open(inputFile); 
oDoc.ExportAsFixedFormat(outputFile, 
         Word.WdExportFormat.wdExportFormatPDF, 
         OpenAfterExport, 
         Word.WdExportOptimizeFor.wdExportOptimizeForPrint, 
         Word.WdExportRange.wdExportAllDocument, 
         _From, 
         _To, 
         Word.WdExportItem.wdExportDocumentContent, 
         _IncludeDocProps, 
         _KeepIRM, 
         Word.WdExportCreateBookmarks.wdExportCreateHeadingBookmarks) 
oDoc.Close(); 
oWord.Quit(); 
System.Runtime.InteropServices.Marshal.ReleaseComObject(oDoc); 

Надеюсь, что эта проблема решена.

+0

Я переустановил все свои PDF-ридеры и заменил свой код на этот код. Теперь это совершенно исправлено.^_^спасибо тонну. , , – ThEpRoGrAmMiNgNoOb

+0

Не проблема. Я обнаружил, что работа с Word и PDF иногда может быть немного сложной. – SimTrooper

Смежные вопросы