Hello,
I would need some advice please. My situation is the following:
I have a zip-folder with PDF files in it. I go over all the PDFs in the zip folder and print each one.
Is this possible with the native Visual Studio and what it has to offer? Or do I essentially need a tool such as iTextPDF or PDFSharp?
I have been researching for so many hours and I cannot find a solution.
My main problem is, that I cannot find a way to connect my PDF-document I would like to print with the PrintDocument object. I cannot give a path to the document to the PrintDocument. It does not have an attribute either for passing on the path of where your document is located.
So how do I tell it which document to print?
So when I show my print preview, it is all blank. Is this because I cannot natively print PDF from a console application? Or is it possible somehow?
I would appreciate some help very much.
Thank you in advance! :-)
Lila
Some excerpt of my C# code, which I am using within a console application:
PrintDialog pDialog = new PrintDialog();
PrintDocument printDoc = new PrintDocument();
printDoc.DocumentName = ("Print Document");
if (pDialog.ShowDialog() == DialogResult.OK)
{
printDoc.PrinterSettings = pDialog.PrinterSettings;
pDialog.Document = printDoc;
var settingsValid = printDoc.PrinterSettings.IsValid;
}
if (settingsValid)
{
PrintPreviewDialog p = new PrintPreviewDialog();
p.Document = printDoc;
try
{
var r = p.ShowDialog();
printDoc.Print();
}
Lila lPosted Feb 7, 2016, 5:11 AM
alice yangPosted Feb 5, 2016, 3:34 AM
Lila lPosted Feb 4, 2016, 4:29 PM
Hello Hilal Burak,
thank you SO much for this, I got my code to work now, using Adobe Reader. A difficulty to overcome was also, that I need to print to a specific printer, chosen by the user in the print dialog.
{
DirectoryInfo unzippedFolder = new DirectoryInfo(zibname);
foreach (FileInfo file in unzippedFolder.GetFiles())//print each PDF-file within the unzipped folder
{
ProcessStartInfo startInfo = new ProcessStartInfo();
startInfo.FileName = @"C:\Program Files (x86)\Adobe\Acrobat Reader DC\Reader\AcroRd32.exe";
Process process = new Process();
startInfo.Arguments = String.Format("/h /t \"{0}\" \"{1}\"", file.FullName, pDialog.PrinterSettings.PrinterName);//file.FullName: full path of PDF file startInfo.CreateNoWindow = true;
startInfo.ErrorDialog = false;
startInfo.UseShellExecute = false;
process = Process.Start(startInfo);
if (!process.WaitForExit(7000))
{
// kill Adobe Reader
process.Kill();
}
}
Hilal BurakPosted Feb 4, 2016, 11:02 AM
1. If the PC has Adobe Acrobat Reader installed, you can use it to print the PDF file. See this link:
http://www.codeproject.com/Tips/598424/How-to-Silently-Print-PDFs-using-Adobe-Reader-and
the problem here that if the machine doesn't have Acrobat reader installed.
2. Use a library that supports loading PDF and printing such as this:
https://www.leadtools.com/sdk/print