を作成しますまたは破損している。印刷これは、ファイルを作成するために管理し、それを開こうとすると、ファイルが破損していると言うファイルに印刷し、.docxのかの.xlsx</p> <p>からPDFファイルを作成しようと、破損したファイル
コード:テキストエディタで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-のAdobe-3.0 %%タイトル:C:ジャンク\サンプル\ .docx %%作成者:PScript5.dllバージョン5.2.2 %%作成日:2/24/2017 14:12:57 %%ユーザー: %% BoundingBox :(atend) %%ページ:(atend ) %%オリエンテーション:ポートレート %% PAGEORDER:特別 %% DocumentNeededResources: %% DocumentSuppliedResources(atend):(atend) %%をDocumentData:Clean7Bit %%ターゲットデバイス:(PDFCreatorを)(3010)096 %% LanguageLevel:3 %% EndComments %% BeginDefaults %% PageBoundingBox:0 0 595 842 %% ViewingOrientation:1 0 0 1 %% EndDefaults
は、最初の行の%PDFの変動にヘッダを編集しようとしたが、これまでのところありファイルを開くことはできません。
何か助けや助言をいただければ幸いです。
ありがとうございました。
この回答はPDFCreatorとCutePDF Writerに当てはまりますが、すべてのPDFプリンタで当てはまるわけではありません。 Win2PDFなどの一部のPDFプリンタは、PDFに直接出力し、.NET .PrintToFileNameおよび.PrintFileNameプロパティをサポートします。 –
あなたのコメント、ブラッドリーとクレイグありがとう。私はWin2PDFを試みますが、それでもうまくいかない場合は、Wordのインスタンスを開くことに戻ります。 – Pearcy