0

Im trying to print an existing .pdf to a new .pdf File using the nowadays Windows 10 inbuilt Print-to-PDF printer (or anything else that works).

Ive been searching for 2 days now but i cant find anything that works for my case, only solutions for either printing to .pdf or printing a .pdf.

I need to be able to specify the printer, an input and an output filename/path and have no required user interaction.

Surprised its this difficult to automate what would be roughly 8 manual clicks... Anyone got any ideas? Seems like a commenter in this thread was asking the same but never got an answer How to programmatically print to PDF file without prompting for filename in C# using the Microsoft Print To PDF printer that comes with Windows 10

F. S.
  • 1
  • 2
    would it be possible to simply _copy the file_? – Franz Gleichmann Jul 29 '21 at 08:01
  • sounds a bit like an XY problem (https://xyproblem.info/) - Include information about a broader picture so we can understand what you are really trying to do. Maybe if you search for "convert pdf to pdf/a" you will find what you need but without more details we don't really know what you are trying to achieve. – wischi Jul 29 '21 at 09:12
  • I have an OCR processing Program and some pdfs come with some weird protection. You can open them, print them,etc but not alter them which for whatever reason makes the OCR throw an exception. If i reprint those files the protection is gone and everything works thats why i cant just save them again. Basically its to get rid of extra data on the document. You might be right with the XY problem but i couldnt find an easier way to get rid of that pdf protection/metadata/whatever either. Entering the passwords or having the document suppliers adhere to certain standards arent options – F. S. Jul 29 '21 at 10:48
  • This is the Problem i have https://superuser.com/questions/47462/cant-copy-text-from-a-pdf-file but i shouldnt use 3rd party programs besides acrobat reader itself and it needs to happen without user input – F. S. Jul 29 '21 at 11:01

1 Answers1

0

The link you have describe does contain the solution for your problem, at least programmatically.

Please set your default printer to Microsoft XPS Printer, then you will be able to save your print output file in .pdf format.

I believe what you are trying to do is trigger print from your code so that it will be automatically saved to .pdf format. Unfortunately, this is not how the print library of C# works, it rather triggers the printer driver in your machine.

Thanks.

  • I need to be able to specify the printer, using the default printer wont work since there is no guarantee someone wont change the default printer on this machine. – F. S. Jul 29 '21 at 10:43
  • Basically what i need is what the top commenter on the top solution of that link asks: "How can I use this to print an existing PDF anew with Microsoft Print To PDF, e.g. to "bake" annotations inside the PDF? – clocktown Jun 18 '17 at 23:37" – F. S. Jul 29 '21 at 10:52
  • Apparently its not that easy to just print from a pdf file to a new pdf file or atleast i didnt get it if the solution was there. Would you mind Pointing me towards it? Im fairly new to C# but i expected this to be easily done so i accepted the task – F. S. Jul 29 '21 at 10:55