当前位置: 首页>>代码示例>>C#>>正文


C# Windows.GetPage方法代码示例

本文整理汇总了C#中Windows.GetPage方法的典型用法代码示例。如果您正苦于以下问题:C# Windows.GetPage方法的具体用法?C# Windows.GetPage怎么用?C# Windows.GetPage使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Windows的用法示例。


在下文中一共展示了Windows.GetPage方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: SaveInkingToPdf

        /// <summary>
        /// Save the ink annotations into the pdf file.
        /// </summary>
        /// <param name="inkManager"></param>
        /// <returns></returns>
        /// <remarks>
        /// The page size returned from Syncfusion pdf is the media box size.
        /// The page size displayed to the end user is the crop box size.
        /// The size of the ink canvas is the same as the crop box size.
        /// Syncfusion uses the bottom left corner as the origin, while ink canvas uses the top left corner.
        /// </remarks>
        public async Task<bool> SaveInkingToPdf(InkingManager inkManager, Windows.Data.Pdf.PdfDocument pdfDoc)
        {
            // Indicate whether any ink annotation is added to the PDF file
            bool fileChanged = false;
            // Add ink annotations for each page
            foreach (KeyValuePair<int, InkStrokeContainer> entry in inkManager.InkDictionary)
            {
                // The key of the dictionary is page number, which is 1-based. Page index is 0-based.
                int pageIndex = entry.Key - 1;
                PdfLoadedPage sfPage = pdf.Pages[pageIndex] as PdfLoadedPage;
                // Get page information from MS model
                Windows.Data.Pdf.PdfPage msPage = pdfDoc.GetPage((uint)pageIndex);
                int rotation = (int)msPage.Rotation;
                // The page size returned from Syncfusion pdf is the media box size.
                double scaleRatio = sfPage.Size.Width / msPage.Dimensions.MediaBox.Width;

                // The ink canvas size is the same as crop box
                // Crop box could be smaller than media box
                // There will be an offset if the crop box is smaller than the media box.
                double xOffset = msPage.Dimensions.CropBox.Left * scaleRatio;
                double yOffset = msPage.Dimensions.CropBox.Top * scaleRatio;
                RectangleF rectangle = new RectangleF(0, 0, sfPage.Size.Width, sfPage.Size.Height);
                // Add each ink stroke to the page
                foreach (InkStroke stroke in entry.Value.GetStrokes())
                {
                    List<float> strokePoints = new List<float>();
                    foreach (InkPoint p in stroke.GetInkPoints())
                    {
                        float X = (float)(p.Position.X * scaleRatio + xOffset);
                        float Y = (float)(p.Position.Y * scaleRatio + yOffset);
                        switch (rotation)
                        {
                            case 0: // No rotation
                                {
                                    strokePoints.Add(X);
                                    strokePoints.Add(sfPage.Size.Height - Y);
                                    break;
                                }
                            case 1: // 90-degree rotation
                                {
                                    strokePoints.Add(Y);
                                    strokePoints.Add(X);
                                    break;
                                }
                            case 2: // 180-degree rotation
                                {
                                    strokePoints.Add(sfPage.Size.Width - X);
                                    strokePoints.Add(Y);
                                    break;
                                }
                            case 3: // 270-degree rotation
                                {
                                    strokePoints.Add(sfPage.Size.Height - Y);
                                    strokePoints.Add(sfPage.Size.Width - X);
                                    break;
                                }
                        }
                    }
                    PdfInkAnnotation inkAnnotation = new PdfInkAnnotation(rectangle, strokePoints);
                    // Color
                    inkAnnotation.Color = new PdfColor(fromUIColor(stroke.DrawingAttributes.Color));
                    // Size
                    inkAnnotation.BorderWidth = (int) Math.Round(stroke.DrawingAttributes.Size.Width * scaleRatio);
                    sfPage.Annotations.Add(inkAnnotation);
                    fileChanged = true;
                }
            }
            bool inkSaved = false;
            // Save the file only if there are changes.
            if (fileChanged)
            {
                try
                {
                    inkSaved = await pdf.SaveAsync(pdfFile);
                }
                catch (Exception ex)
                {
                    App.NotifyUser(typeof(ViewerPage), "Error: \n" + ex.Message, true);
                }
            }
            //pdf.Close(true);
            return !(inkSaved ^ fileChanged);
        }
开发者ID:qiuosier,项目名称:Libra,代码行数:94,代码来源:SFPdfModel.cs

示例2: ScaleRatio

 /// <summary>
 /// Return the page size ratio of SF Model / MS model
 /// </summary>
 /// <param name="pdfDoc"></param>
 /// <returns></returns>
 public double ScaleRatio(Windows.Data.Pdf.PdfDocument pdfDoc)
 {
     PdfLoadedPage sfPage = pdf.Pages[0] as PdfLoadedPage;
     Windows.Data.Pdf.PdfPage msPage = pdfDoc.GetPage(0);
     return sfPage.Size.Width / msPage.Dimensions.MediaBox.Width;
 }
开发者ID:qiuosier,项目名称:Libra,代码行数:11,代码来源:SFPdfModel.cs


注:本文中的Windows.GetPage方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。