이상한 문제가 있습니다. 파일을 채우고 .doc 파일로 변환하는 .dot 파일이 있습니다. 그런 다음이 .doc 파일을 가져 와서 이미지로 변환합니다. 문제는 이미지가 로컬 호스트 (고품질)에서 완벽하며 라이브 서버에서 품질이 매우 낮습니다. 내 질문에, 어떻게 고품질의 .png (또는 다른) 이미지 대신 저품질을 저장할 수 있습니까? 동일한 코드가 localhost에서 작동하지만 라이브 서버에서는 실패하기 때문에 기괴합니다. 여기에 내가 변환 방법 사용하고 있습니다 :DOC에서 PNG로 변환 할 때의 문제
private void ConvertDocToPNG(string startupPath, string filename1)
{
var docPath = Path.Combine(startupPath, filename1);
Application app = new Application();
Microsoft.Office.Interop.Word.Document doc = new Microsoft.Office.Interop.Word.Document();
app.Visible = false;
doc = app.Documents.Open(docPath);
doc.ShowGrammaticalErrors = false;
doc.ShowRevisions = false;
doc.ShowSpellingErrors = false;
//doc.ActiveWindow.ActivePane.View.Zoom.Percentage = 500;
//Opens the word document and fetch each page and converts to image
foreach (Microsoft.Office.Interop.Word.Window window in doc.Windows)
{
foreach (Microsoft.Office.Interop.Word.Pane pane in window.Panes)
{
for (var i = 1; i <= pane.Pages.Count; i++)
{
Microsoft.Office.Interop.Word.Page page = null;
bool populated = false;
while (!populated)
{
try
{
// This [email protected]#$ variable won't always be ready to spill its pages. If you step through
// the code, it will always work. If you just execute it, it will crash. So what
// I am doing is letting the code catch up a little by letting the thread sleep
// for a microsecond. The second time around, this variable should populate ok.
page = pane.Pages[i];
populated = true;
}
catch (COMException ex)
{
Thread.Sleep(1);
}
}
var bits = page.EnhMetaFileBits;
var target = Path.Combine(startupPath + "\\", string.Format("{1}_page_{0}", i, filename1.Split('.')[0]));
try
{
using (var ms = new MemoryStream((byte[])(bits)))
{
var image = System.Drawing.Image.FromStream(ms);
var pngTarget = Path.ChangeExtension(target, "png");
image.Save(pngTarget, ImageFormat.Png);
}
}
catch (System.Exception ex)
{
doc.Close(true, Type.Missing, Type.Missing);
Marshal.ReleaseComObject(doc);
doc = null;
app.Quit(true, Type.Missing, Type.Missing);
Marshal.ReleaseComObject(app);
app = null;
throw ex;
}
}
}
}
doc.Close(true, Type.Missing, Type.Missing);
Marshal.ReleaseComObject(doc);
doc = null;
app.Quit(true, Type.Missing, Type.Missing);
Marshal.ReleaseComObject(app);
app = null;
}
는 서버가 필요한 모든 라이브러리를합니까? 특히 Microsoft.Office를위한 것입니까? – lucuma
물론 있습니다. 나 또한 아무 소용이없는 줌을 사용해 보았습니다. – Lukas
나는 이것을 ASP.NET과 Office Interop로 태그를 붙인 것으로 나타났습니다. Office Interop은 ** 서버에서 지원되지 않습니다. ** 많은 문제가 발생할 수 있습니다. 자세한 내용은 MSDN (http://support.microsoft.com/kb/257757)을 참조하십시오. – mason