2012-05-04 2 views
1

2 가지 다른 이유로 2 가지 응용 프로그램에서 PDFSharp를 사용하고 있습니다. 첫 번째는 문서를 암호로 보호하고 두 번째는 문서를 워터 마크하는 것입니다. 이러한 프로세스는 둘 다 자체 응용 프로그램/워크 플로에서 개별적으로 작동합니다. 문제는 응용 프로그램 1은 암호 만 알고 응용 프로그램 2는 워터 마크를 알고 응용 프로그램 1은 기본 소유자 암호와 동적 사용자 암호를 사용하고 응용 프로그램 2는 워터 마크를 적용하기 위해 소유자 암호로 문서를 엽니 다. 문제는 암호가 지속되지 않는다는 것입니다. 문서를 저장하는 동안 PDFSharp가 이전 PDF 암호를 무시하는 것 같습니다.PDFSharp 문서 열기 및 저장하기 암호 제거

명시 적으로 암호를 다시 정의하지 않고도 워터 마크를 적용 할 때 보안 설정을 유지할 수 있습니까?

나는 이것을 PDFSharp 포럼에 올렸지 만, 그것을 무시하고있는 것은 좋은 징조가 아닐까요?! http://forum.pdfsharp.net/viewtopic.php?f=2&t=2003&p=5737#p5737

친절 감사를

답변

4

나는 이것이 내가 응답을 얻지로, 날카로운 PDF의 제한이었다 또는이 포럼에 그들로부터 도움을 생각합니다. 거기에 코드를 열고 다음과 같이 변경하여 오류를 수정했습니다.

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(); 

... 

마지막으로 나는 CanSave 방법을 변경 : 첫째로 나는 다음과 같이보고 나는 PdfDocument.cs 클래스에 doSave 방법을 변경

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

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

SecurityHandler.cs 클래스에 새로운 속성을 추가 이에 PDFSecuritySettings.cs에 :

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 설정 등을 설정할 수 있도록한다 그것은 잘 작동하고 멋지게 작동해야합니다.

오버 및 아웃.