Regenerate a PDF file with a PDF printer
Hello.
We have issues with PDF files which need to be re-generated, using the “microsoft print to PDF” printer fixed issues that we have.
How can I code that in C#? I have tried heaps of codes, nothing worked.
I have tried this :
try
{
ProcessStartInfo info = new ProcessStartInfo
{
FileName = filePath,
Verb = “PrintTo”,
Arguments = “”” + outputFilePath + “” “Microsoft Print to PDF””,
CreateNoWindow = true,
WindowStyle = ProcessWindowStyle.Hidden
};
using (Process p = new Process())
{
p.StartInfo = info;
p.Start();
p.WaitForExit();
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
but it’s not adapter for Windows, or even :
try
{
PrintDocument pd = new PrintDocument();
ProcessStartInfo info = new ProcessStartInfo(filePath);
info.Verb = “Print”;
pd.PrinterSettings.PrintToFile = true;
pd.PrinterSettings.PrinterName = “Microsoft Print to PDF”;
pd.PrinterSettings.PrintFileName = outputFilePath;
pd.Print();
info.CreateNoWindow = true;
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
which generates empty files…
Thanks
Hello.We have issues with PDF files which need to be re-generated, using the “microsoft print to PDF” printer fixed issues that we have.How can I code that in C#? I have tried heaps of codes, nothing worked.I have tried this : try
{
ProcessStartInfo info = new ProcessStartInfo
{
FileName = filePath,
Verb = “PrintTo”,
Arguments = “”” + outputFilePath + “” “Microsoft Print to PDF””,
CreateNoWindow = true,
WindowStyle = ProcessWindowStyle.Hidden
};
using (Process p = new Process())
{
p.StartInfo = info;
p.Start();
p.WaitForExit();
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
} but it’s not adapter for Windows, or even : try
{
PrintDocument pd = new PrintDocument();
ProcessStartInfo info = new ProcessStartInfo(filePath);
info.Verb = “Print”;
pd.PrinterSettings.PrintToFile = true;
pd.PrinterSettings.PrinterName = “Microsoft Print to PDF”;
pd.PrinterSettings.PrintFileName = outputFilePath;
pd.Print();
info.CreateNoWindow = true;
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
} which generates empty files…Thanks Read More