1

2つの異なる理由で2つの異なるアプリケーションでPDFSharpを使用しています。1つはドキュメントをパスワードで保護する方法で、もう1つはドキュメントに透かしを入れる方法です。これらのプロセスは両方とも、独自のアプリケーション/ワークフローで個別に機能します。問題は、アプリケーション1はパスワードのみを認識し、アプリケーション2は透かしのみを認識し、アプリケーション1はデフォルトの所有者パスワードと動的ユーザーパスワードを使用し、アプリケーション2は所有者パスワードを使用してドキュメントを開いて透かしを適用することです。問題は、パスワードが保持されていないことです。ドキュメントを保存している間、PDFSharpは以前のPDFパスワードを無視しているようです。

パスワードを再度明示的に定義せずに、透かしを適用するときにセキュリティ設定を保持する方法はありますか?

私はこれをPDFSharpフォーラムに投稿しましたが、彼らはそれを無視しています。これは良い兆候ではありませんか?! http://forum.pdfsharp.net/viewtopic.php?f=2&t=2003&p=5737#p5737

敬具、

4

1 に答える 1

4

フォーラムで彼らからの返答や助けが得られなかったので、これはPDFシャープの制限だったと思います。そこでコードを開き、エラーを修正するために次の変更を加えました。まず、SecurityHandler.csクラスに新しいプロパティを追加しました

public string OwnerPassword
{
  set { SecurityHandler.OwnerPassword = value; }
}

/// <summary>
/// TODO: JOSH
/// </summary>
public bool MaintainOwnerAndUserPassword
{
    get { return SecurityHandler.MaintainOwnerAndUserPassword; }
    set { SecurityHandler.MaintainOwnerAndUserPassword = value; }
}

次に、PdfDocument.csクラスのdoSaveメソッドを次のように変更しました。

    void DoSave(PdfWriter writer)
{
  if (this.pages == null || this.pages.Count == 0)
    throw new InvalidOperationException("Cannot save a PDF document with no pages.");

  try
  {
    bool encrypt = this.securitySettings.DocumentSecurityLevel != PdfDocumentSecurityLevel.None;
    if (encrypt)
    {
      PdfStandardSecurityHandler securityHandler = this.securitySettings.SecurityHandler;
      if (securityHandler.Reference == null)
        this.irefTable.Add(securityHandler);
      else
        Debug.Assert(this.irefTable.Contains(securityHandler.ObjectID));
      this.trailer.Elements[PdfTrailer.Keys.Encrypt] = this.securitySettings.SecurityHandler.Reference;
    }
    else
      this.trailer.Elements.Remove(PdfTrailer.Keys.Encrypt);

    PrepareForSave();

    if (encrypt && !securitySettings.SecurityHandler.MaintainOwnerAndUserPassword)
      this.securitySettings.SecurityHandler.PrepareEncryption();

...

最後に、PDFSecuritySettings.csのCanSaveメソッドを次のように変更しました。

    internal bool CanSave(ref string message)
{
  if (this.documentSecurityLevel != PdfDocumentSecurityLevel.None)
  {
    if ((SecurityHandler.userPassword == null || SecurityHandler.userPassword.Length == 0) &&
        (SecurityHandler.ownerPassword == null || SecurityHandler.ownerPassword.Length == 0) &&
        !SecurityHandler.MaintainOwnerAndUserPassword)
    {
      message = PSSR.UserOrOwnerPasswordRequired;
      return false;
    }
  }
  return true;
}

これにより、MaintainOwnerAndUserPassword設定を設定できるようになり、ハッシュ化されたユーザー名とパスワードが既にあると仮定すると、正常に機能し、ダンディになります。

何度も何度も。

于 2012-05-08T00:36:47.557 に答える