가상 경로로 파일 저장 오류
ASP.NET 애플리케이션에서, PdfDocument.SaveAs()는 다음과 같은 오류와 함께 실패할 수 있습니다:
IronPDF could not write to the file '~/PDFFiles/mydocument.pdf'. It may be open in a PDF viewer.
"메시지는 잠긴 파일을 가리키지만, 실제 원인은 대개 경로에 있습니다." IronPDF는 디스크에 기록하며 완전하게 정의된 물리적 경로가 필요한 반면, ~/PDFFiles/file.pdf 같은 값은 파일 시스템이 해결할 수 없는 ASP.NET 가상 경로입니다.
가상 경로를 물리적 경로로 매핑
ASP.NET Web Forms에서 Server.MapPath()를 사용하거나 다른 곳에서 HostingEnvironment.MapPath()를 사용하여 저장하기 전에 가상 경로를 변환하십시오:
string virtualPath = "~/PDFFiles/mydocument.pdf";
string physicalPath = Server.MapPath(virtualPath); // or HostingEnvironment.MapPath outside Web Forms
pdf.SaveAs(physicalPath);
string virtualPath = "~/PDFFiles/mydocument.pdf";
string physicalPath = Server.MapPath(virtualPath); // or HostingEnvironment.MapPath outside Web Forms
pdf.SaveAs(physicalPath);
Imports System.Web
Dim virtualPath As String = "~/PDFFiles/mydocument.pdf"
Dim physicalPath As String = Server.MapPath(virtualPath) ' or HostingEnvironment.MapPath outside Web Forms
pdf.SaveAs(physicalPath)
"최소한의 작동 예제:"
var renderer = new ChromePdfRenderer();
PdfDocument pdf = renderer.RenderUrlAsPdf("https://example.com");
string physicalPath = Server.MapPath("~/App_Data/PDFFiles/output.pdf");
pdf.SaveAs(physicalPath);
var renderer = new ChromePdfRenderer();
PdfDocument pdf = renderer.RenderUrlAsPdf("https://example.com");
string physicalPath = Server.MapPath("~/App_Data/PDFFiles/output.pdf");
pdf.SaveAs(physicalPath);
Dim renderer As New ChromePdfRenderer()
Dim pdf As PdfDocument = renderer.RenderUrlAsPdf("https://example.com")
Dim physicalPath As String = Server.MapPath("~/App_Data/PDFFiles/output.pdf")
pdf.SaveAs(physicalPath)
저장 전 확인 사항
"- 디렉토리 존재 여부: 대상 폴더를 생성하고 앱이 해당 폴더에 쓰기 권한이 있는지 확인하십시오." "- 파일이 열려 있지 않음: 출력이 Adobe Reader와 같은 뷰어에 이미 열려 있지 않은지 확인하십시오."
- 제한된 위치:
Program Files와 같은 보호된 폴더에 기록할 때 충분한 권한으로 실행하십시오. "- 경로 확인: 개발 중에 해결된 물리적 경로를 로그에 기록하여 예상 위치를 가리키는지 확인하십시오."

