示例#1
0
 public SvgClipPathPageElement(PageElement child, SvgClipPathElement clipPath, SvgMatrix clipPathParentTransform, PdfSpotColor spotColorOverride)
 {
     _spotColorOverride       = spotColorOverride;
     _child                   = child ?? throw new ArgumentNullException(nameof(child));
     _clipPath                = clipPath ?? throw new ArgumentNullException(nameof(clipPath));
     _clipPathParentTransform = clipPathParentTransform ?? throw new ArgumentNullException(nameof(clipPathParentTransform));
 }
示例#2
0
 /// <summary>
 /// Initializes a new instance of <see cref="SvgPathSegToDynamicPdfPathsConverter"/> using the specified <see cref="graphicsElement"/>
 /// for the styling properties of the resulting paths
 /// </summary>
 public SvgPathSegToDynamicPdfPathsConverter(SvgGraphicsElement graphicsElement, VectorElementPdfPageViewport pageViewport, float pageHeight, PdfSpotColor spotColorOverride)
 {
     _spotColorOverride = spotColorOverride;
     _pageViewport      = pageViewport;
     _pageHeight        = pageHeight;
     SetFillStyle(graphicsElement);
     SetStrokeStyle(graphicsElement);
 }
示例#3
0
 public SvgElementToDynamicPdfElementConverter(SvgSvgElement rootSvgElement, VectorElementPdfPageViewport pageViewport, float pageHeight, PdfSpotColor spotColorOverride)
 {
     _spotColorOverride = spotColorOverride;
     _rootSvgElement    = rootSvgElement ?? throw new ArgumentNullException(nameof(rootSvgElement));
     _pageViewport      = pageViewport ?? throw new ArgumentNullException(nameof(pageViewport));
     _pageHeight        = pageHeight;
     _matrixStack.Push(SvgMatrix.Identity);
 }
示例#4
0
        public void QuickTest()
        {
            var svgFilePath = Path.Combine(Utils.TestFolder, "Test", "Tiger.svg");

            Debug.WriteLine($"Testing QuickTest: {Path.GetFileName(svgFilePath)} in {Path.GetDirectoryName(svgFilePath)}");
            Document document = new Document
            {
                Creator = "PNI",
                Author  = "PNI"
            };
            var  spotColorInk = new PdfSpotColorInk("MyCol", new CmykColor(0, 255, 0, 0));
            var  spotColor    = new PdfSpotColor(1, spotColorInk);
            Page page         = new Page(PageSize.Letter, PageOrientation.Portrait, 54.0f);
            var  svgDocument  = SvgDocument.Parse(File.ReadAllText(svgFilePath));
            var  pageElement  = Renderer.CreateSvgImagePageElement(svgDocument, new Rectangle(0, 0, 300, 300), HorizontalAlignment.Center, VerticalAlignment.Center, spotColor);

            page.Elements.Add(pageElement);
            document.Pages.Add(page);
            document.Draw(Path.Combine(Path.GetDirectoryName(svgFilePath), Path.GetFileNameWithoutExtension(svgFilePath) + ".pdf"));
        }
示例#5
0
        public static PageElement CreateSvgImagePageElement(SvgDocument document, Rectangle bounds, HorizontalAlignment horizontalAlignment, VerticalAlignment verticalAlignment, PdfSpotColor spotColorOverride)
        {
            var svg          = document.RootElement;
            var boundsWidth  = (float)bounds.Width;
            var boundsHeight = (float)bounds.Height;

            if (svg.WidthAsLength == null || svg.HeightAsLength == null)
            {
                svg.Width  = boundsWidth;
                svg.Height = boundsHeight;
            }

            if (svg.WidthAsLength?.LengthType == SvgLengthType.Percentage)
            {
                svg.Width = boundsWidth * (svg.WidthAsLength?.ValueInSpecifiedUnits / 100);
            }

            if (svg.HeightAsLength?.LengthType == SvgLengthType.Percentage)
            {
                svg.Height = boundsHeight * (svg.HeightAsLength?.ValueInSpecifiedUnits / 100);
            }

            var svgElement = new SvgPageElement(document, bounds, horizontalAlignment, verticalAlignment);

            svgElement.SpotColorOveride = spotColorOverride;
            var shouldClip = horizontalAlignment == HorizontalAlignment.Stretch || verticalAlignment == VerticalAlignment.Stretch;

            return(shouldClip ? (PageElement) new ClippingGroup(bounds, svgElement) : svgElement);
        }