1
(그려진) 서명이있는 png 이미지를 PDFSharp로 PDF에 삽입하려고합니다. 이미지의 위치와 크기는 이전에 PDF에서 생성 한 보이지 않는 PdfTextField에 의해 결정됩니다. 현재 코드의 문제는 다음과 같습니다. PdfTextField (이 필드가 포함 된 페이지)에서 페이지 참조를 얻으려면 어떻게해야합니까?PDFSharp 위치 및 크기 참조로 PdfTextField를 사용하여 pdf에 이미지 삽입
코드 :
protected int PaginaCampo(string campofirma, PdfDocument document)
{
for (int i = 0; i < document.Pages.Count; i++)
{
PdfAnnotations anotations = document.Pages[i].Annotations;
for (int j = 0; j < anotations.Count; j++)
{
if (anotations[j].Title != campofirma) continue;
return i;
}
}
return -1;
}
아니 최고의 솔루션 있지만 작동 ... 사람이 하나 더 추가하는 경우 우리가를 줄 것이다 : 결국
PdfDocument document = PdfReader.Open("C:\\filex.pdf", PdfDocumentOpenMode.Modify);
// Get the root object of all interactive form fields
PdfAcroForm form = document.AcroForm;
// Get all form fields of the whole document
PdfAcroField.PdfAcroFieldCollection fields = form.Fields;
//Get the invisible PdfTextField used as position and size reference
PdfTextField signatureposition= (PdfTextField)fields["thesignature"];
PdfArray signaturerect= (PdfArray)signatureposition.Elements["/Rect"];
string x = signaturerect.Elements[0].ToString();
string y = signaturerect.Elements[1].ToString();
string w = signaturerect.Elements[2].ToString();
string h = signaturerect.Elements[3].ToString();
string imagepath= "C:\\signature.png";
//how to get the correct page reference respect the especified field?
PdfPage page= signatureposition.Owner.Pages[???];
XGraphics gfx = XGraphics.FromPdfPage(page);
XImage image = XImage.FromFile(imagepath);
gfx.DrawImage(image, x, y, width, height);
campofirma는 무엇을 나타 냅니까? 그것의 문자열은 firma의 png (서명?) –