나는 보통 pdf, 디지털 서명 된 pdf 및 암호를 사용하여 programatically C#을 사용하여 pdf의 다른 유형에 워터 마크를 추가해야합니다. 나는 아래의 코드를 사용하여 디지털 서명 된 일반 pdf 및 일부 pdf 워터 마크 수 있지만 디지털 서명 및 보안이 보호 된 다른 pdf 작동하지 않습니다. 누구든지 itextsharp을 사용하여 pdf 보안을 제거하는 방법을 말해 줄 수 있습니다. 그래야 워터 마킹이 가능합니다.PDF와 워터 마크의 보안을 제거하기 위해 itextsharp를 사용하는 방법 pdf
다음 코드는 보안이 설정되어 있지 않지만 보안이 설정된 pdf에 워터 마크를 삽입 할 수없는 일반 pdf에 워터 마크를 추가 할 수 있습니다.
public void AddWatermarkText(string sourceFile, string outputFile,
string watermarkText, iTextSharp.text.pdf.BaseFont watermarkFont, float
watermarkFontSize, iTextSharp.text.Color watermarkFontColor, float
watermarkFontOpacity, float watermarkRotation)
{
iTextSharp.text.pdf.PdfReader reader = null;
iTextSharp.text.pdf.PdfStamper stamper = null;
iTextSharp.text.pdf.PdfGState gstate = null;
iTextSharp.text.pdf.PdfContentByte underContent = null;
iTextSharp.text.Rectangle rect = null;
int pageCount = 0;
try
{
{
reader = new iTextSharp.text.pdf.PdfReader(sourceFile);
rect = reader.GetPageSizeWithRotation(1);
stamper = new PdfStamper(reader, new System.IO.FileStream(outputFile, System.IO.FileMode.CreateNew), '\0', true);
if (watermarkFont == null)
{
watermarkFont =iTextSharp.text.pdf.BaseFont.CreateFont(iTextSharp.text.pdf.BaseFont.HELVETICA,iTextSharp.text.pdf.BaseFont.CP1252,iTextSharp.text.pdf.BaseFont.NOT_EMBEDDED);
}
if (watermarkFontColor == null)
{
watermarkFontColor = iTextSharp.text.Color.BLUE;
}
gstate = new iTextSharp.text.pdf.PdfGState();
gstate.FillOpacity = watermarkFontOpacity;
gstate.StrokeOpacity = watermarkFontOpacity;
pageCount = reader.NumberOfPages;
for (int i = 1; i <= pageCount; i++)
{
underContent = stamper.GetUnderContent(i);
//_with1 = underContent;
underContent.SaveState();
underContent.SetGState(gstate);
underContent.SetColorFill(watermarkFontColor);
underContent.BeginText();
underContent.SetFontAndSize(watermarkFont,watermarkFontSize);
underContent.SetTextMatrix(30, 30);
underContent.ShowTextAligned(iTextSharp.text.Element.ALIGN_CENTER,watermarkText,rect.Width/2, rect.Height/2, watermarkRotation);
underContent.EndText();
underContent.RestoreState();
}
}
stamper.Close();
reader.Close();
}
catch (Exception ex)
{
throw ex;
}
}
감사
전체 보안 보호 요점은 문서를 수정할 수 없다는 점입니다. –