[英]Word to PDf converted PDF is having error -access denied error
將MS Word文檔轉換為PDF后。 如果我將轉換后的單詞的相同路徑發送到pdf。 即PDF。 在提取文件時,在server.pubs中發布網站時,我會收到拒絕訪問的錯誤。它在本地計算機上有效。 我在代碼中還剩下什么,還是我需要安裝什么?
public string WordtoPdf_Input(string wordFileName_input)
{
try
{
Microsoft.Office.Interop.Word.Application appWord_input = new Microsoft.Office.Interop.Word.Application();
object _MissingValue_ip = System.Reflection.Missing.Value;
//filename_doc = System.IO.Path.GetFileName(LblFleip.Text);
//wordFileName = LblFleip.Text;
string pdfFileName = string.Empty;
appWord_input.Visible = false;
appWord_input.ScreenUpdating = false;
// Cast as Object for word Open method
object filename = (object)wordFileName_input;
// Use the dummy value as a placeholder for optional arguments
Microsoft.Office.Interop.Word.Document doc = appWord_input.Documents.Open(ref filename, ref _MissingValue_ip,
ref _MissingValue_ip, ref _MissingValue_ip, ref _MissingValue_ip, ref _MissingValue_ip, ref _MissingValue_ip,
ref _MissingValue_ip, ref _MissingValue_ip, ref _MissingValue_ip, ref _MissingValue_ip, ref _MissingValue_ip,
ref _MissingValue_ip, ref _MissingValue_ip, ref _MissingValue_ip, ref _MissingValue_ip);
doc.Activate();
InputFilename = pdfFileName = Path.ChangeExtension(wordFileName_input, ".pdf");
object fileFormat = WdSaveFormat.wdFormatPDF;
//All is well until here, Save thinks the excelfile is readonly
object tmpName = Path.GetTempFileName();
File.Delete(tmpName.ToString());
// Save document into PDF Format
doc.SaveAs(ref tmpName,
ref fileFormat, ref _MissingValue_ip, ref _MissingValue_ip,
ref _MissingValue_ip, ref _MissingValue_ip, ref _MissingValue_ip, ref _MissingValue_ip,
ref _MissingValue_ip, ref _MissingValue_ip, ref _MissingValue_ip, ref _MissingValue_ip,
ref _MissingValue_ip, ref _MissingValue_ip, ref _MissingValue_ip, ref _MissingValue_ip);
// Close the Word document, but leave the Word application open.
// doc has to be cast to type _Document so that it will find the
// correct Close method.
object saveChanges = WdSaveOptions.wdDoNotSaveChanges;
((_Document)doc).Close(ref saveChanges, ref _MissingValue_ip, ref _MissingValue_ip);
doc = null;
// word has to be cast to type _Application so that it will find
// the correct Quit method.
((_Application)appWord_input).Quit(ref _MissingValue_ip, ref _MissingValue_ip, ref _MissingValue_ip);
appWord_input = null;
File.Delete(InputFilename.ToString());
File.Move(tmpName.ToString(), InputFilename.ToString());
//File.Move(tmpName,InputFilename.ToString())
filePath_input = InputFilename.ToString();
GC.Collect();
GC.WaitForPendingFinalizers();
}
catch (Exception ex)
{
}
finally
{
GC.Collect(); // force final cleanup!
GC.WaitForPendingFinalizers();
}
return filePath_input;
}
Public void PDFnumofPagecount()
{
LblFleip.Text = filePath_input;
PdfReader readerPages_ip = new PdfReader(LblFleip.Text);
NumberofPages_ip = readerPages_ip.NumberOfPages;
txtbNumberofPages_ip.Text = NumberofPages_ip.ToString();
readerPages_ip.Close();
}
i have used itextsharp for reading pages and extraction of PDF
您是否在給出錯誤的計算機上檢查了用戶的權限(以確保他們具有必需的讀/寫權限)?
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.