public PipelineInputPdf(string filename, PipelineFactory factory, PipelineInputCache <IProcessBlockData> cache = null)
        {
            if (factory == null)
            {
                throw new ArgumentNullException(nameof(factory));
            }

            var pdfDocument = new PdfDocument(VirtualFS.OpenPdfReader(filename));

            InitDocument(pdfDocument, factory);

            this._input           = filename;
            this._pdfDocument     = pdfDocument;
            this._documentFactory = factory;

            if (cache != null)
            {
                cache.SetSize(_pdfDocument.GetNumberOfPages());
                this._cache = cache;
            }

            PipelineInputPdf.DebugCurrent = this;

            PdfReaderException.ClearContext();
        }
Example #2
0
        static public void ShowException(PipelineInputPdf pdf, Exception ex)
        {
            PdfReaderException pdfException = ex as PdfReaderException;

            string component = FindPdfCoreComponent(ex.StackTrace);

            if (pdfException == null)
            {
                string text = component + "\n" + ex.Message + "\n" + ex.StackTrace;

                var white = System.Drawing.Color.FromArgb(230, 250, 250, 250);

                pdf.CurrentPage.DrawBackground(white);
                pdf.CurrentPage.DrawWarning(text, 20, Color.Red);
            }
            else
            {
                string text = $"({component}) {pdfException.ShortMessage}";

                var white  = System.Drawing.Color.FromArgb(100, 200, 200, 200);
                var yellow = System.Drawing.Color.FromArgb(100, 250, 250, 0);
                var blue   = System.Drawing.Color.FromArgb(100, 0, 0, 250);

                pdf.CurrentPage.DrawBackground(white);
                pdf.CurrentPage.DrawWarning(text, 12, Color.Red);

                var additionalInfo = pdfException.Blocks;
                if (additionalInfo != null)
                {
                    foreach (var block in additionalInfo)
                    {
                        float width  = block.GetWidth();
                        float height = block.GetHeight();

                        bool invalidBoundary = false;

                        if (width <= 3f)
                        {
                            width = 3f; invalidBoundary = true;
                        }
                        if (height <= 3f)
                        {
                            height = 3f; invalidBoundary = true;
                        }

                        if (invalidBoundary)
                        {
                            pdf.CurrentPage.FillRectangle(block.GetX(), block.GetH(), width, height, blue);
                            pdf.CurrentPage.DrawRectangle(block.GetX(), block.GetH(), width, height, Color.DarkRed);
                        }
                        else
                        {
                            pdf.CurrentPage.FillRectangle(block.GetX(), block.GetH(), width, height, yellow);
                            pdf.CurrentPage.DrawRectangle(block.GetX(), block.GetH(), width, height, Color.DarkRed);
                        }
                    }
                }
            }
        }
Example #3
0
 static public void Show(PipelineInputPdf pdf, System.Collections.IEnumerable objectList, Color color)
 {
     foreach (var t in objectList)
     {
         var b = (IBlock)t;
         pdf.CurrentPage.DrawRectangle(b.GetX(), b.GetH(), b.GetWidth(), b.GetHeight(), color);
     }
 }
Example #4
0
        public PipelineInputPdf Input(string filename)
        {
            var context = new PipelineInputPdf(filename);

            this._activeContext = context;
            this._inputFilename = filename;

            return(context);
        }
Example #5
0
        static public void Show(PipelineInputPdf pdf, BlockPage blockPage, Color color)
        {
            var blocks = blockPage.AllBlocks;

            foreach (var b in blocks)
            {
                pdf.CurrentPage.DrawRectangle(b.GetX(), b.GetH(), b.GetWidth(), b.GetHeight(), color);
            }
        }
Example #6
0
            public PipelineInputPdfPage(PipelineInputPdf pipelineInputContext, int pageNumber)
            {
                var pdfPage = pipelineInputContext._pdfDocument.GetPage(pageNumber);

                this._pdf        = pipelineInputContext;
                this._pageNumber = pageNumber;
                this._pdfPage    = pdfPage;

                PdfReaderException.SetContext(_pdf._input, pageNumber);
            }
Example #7
0
        public void Dispose()
        {
            var disposable = _activeContext as IDisposable;

            if (disposable != null)
            {
                disposable.Dispose();
            }

            _activeContext = null;
        }
Example #8
0
        public PipelineInputPdf(string filename)
        {
            var pdfDocument = new PdfDocument(VirtualFS.OpenPdfReader(filename));

            this._input       = filename;
            this._pdfDocument = pdfDocument;

            PipelineInputPdf.DebugCurrent = this;

            PdfReaderException.ClearContext();
        }
Example #9
0
        static public void ShowText(PipelineInputPdf pdf, BlockPage blockPage, Color color)
        {
            var blocks = blockPage.AllBlocks;

            foreach (var b in blocks)
            {
                float diff = 2f;
                pdf.CurrentPage.DrawRectangle(b.GetX() + diff / 2, b.GetH() + diff / 2, b.GetWidth() - diff, b.GetHeight() - diff, color);
                pdf.CurrentPage.DrawText(b.GetX(), b.GetH() + b.GetHeight(), b.GetText(), b.GetHeight() / 2, color);
            }
        }
Example #10
0
        static public void ShowLine(PipelineInputPdf pdf, BlockPage blockPage, Color color)
        {
            var blocks = blockPage.AllBlocks;

            float x1 = float.NaN;
            float h1 = float.NaN;

            foreach (var b in blocks)
            {
                float x2 = b.GetX() + b.GetWidth() / 2;
                float h2 = b.GetH() + b.GetHeight() / 2;

                if ((!float.IsNaN(x1)) && (!float.IsNaN(h1)))
                {
                    pdf.CurrentPage.DrawLine(x1, h1, x2, h2, color);
                }

                x1 = x2;
                h1 = h2;
            }
        }
Example #11
0
 public PipelinePage(PipelineInputPdf pdf, int pageNumber)
 {
     this.Context    = pdf;
     this.PageNumber = pageNumber;
 }
Example #12
0
        static public void ShowWarnings(PipelineInputPdf pdf, IEnumerable <string> warnings)
        {
            string text = String.Join("\n", warnings);

            pdf.CurrentPage.DrawWarning(text, 6, Color.Red);
        }
Example #13
0
 static public void Output(PipelineInputPdf pdf, string filename)
 {
     pdf.Output(filename);
 }