내 응용 프로그램에서 기존 PDF 또는 Doc를 인쇄하는 기능을 만들려고합니다. C#에서이 작업을 수행하고 사용자가 다른 프린터 또는 다른 속성을 선택할 수 있도록 메커니즘을 제공 할 수 있습니까?C#을 사용하여 PDF 파일 및 문서 파일 인쇄
PrintDialog를 보았지만 인쇄하려고하는 파일이 무엇인지 확실하지 않습니다. b/c 출력은 항상 빈 페이지입니다. 어쩌면 거기에 뭔가 빠져있을 수도 있습니다.
조언, 예제 또는 샘플 코드는 훌륭합니다!
using System.Diagnostics.Process;
...
Process process = new Process();
process.StartInfo.FileName = pathToPdfOrDocFile;
process.UseShellExecute = true;
process.StartInfo.Verb = "printto";
process.StartInfo.Arguments = "\"" + printerName + "\"";
process.Start();
process.WaitForInputIdle();
process.Kill();
가 기본 프린터로 인쇄 print
와 printto
을 대체하고 Arguments
라인을 떠나 :
은 아래이 작업했던 내 코드
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
string printPath =
System.Environment.GetFolderPath(Environment.SpecialFolder.Desktop);
System.IO.StreamReader fileToPrint;
fileToPrint= new System.IO.StreamReader(printPath + @"\myFile.txt");
System.Drawing.Font printFont;
printPDF(e);
printDocument1.Print();
fileToPrint.Close();
}
private void button2_Click(object sender, EventArgs e)
{
//printDoc(e);
}
public void printPDF(object sender ,
System.Drawing.Printing.PrintPageEventArgs e))
{
printFont = new System.Drawing.Font("Arial", 10);
float yPos = 0f;
int count = 0;
float leftMargin = e.MarginBounds.Left;
float topMargin = e.MarginBounds.Top;
string line = null;
float linesPerPage = e.MarginBounds.Height/
printFont.GetHeight(e.Graphics);
while (count < linesPerPage)
{
line = fileToPrint.ReadLine();
if (line == null)
{
break;
}
yPos = topMargin + count * printFont.GetHeight(e.Graphics);
e.Graphics.DrawString(line, printFont, Brushes.Black, leftMargin, yPos,
new StringFormat());
count++;
}
if (line != null)
{
e.HasMorePages = true;
}
fileToPrint.Close();
}
public void printDoc()
{
}
}
}
귀하의 응용 프로그램이 이미 파일을 메모리에로드했다고 말할 수 있습니까? 왜 당신이 시도한 것을 게시하지 않으시겠습니까? –