我正在尝试使用Spire.PDF和C#自动填写/签名/打印联邦i-9表格。 i9文件是XFA表单,已受保护,不允许签名。但是,如果我填写i9并打印为PDF,则可以对该新文件签名。
我要坚持的步骤是将填充的i9打印到PDF文件,而无需实际打开Acrobat或与最终用户直接交互以指定文件名。我之所以说“打印”,是因为如果我将其另存为PDF文件,则它永远不会使XFA表单变平,并且不会签名。
到目前为止,我已经使用以下代码自动打印了文件:
Process proc = new Process();
proc.StartInfo.Verb = "PrintTo";
proc.StartInfo.FileName = filename;
proc.StartInfo.Arguments = "\"" + printername + "\"";
proc.StartInfo.UseShellExecute = true;
proc.StartInfo.CreateNoWindow = true;
proc.Start();
,我想我也许可以在这里强制使用Microsoft Print to PDF'printer',但是我不知道是否有一种方法可以指定要使用的文件名,从而不会提示用户?
如果尝试使用Spire.PDF控件进行打印,则只能获得带有“请稍候...的文件”。 如果此消息最终没有被文档的正确内容取代,则您的PDF 查看器可能无法显示这种类型的文档。”消息。
当通过Acrobat打开表格进行打印时,我会弹出“此表格包含不完整或无效的信息。确定要打印吗?”如果单击“是”,则可以成功打印为PDF,然后可以对该文件签名。
因此,我相信无论发生什么数据检查都将导致无法通过代码打印,并且我希望那些比我对解决此问题的方法有更多想法的人更明智。
预先感谢您的帮助!如果仅搜索Federal i9,则应该找到我正在使用的文件。我没有在此处附加文件的空间。
这是我用来尝试通过Spire.PDF控件完成任务的代码。
PdfDocument doc = new PdfDocument();
string i9path = "locationofi9file"
string newi9path = "locationoffilledi9file"
doc.LoadFromFile(i9path);
/*fill form here*/
doc.Form.IsFlatten = true;
doc.SaveToFile(newi9path, FileFormat.PDF);
doc.Close();
doc.Dispose();
doc.LoadFromFile(newi9path);
string file = "printi9";
if (System.IO.File.Exists(file))
System.IO.File.Delete(file);
string directory = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
PrinterSettings settings = new PrinterSettings();
PageSettings pages = new PageSettings();
string printername = "Microsoft Print to PDF";
settings.PrinterName = printername;
settings.PrintToFile = true;
settings.PrintFileName = Path.Combine(directory, file + ".pdf");
PrintDocument printDoc = doc.PrintDocument;
printDoc.PrinterSettings = settings;
printDoc.Print();
doc.Close();
doc.Dispose();