private static PdfBox getPageBox(PdfPage page)
        {
            // Emit Adobe Reader behavior - prefer CropBox, but use MediaBox bounds when
            // some CropBox bound is out of MediaBox area.

            PdfBox mediaBox = page.MediaBox;
            PdfBox cropBox  = page.CropBox;
            double left     = cropBox.Left;
            double bottom   = cropBox.Bottom;
            double right    = cropBox.Right;
            double top      = cropBox.Top;

            if (left < mediaBox.Left || left > mediaBox.Right)
            {
                left = mediaBox.Left;
            }

            if (bottom < mediaBox.Bottom || bottom > mediaBox.Top)
            {
                bottom = mediaBox.Bottom;
            }

            if (right > mediaBox.Right || right < mediaBox.Left)
            {
                right = mediaBox.Right;
            }

            if (top > mediaBox.Top || top < mediaBox.Bottom)
            {
                top = mediaBox.Top;
            }

            return(new PdfBox(left, bottom, right, top));
        }
Пример #2
0
        public RemotePdfStamper(byte[] PdfFile, string StampText)
        {
            string serviceUrl = Config.RemotePdfStamperServiceUrl();
            PdfBox box        = Config.RemotePdfStamperCoords();

            externalStamper.RemotePdfStamper stamper = new externalStamper.RemotePdfStamper();
            stamper.Url = serviceUrl;
            //chiamata AL WS
            _stampedPDF = stamper.RemotePdfStamp(box.Page, box.LeftX, box.LeftY, box.RightX, box.RightY, PdfFile, StampText);
        }
        private static PdfSize getPageSizeInPoints(PdfPage page)
        {
            PdfBox pageArea = getPageBox(page);

            if (page.Rotation == PdfRotation.Rotate90 || page.Rotation == PdfRotation.Rotate270)
            {
                return(new PdfSize(pageArea.Height, pageArea.Width));
            }

            return(pageArea.Size);
        }
        private static PdfSize getPageSizeInPoints(PdfPage page)
        {
            PdfBox pageArea = getPageBox(page);
            double userUnit = page.UserUnit;

            if (page.Rotation == PdfRotation.Rotate90 || page.Rotation == PdfRotation.Rotate270)
            {
                return(new PdfSize(pageArea.Height * userUnit, pageArea.Width * userUnit));
            }

            return(new PdfSize(pageArea.Width * userUnit, pageArea.Height * userUnit));
        }
Пример #5
0
            public static PdfBox RemotePdfStamperCoords()
            {
                string pdfStampSetting = ConfigurationManager.AppSettings["REMOTE_PDF_STAMPER_COORDS"];

                if (string.IsNullOrEmpty(pdfStampSetting))
                {
                    pdfStampSetting = DocsPaUtils.Configuration.InitConfigurationKeys.GetValue("0", "BE_REMOTE_PDF_STAMPER_COORDS");
                }

                // nulla in config non posso continuare -> magari in futuro possiamo pensare a dei config.
                if (string.IsNullOrEmpty(pdfStampSetting))
                {
                    return(null);
                }

                PdfBox retval = new PdfBox(pdfStampSetting);

                return(retval);
            }
        private static void showTextAtRotatedPage(string text, PdfPoint position, PdfPage page, PdfBox pageBox)
        {
            PdfCanvas canvas = page.Canvas;

            if (page.Rotation == PdfRotation.None)
            {
                canvas.DrawString(position.X, position.Y, text);
                return;
            }

            canvas.SaveState();

            switch (page.Rotation)
            {
            case PdfRotation.Rotate90:
                canvas.TranslateTransform(position.Y, pageBox.Height - position.X);
                break;

            case PdfRotation.Rotate180:
                canvas.TranslateTransform(pageBox.Width - position.X, pageBox.Height - position.Y);
                break;

            case PdfRotation.Rotate270:
                canvas.TranslateTransform(pageBox.Width - position.Y, position.X);
                break;
            }
            canvas.RotateTransform((int)page.Rotation * 90);
            canvas.DrawString(0, 0, text);

            canvas.RestoreState();
        }