We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy.
Unfortunately, activation email could not send to your email. Please try again.

How to Sign the PDF document using SfPdfViewerControl in WinRT Platform?

How to Sign the PDF document using SfPdfViewerControl in WinRT Platform?

We do not have support for applying Signature in PDF document using SfPdfViewerControl in WinRT at present. However, as a workaround we can Sign the PDF Document by finding the X and Y Coordinates of the PDF document where you can place the signature.

  1. Code Snippet for updating the document once signature is applied

Class: AnnotationEditorViewModel.cs

private void UpdateDocumentCommandClick(object obj)

{

if (IsInEditMode)

{

var signPoints = View.CanvasView.AllPoints;

 

if (signPoints != null && signPoints.Count > 0)

{

 

PdfPen pen = new PdfPen(new PdfColor(Constants.SignatureColor.R, Constants.SignatureColor.G, Constants.SignatureColor.B), (float)Constants.SigntureThickness / 2.5f);

var path = new PdfPath();

foreach (var sigPoint in signPoints)

{

var linePath = new PdfPath();

for (int i = 0; i < sigPoint.Count - 1; i++)

{

var start = GetDocumentXYPosition(sigPoint[i].X * ScreenToPageConversion, sigPoint[i].Y * ScreenToPageConversion);

var end = GetDocumentXYPosition(sigPoint[i + 1].X * ScreenToPageConversion, sigPoint[i + 1].Y * ScreenToPageConversion);

 

linePath.AddLine(start, end);

}

 

path.AddPath(linePath);

}

 

 

_loadedDocument.Pages[View.CurrentPageIndex].Graphics.DrawPath(pen, path);

 

_loadedDocument.Save();

View.PdfView.ZoomTo(View.PdfView.Zoom);

View.PdfView.LoadDocument(_loadedDocument);

View.NaviFrame.Navigate(typeof(PdfEditorView), _loadedDocument);

}

 

View.CanvasView.ClearSignPanel();

}

 

this.IsInEditMode = !this.IsInEditMode;

SetZIndexValues();

}

  1. Code Snippet to find the X and Y coordinates in a particular page of PDF Document:

Class: AnnotationEditorViewModel.cs

private PointF GetDocumentXYPosition(double pX, double pY)

{

int currentPageNumber;

float zoomConversionFactor = _zoomFactor / 100.0f;

double pageWidth = _loadedDocument.Pages[View.CurrentPageIndex].Size.Width * zoomConversionFactor;

double pageHeight = _loadedDocument.Pages[View.CurrentPageIndex].Size.Height * zoomConversionFactor;

float pixelPageHeight = _converter.ConvertToPixels((float)pageHeight, PdfGraphicsUnit.Point);

float pixelPageWidth = _converter.ConvertToPixels((float)pageWidth, PdfGraphicsUnit.Point);

float offsetPixelsX, offsetPixelsY;

if (View.ActualWidth > pixelPageWidth)

{

offsetPixelsX = ((float)View.PdfView.ActualWidth - pixelPageWidth);

offsetPixelsX = (offsetPixelsX / 2.0f);

}

else

{

offsetPixelsX = (zoomConversionFactor) - View.PdfView.HorizontalOffset;

}

if (View.PdfView.VerticalOffset < pixelPageHeight)

{

offsetPixelsY = View.PdfView.VerticalOffset -

(View.PdfView.PageGap * zoomConversionFactor);

}

else

{

offsetPixelsY = (View.CurrentPageIndex *

((View.PdfView.VerticalOffset / (View.CurrentPageIndex)) - pixelPageHeight)) -

(View.PdfView.PageGap * (View.CurrentPageIndex + 1) * zoomConversionFactor);

}

 

var pointX = (float)pX;

var pointY = (float)pY;

float currentImageLocationY = (View.PdfView.VerticalOffset + pointY) / zoomConversionFactor;

 

float x = 0.0f, y = 0.0f;

 

 

currentPageNumber = (int)Math.Floor(currentImageLocationY / (pixelPageHeight / zoomConversionFactor));

 

x = _converter.ConvertFromPixels((pointX - offsetPixelsX), PdfGraphicsUnit.Point);

y = _converter.ConvertFromPixels((offsetPixelsY + pointY), PdfGraphicsUnit.Point);

 

x = x / zoomConversionFactor;

y = y / zoomConversionFactor;

 

 

Debug.WriteLine("X={0}, y={1} -- pX={2}, pY={3}", x, y, pX, pY);

return new PointF(x, y);

}

Here we are drawing the signature by passing the appropriate Page of PDF document as parameter using Xaml Navigation:

  1. Code Snippet for Xaml Navigation is as follows.

Class Name : AnnotViewer.xaml.cs

protected override void OnNavigatedTo(NavigationEventArgs e)

{

List<object> parameterList = e.Parameter as List<object>;

 

_viewModel.LoadedDocument = parameterList[0] as PdfLoadedDocument;

pageIndex = int.Parse(parameterList[1].ToString());

zoomFactor = int.Parse(parameterList[2].ToString());

_currentPageIndex = pageIndex;

 

float pagewidth = _viewModel.LoadedDocument.Pages[pageIndex].Size.Width;

float pageHeight = _viewModel.LoadedDocument.Pages[pageIndex].Size.Height;

 

annotViewer = new SfPdfViewerControl();

annotViewer.LoadDocument(_viewModel.LoadedDocument);

PdfView = annotViewer;

 

Image image = annotViewer.GetPage(pageIndex, 300);

image.Width =

unitConvertor.ConvertToPixels(pagewidth, PdfGraphicsUnit.Point);

image.Height = unitConvertor.ConvertToPixels(pageHeight, PdfGraphicsUnit.Point);

AnnotSp.Children.Add(image);

}

Please find the sample in the following link:

http://www.syncfusion.com/downloads/support/directtrac/138259/SignatureSample611423179.zip

 

Article ID: Published Date: Last Revised Date: Platform: Control: .NET Framework: Product Version:
5016 05/25/2015 12/11/2015 WinRT PDF 4.5.1 12.4.0.24
Did you find this information helpful?
Add Comment
You must log in to leave a comment

You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.