Microsoft를 사용하여 docx (바이트 [] 형식)를 pdf (바이트 [] 형식)로 변환하는 함수가 있습니다. .Office.Interop.Worddocx를 bytes [] 형식으로 변환하여 pdf 형식으로 openXML 또는 그 유사 형식으로 변환
그리고 잘 작동합니다. WinOffice를 서버에 설치해야하므로 온라인으로 작동하지 않는다는 점을 제외하고는 아무 것도 할 수 없습니다.
그래서 저는 다른 뭔가를 생각해보고 openXML에 대해 생각하고 있습니다 (더 좋은 방법을 알지 못한다면).
하지만 정확히이 문제를 어떻게 해결할 수 있습니까? 이 docx 파일을 가져 와서 바이트 수 [] 형식의 pdf로 변환하고 싶습니다. 이
public static byte[] ConvertDocx2PDF(byte[] DocxFile, string FileName)
{
try
{
string path = Path.Combine(HttpRuntime.AppDomainAppPath, "MailFiles/DOCX2PDF");
if (!Directory.Exists(path))
Directory.CreateDirectory(path);
Guid id = Guid.NewGuid();
FileName = id.ToString() + FileName;
path += "/" + FileName;
if (File.Exists(path))
File.Delete(path);
File.WriteAllBytes(path, DocxFile);
Microsoft.Office.Interop.Word.Application word = new Microsoft.Office.Interop.Word.Application();
object oMissing = System.Reflection.Missing.Value;
word.Visible = false;
word.ScreenUpdating = false;
// Cast as Object for word Open method
Object filename = (Object)path;
// Use the dummy value as a placeholder for optional arguments
Microsoft.Office.Interop.Word.Document doc = word.Documents.Open(ref filename, 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, ref oMissing);
doc.Activate();
object outputFileName = (object)path.ToLower().Replace(".docx", ".pdf");
object fileFormat = Microsoft.Office.Interop.Word.WdSaveFormat.wdFormatPDF;
if (File.Exists(outputFileName.ToString()))
File.Delete(outputFileName.ToString());
// Save document into PDF Format
doc.SaveAs(ref outputFileName,
ref fileFormat, 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);
object saveChanges = Microsoft.Office.Interop.Word.WdSaveOptions.wdDoNotSaveChanges;
((Microsoft.Office.Interop.Word._Document)doc).Close(ref saveChanges, ref oMissing, ref oMissing);
doc = null;
((Microsoft.Office.Interop.Word._Application)word).Quit(ref oMissing, ref oMissing, ref oMissing);
word = null;
try
{
File.Delete(path);
}
catch { }
return File.ReadAllBytes(path.ToLower().Replace(".docx", ".pdf"));
}
catch (Exception e)
{
}
byte[] erroByte = new byte[0];
return erroByte;
}
으로 말한 것처럼 Microsoft.Office에서
내 앞의 코드 보인다. 그것은 잘 작동하지만 내 서버에서 작동하지 않습니다.
openXML 또는 다른 어떤 방법으로 어떻게 할 수 있습니까?
당신은 벡터 그래픽 포맷으로 PDF 생각할 수있는 반면
http://stackoverflow.com/a/607679/56778 –