2012-12-13 7 views
0

내가하려는 것은 .txt로 Windows 필기장 (.jrn) 파일을 만드는 것입니다. 이 변환은 가상 "Journal Note Writer"프린터로 인쇄하여 수행 할 수 있습니다. 나는 이것을 잠시 동안 작동시키는 몇 가지 다른 방법으로 고심하고 있었기 때문에 나는 물건들을 단순화하려고 노력했다. (나는 희망한다). 이 파일을 메모장에서 열리지 만 인쇄 대화 상자가 열리지 않습니다 내가 현재인쇄 대화 상자에서 메모장으로 열기

Process p = new Process(); 
p.StartInfo = new ProcessStartInfo() 
{ 
    FileName = fileToOpen, // My .txt file I'd like to convert to a .jrn 
    CreateNoWindow = true, 
    Arguments = "-print-dialog -exit-on-print" 
}; 
p.Start(); 

것을

. 인쇄 대화 상자를 열고 이상적인 인쇄 대화 상자에서 몇 가지 기본 옵션을 지정할 수있게하고 싶습니다.

내가 해봤 또 다른 것은이 (다른 SO 질문에 있음)입니다 :

Process p = new Process(); 
p.StartInfo = new ProcessStartInfo() 
{ 
    CreateNoWindow = true, 
    Verb = "print", 
    FileName = fileToOpen 
}; 
p.Start(); 

이 문제는 그냥 자동으로 부여하지 않고 기본 프린터로 파일 (물리적 하나) 출력이다 나에게 그것을 바꿀 수있는 옵션. 에가 .txt를 인쇄하는 내가 그냥 어떤 방법을 찾고 있어요이 시점에서

을 찾고 있어요

"윈도우 참고 작가." 필자는 외부 응용 프로그램을 거치지 않고 인쇄 작업을 시도해 보았습니다. .jrn 파일로 변환하는 다른 참조를 찾을 수 없었으므로 어떤 아이디어라도 열어 볼 수 있습니다.

+1

아마도이 문서가 도움이 될 수 있습니다. http://support.microsoft.com/kb/322091 죄송합니다. 직접 시도하지는 않았지만 직장에 있습니다 ... – CMPerez

+0

@Picacodigos - 링크를 제공해 주셔서 감사합니다. 메모장을 통해 인쇄 작업을 할 수 없다면 촬영할 가치가있는 것 같습니다. 나는 이와 비슷한 접근법을 시도했지만, 프린터 도우미 클래스를 사용하지 않아도되기를 희망했다. –

+0

또 다른 아이디어. ShellExecute (ing) DOS 명령 "TYPE > LPT1"을 사용해 보셨습니까? – CMPerez

답변

0

이 문제로 잠시 고생하고 나서 필자는 메모장을 통하지 않고 응용 프로그램을 통해 직접 인쇄 작업을 시도하기로 결정했습니다. 전에 시도했던 문제는 용지 크기를 변경하면 결과 .jrn 파일이 손상된다는 것입니다 (인쇄물이 비어 있음). 기본이 아닌 용지 크기로 인쇄하려면 일부 용지 크기 설정을 변경해야합니다.

다음은이 문제에 대해 다른 사람들이 고심하는 경우의 최종 코드입니다. 모두의 도움에 감사드립니다.

private void btnOpenAsJRN_Click(object sender, EventArgs e) { 
    string fileToOpen = this.localDownloadPath + "\\" + this.filenameToDownload; 
    //Create a StreamReader object 
    reader = new StreamReader(fileToOpen); 
    //Create a Verdana font with size 10 
    lucida10Font = new Font("Lucida Console", 10); 
    //Create a PrintDocument object 
    PrintDocument pd = new PrintDocument(); 

    PaperSize paperSize = new PaperSize("Custom", 400, 1097); 
    paperSize.RawKind = (int)PaperKind.Custom; 
    pd.DefaultPageSettings.PaperSize = paperSize; 
    pd.DefaultPageSettings.Margins = new Margins(20, 20, 30, 30); 

    pd.PrinterSettings.PrinterName = ConfigurationManager.AppSettings["journalNotePrinter"]; 
    pd.DocumentName = this.filenameToDownload; 
    //Add PrintPage event handler 
    pd.PrintPage += new PrintPageEventHandler(this.PrintTextFileHandler); 

    //Call Print Method 
    try { 
     pd.Print(); 
    } 
    finally { 
     //Close the reader 
     if (reader != null) { 
      reader.Close(); 
     } 
     this.savedJnt = fileToOpen.Replace("txt", "jnt"); 
     System.Threading.Thread.Sleep(1000); 
     if (File.Exists(this.savedJnt)) { 
      lblJntSaved.Visible = true; 
      lblJntSaved.ForeColor = Color.Green; 
      lblJntSaved.Text = "File successfully located."; 
      // If the file can be found, show all of the buttons for completing 
      // the final steps. 
      lblFinalStep.Visible = true; 
      btnMoveToSmoketown.Visible = true; 
      btnEmail.Visible = true; 
      txbEmailAddress.Visible = true; 
     } 
     else { 
      lblJntSaved.Visible = true; 
      lblJntSaved.ForeColor = Color.Red; 
      lblJntSaved.Text = "File could not be located. Please check your .jnt location."; 
     } 
    } 
} 

private void PrintTextFileHandler(object sender, PrintPageEventArgs ppeArgs) { 
    //Get the Graphics object 
    Graphics g = ppeArgs.Graphics; 
    float linesPerPage = 0; 
    float yPos = 0; 
    int count = 0; 
    //Read margins from PrintPageEventArgs 
    float leftMargin = ppeArgs.MarginBounds.Left; 
    float topMargin = ppeArgs.MarginBounds.Top; 
    string line = null; 
    //Calculate the lines per page on the basis of the height of the page and the height of the font 
    linesPerPage = ppeArgs.MarginBounds.Height/
    lucida10Font.GetHeight(g); 
    //Now read lines one by one, using StreamReader 
    while (count < linesPerPage && 
    ((line = reader.ReadLine()) != null)) { 
     //Calculate the starting position 
     yPos = topMargin + (count * 
     lucida10Font.GetHeight(g)); 
     //Draw text 
     g.DrawString(line, lucida10Font, Brushes.Black, 
     leftMargin, yPos, new StringFormat()); 
     //Move to next line 
     count++; 
    } 
    //If PrintPageEventArgs has more pages to print 
    if (line != null) { 
     ppeArgs.HasMorePages = true; 
    } 
    else { 
     ppeArgs.HasMorePages = false; 
    } 
} 
0

프린터로 Journal Note Writer을 얻으려면 프린터 기본 설정에 추가해야합니다. -> 프린터 추가 (프로그래밍 방식으로 수행 할 수 있는지 궁금합니다).

어쨌든 MSDN에 설명 된대로 일반 .txt 파일의 인쇄물을 얻을 수 있습니다.

관련 문제