title: c# printing through PDF drivers, print to file option will output PS instead of PDF
body: <p>After struggling whole day, I identified the issue but this didn't solve my problem. </p>
  
  <p>On short:</p>
  
  <p>I need to open a PDF, convert to BW (grayscale), search some words and insert some notes nearby found words. At a first look it seems easy but I discovered how hard PDF files are processed (having no "words" concepts and so on).</p>
  
  <p>Now the first task, converting to grayscale just drove me crazy. I didn't find a working solution either commercial or free. I came up with this solution:</p>
  
  <ul>
  <li>open the PDF</li>
  <li>print with windows drivers, some free PDF printers</li>
  </ul>
  
  <p>This is quite ugly since I will force the C# users to install such 3'rd party SW but.. that is fpr the moment. I tested FreePDF, CutePDF and PDFCreator. All of them are working "stand alone" as expected.</p>
  
  <p>Now when I tried to print from C#, obviously, I don't want the print dialog, just select BW option and print (aka. convert)</p>
  
  <p>The following code just uses a PDF library, shown for clarity only. </p>
  
  <pre><code>                Aspose.Pdf.Facades.PdfViewer viewer = new Aspose.Pdf.Facades.PdfViewer();
                  viewer.BindPdf(txtPDF.Text);
  
                  viewer.PrintAsGrayscale = true;
                  //viewer.RenderingOptions = new RenderingOptions { UseNewImagingEngine = true };
  
                  //Set attributes for printing
                  //viewer.AutoResize = true;         //Print the file with adjusted size
                  //viewer.AutoRotate = true;         //Print the file with adjusted rotation
                  viewer.PrintPageDialog = true;   //Do not produce the page number dialog when printing
  
                  ////PrinterJob printJob = PrinterJob.getPrinterJob();
  
                  //Create objects for printer and page settings and PrintDocument
                  System.Drawing.Printing.PrinterSettings ps = new System.Drawing.Printing.PrinterSettings();
                  System.Drawing.Printing.PageSettings pgs = new System.Drawing.Printing.PageSettings();
                  //System.Drawing.Printing.PrintDocument prtdoc = new System.Drawing.Printing.PrintDocument();
  
  
                  //prtdoc.PrinterSettings = ps;
  
                  //Set printer name
                  //ps.PrinterName = prtdoc.PrinterSettings.PrinterName;
  
  
                  ps.PrinterName = "CutePDF Writer";
                  ps.PrintToFile = true;
  
                  ps.PrintFileName = @"test.pdf";
                  //
                  //ps.
  
                  //Set PageSize (if required)
                  //pgs.PaperSize = new System.Drawing.Printing.PaperSize("A4", 827, 1169);
  
                  //Set PageMargins (if required)
                  //pgs.Margins = new System.Drawing.Printing.Margins(0, 0, 0, 0);
  
                  //Print document using printer and page settings
                  viewer.PrintDocumentWithSettings(ps);
                  //viewer.PrintDocument();
  
                  //Close the PDF file after priting
  </code></pre>
  
  <p>What I discovered and seems to be little explained, is that if you select</p>
  
  <p>ps.PrintToFile = true;</p>
  
  <p>no matter C# PDF library or PDF printer driver, Windows will just skip the PDF drivers and instead of PDF files will output PS (postscript) ones which obviously, will not be recognized by Adobe Reader.</p>
  
  <p>Now the question (and I am positive that others who may want to print PDFs from C# may be encountered) is how to print to CutePDF for example and still suppress any filename dialog?</p>
  
  <p>In other words, just print silently with programmatically selected filename from C# application. Or somehow convince "print to file" to go through PDF driver, not Windows default PS driver.</p>
  
  <p>Thanks very much for any hints.</p>