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(); }
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); } } } } }
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); } }
public PipelineInputPdf Input(string filename) { var context = new PipelineInputPdf(filename); this._activeContext = context; this._inputFilename = filename; return(context); }
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); } }
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); }
public void Dispose() { var disposable = _activeContext as IDisposable; if (disposable != null) { disposable.Dispose(); } _activeContext = null; }
public PipelineInputPdf(string filename) { var pdfDocument = new PdfDocument(VirtualFS.OpenPdfReader(filename)); this._input = filename; this._pdfDocument = pdfDocument; PipelineInputPdf.DebugCurrent = this; PdfReaderException.ClearContext(); }
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); } }
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; } }
public PipelinePage(PipelineInputPdf pdf, int pageNumber) { this.Context = pdf; this.PageNumber = pageNumber; }
static public void ShowWarnings(PipelineInputPdf pdf, IEnumerable <string> warnings) { string text = String.Join("\n", warnings); pdf.CurrentPage.DrawWarning(text, 6, Color.Red); }
static public void Output(PipelineInputPdf pdf, string filename) { pdf.Output(filename); }