2017-09-26 1 views
-1

PDFをドキュメントフォルダに保存しようとしています。私はグーグルで多くのリソースに出くわしましたが、誰も私のために働いていませんでした。私は動作しなかったshowfiledialogの使用を試みました。私が望むのは、自分のPDFファイルをドキュメントフォルダに保存することです。私は学校のプロジェクトのためにこれを行う必要があり、これは私を困らせた唯一の部分です。今のところ、これは私のコードです:ローカルディスクにPDFを保存するC#

private void savePDF_Click(object sender, EventArgs e) 
{ 
    FileStream fileStream = new FileStream(nameTxtB.Text + "Repair.pdf", FileMode.Create, FileAccess.Write, FileShare.None); 

    Document document = new Document(); 
    PdfWriter pdfWriter = PdfWriter.GetInstance(document, fileStream);    
    pdfWriter.Open(); 
    PdfContentByte cb = pdfWriter.DirectContent; 
    ColumnText ct = new ColumnText(cb); 
    document.Open(); 
    ... 
+0

をあなたのコンテンツ(nameTxtB.Text)を追加する必要があります_nameTxtB.Text_の内容は何ですか? – Steve

+0

また、そのストリームの周りに 'using'ブロックを投げます。 –

+0

@Steve '' nameTxtB.text''は、あなたの質問が求めているものなら、組織のためのPDFのタイトルとして使用される顧客名です。 – Yuvraj

答えて

1

あなたがいないのFileStream

に段落に
using System.IO; 
    using iTextSharp.text.pdf; 
    using iTextSharp.text; 

static void Main(string[] args) { 
     // open the writer 
      string fileName = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments), "Repair.pdf"); 
     FileStream fs = new FileStream(fileName, FileMode.Create, FileAccess.Write); 
     Document doc = new Document(); 

     //Create a New instance of PDFWriter Class for Output File 

     PdfWriter.GetInstance(doc, fs); 
     //Open the Document 
     doc.Open(); 
     //Add the content of Text File to PDF File 

     doc.Add(new Paragraph("Document Content")); 

     //Close the Document 

     doc.Close(); 
     System.Diagnostics.Process.Start(fileName); 
    } 
関連する問題