我找到了重新编写旧代码的方法,这些代码将PDF文件签名为新文件,这标志着来自Web服务的MemoryStreams(字节数组).简单吧?那是昨天.今天我无法让它发挥作用.
这是旧代码,它使用FileStreams并且它可以工作:
public static string OldPdfSigner(PdfReader pdfReader, string destination, string password, string reason, string location, string pathToPfx)
{
using (FileStream pfxFile = new FileStream(pathToPfx, FileMode.Open, FileAccess.Read))
{
...
using (PdfStamper st = PdfStamper.CreateSignature(pdfReader, new FileStream(destination, FileMode.Create, FileAccess.Write), '\0'))
{
PdfSignatureAppearance sap = st.SignatureAppearance;
sap.SetCrypto(key, chain, null, PdfSignatureAppearance.WINCER_SIGNED);
sap.Reason = reason;
sap.Location = location;
return destination;
}
}
}
Run Code Online (Sandbox Code Playgroud)
下面是我自己重做的内容,它抛出System.ObjectDisposedException:无法访问已关闭的Stream.
public static byte[] PdfSigner(PdfReader pdfReader, string password, string reason, string location, string pathToPfx)
{
using (FileStream pfxFile = new FileStream(pathToPfx, FileMode.Open, …Run Code Online (Sandbox Code Playgroud) 我承认我对c#的经验很少,所以这可能很明显,但我不得不问 - 两个代码示例之间有什么区别吗?如果不明显,第一个语句会在new运算符的末尾省略().那里有什么区别或者()在这种情况下是多余的?
private static Dictionary<string, string> dict1 = new Dictionary<string, string>
{
{ "a", "A" },
{ "b", "B" }
};
private static Dictionary<string, string> dict2 = new Dictionary<string, string>()
{
{ "a", "A" },
{ "b", "B" }
};
Run Code Online (Sandbox Code Playgroud) 我在.Net中编写了一个简单的例程,我需要从Java调用并检查退出值.出于某种原因,当从Java调用时,waitFor永远不会结束.这是因为从命令提示符调用时.Net例程很快就会结束,当从test.bat调用时它会正确返回-1.任何人都知道问题是什么?
这是Java代码:
public static int runOnceWait(String[] cmdarray) throws IOException, InterruptedException
{
Process p;
p = Runtime.getRuntime().exec(cmdarray);
int res = p.waitFor();
p.destroy();
return res;
}
/**
* @param args
* @throws InterruptedException
* @throws IOException
*/
public static void main(String[] args) throws IOException, InterruptedException
{
String [] cmd = new String[2];
cmd[0]=signer;
cmd[1]=fileLocation;
System.out.println ("\"" + cmd[0] + "\" \"" + cmd[1] + "\"");
System.out.println (runOnceWait(cmd));
}
Run Code Online (Sandbox Code Playgroud)
这是C#代码:
static int Main(string[] args)
{
if (args.Length != 1 && args.Length != 2) …Run Code Online (Sandbox Code Playgroud)