Reputation:
I use the following method to print a XPS file with adobe acrobat:
private void GenerateXPS(String filename)
{
Process proc = new Process();
proc.StartInfo.FileName = "AcroRd32.exe";
proc.StartInfo.Arguments = "/t " + filename + ".pdf" + " " + "\"Microsoft XPS Document Writer\"";
proc.Start();
}
But the problem is, the Microsoft XPS Document writer needs a filename where to store the document. Now I'm asked to enter this filename by Adobe Acrobat, but I want to pass this filename as well in the arguments. Or if this is not possible just use the same filename. Is this possible?
Upvotes: 3
Views: 6004
Reputation: 11730
Virtual printers in Windows generically ask for a filename as that is the default setting and itself should not be changed (It would be inadvisable, even if it is your own device)
What you can do personally or in an enterprise setting is add a secondary virtual XPS printer that prints to a fixed file name. Optionally you can program that filename to change in the background, but that is a more complex question & answer.
Here I have a secondary xps printer called MyXPS that will not ask for filename as I set it to c:\temp\MyXPS.xps.
Now I run your command as,
"C:\Program Files\Adobe\Acrobat Reader DC\Reader\AcroRd32.exe" /t "%cd%\in.pdf" "MyXPS"
Ensure you delete any previous run as it may block fresh file writing. It ran so quick I did not even see it in the queue! However the output is there.
Note the XPS quality in this case is much inferior to the PDF quality. Without the user controls, the file size blossoms, the page scale will be altered, fonts lost and far more variable image qualities. It would be simpler for a user to alter the desired output characteristics in run time print prompt dialog.
Upvotes: 0
Reputation: 999
If it isn't mandatory that you use acrobat, you might try printing the file directly to the Microsoft XPS Document writer. You can do this without the UI popping up. (see Feng Yuan's blog post for more details)
Upvotes: 0