2017-02-24 10 views
0

파일로 인쇄 및 .DOCX에서 .PDF를 만들거나 .xlsx '에하려고 만들어인쇄 손상된 파일

그것은 파일을 작성하는 관리하지만 그것을 열려고 할 때 파일이 손상 말한다 또는 손상되었습니다.

코드

: 텍스트 편집기에서 PDF를 보면

 string name = Path.GetFileNameWithoutExtension(filename); 
     string path = Path.GetDirectoryName(filename); 

     Directory.CreateDirectory(path); 

     PrintDocument pd = new PrintDocument(); 
     pd.DocumentName = filename; 

     PrinterSettings printerSettings = new PrinterSettings(); 
     printerSettings.PrinterName = "PDFCreator"; 
     //printerSettings.PrinterName = "CutePDF Writer"; 

     printerSettings.PrintToFile = true; 
     printerSettings.PrintFileName = String.Format(@"{0}/{1}.pdf", path, name); 

     pd.PrinterSettings = printerSettings; 
     pd.Print(); 

, 헤더 읽

% PS-어도비 3.0 %% 제목 :! C : \ 정크 \ 샘플을 .docx %% 작성자 : PScript5.dll 버전 5.2.2 %% CreationDate : 2/24/2017 14:12:57 %% 사용자 : %% BoundingBox : (atend) %% 페이지 : (atend) %% 오리엔테이션 : 세로,%% PageOrder : 특수 %% DocumentNeededResources : %% DocumentSuppliedResources (atend) (atend) %% DocumentData : Clean7Bit %% TargetDevice (을 PDFCreater) (3010) 096 %% LanguageLevel 3 %% EndComments %% BeginDefaults %% PageBoundingBox : 0 0 595 842 %% ViewingOrientation : 1 0 0 1 %% EndDefaults

가 첫 번째 줄에 %의 PDF의 변화에 ​​헤더를 수정했지만, 지금까지 본 적이 파일을 열 수있는 것은 없습니다.

도움이나 조언을 보내 주시면 감사하겠습니다.

감사합니다.

답변

0

파일로 인쇄하는 것은 PDF 프린터로 생성 된 파일을 저장할 위치를 지정하는 것과 같지 않습니다. 단순히 프린터로 보내지는 모든 명령을 대신 파일로 출력합니다 (이 경우 일련의 PostScript 명령). 구현에 따라 생성되는 파일을 PDF 프린터가 저장할 위치를 프로그래밍 방식으로 지정할 방법이 없습니다.

+0

이 답변은 PDFCreator 및 CutePDF Writer에 해당하지만 모든 PDF 프린터에 해당되는 것은 아닙니다. Win2PDF와 같은 일부 PDF 프린터는 PDF로 직접 출력하고 .NET .PrintToFileName 및 .PrintFileName 속성을 지원합니다. –

+0

Bradley와 Craig에게 의견을 보내 주셔서 감사합니다. 나는 Win2PDF를 시도 할 것이고, 여전히 작동하지 않는다면 나는 Word의 인스턴스를 여는 것에 다시 돌아갈 것이다. – Pearcy