/* (non-Javadoc) * @see com.itextpdf.layout.renderer.DocumentRenderer#addNewPage(com.itextpdf.kernel.geom.PageSize) */ protected override PageSize AddNewPage(PageSize customPageSize) { PdfPage addedPage; int pageNumber = document.GetPdfDocument().GetNumberOfPages() + 1; PageContextProcessor nextProcessor = GetPageProcessor(pageNumber); if (customPageSize != null) { addedPage = document.GetPdfDocument().AddNewPage(customPageSize); } else { addedPage = document.GetPdfDocument().AddNewPage(nextProcessor.GetPageSize()); } nextProcessor.ProcessNewPage(addedPage); float[] margins = nextProcessor.ComputeLayoutMargins(); BodyHtmlStylesContainer[] styles = new BodyHtmlStylesContainer[] { ((IPropertyContainer)document).GetProperty <BodyHtmlStylesContainer>(Html2PdfProperty.HTML_STYLING), ((IPropertyContainer)document).GetProperty <BodyHtmlStylesContainer >(Html2PdfProperty.BODY_STYLING) }; pageStylesPropertiesMap.Put(pageNumber, new HtmlBodyStylesApplierHandler.PageStylesProperties(styles)); UpdateDefaultMargins(styles, margins); SetProperty(Property.MARGIN_TOP, margins[0]); SetProperty(Property.MARGIN_RIGHT, margins[1]); SetProperty(Property.MARGIN_BOTTOM, margins[2]); SetProperty(Property.MARGIN_LEFT, margins[3]); return(new PageSize(addedPage.GetTrimBox())); }
internal virtual void ProcessPage(PdfPage page, int pageNumber) { HtmlBodyStylesApplierHandler.PageStylesProperties pageProperties = pageStylesPropertiesMap.Get(pageNumber); if (pageProperties == null) { return; } PageContextProcessor contextProcessor = htmlDocumentRenderer.GetPageProcessor(pageNumber); pdfCanvas = contextProcessor.DrawPageBackground(page); ApplyHtmlBodyStyles(page, contextProcessor.ComputeLayoutMargins(), pageProperties.styles, pageNumber); pdfCanvas = null; }
/// <summary>Processes the page rules.</summary> /// <param name="rootNode">the root node</param> /// <param name="cssResolver">the CSS resolver</param> /// <param name="context">the processor context</param> public virtual void ProcessPageRules(INode rootNode, ICssResolver cssResolver, ProcessorContext context) { PageContextProperties firstPageProps = PageContextProperties.Resolve(rootNode, cssResolver, context.GetCssContext (), PageContextConstants.FIRST, PageContextConstants.RIGHT); // TODO in documents with set to rtl on root document, first page is considered as left PageContextProperties leftPageProps = PageContextProperties.Resolve(rootNode, cssResolver, context.GetCssContext (), PageContextConstants.LEFT); PageContextProperties rightPageProps = PageContextProperties.Resolve(rootNode, cssResolver, context.GetCssContext (), PageContextConstants.RIGHT); PageSize defaultPageSize = document.GetPdfDocument().GetDefaultPageSize(); float[] defaultPageMargins = new float[] { document.GetTopMargin(), document.GetRightMargin(), document.GetBottomMargin (), document.GetRightMargin() }; firstPageProc = new PageContextProcessor(firstPageProps, context, defaultPageSize, defaultPageMargins); leftPageProc = new PageContextProcessor(leftPageProps, context, defaultPageSize, defaultPageMargins); rightPageProc = new PageContextProcessor(rightPageProps, context, defaultPageSize, defaultPageMargins); handler = new HtmlDocumentRenderer.PageMarginBoxesDrawingHandler().SetHtmlDocumentRenderer(this); document.GetPdfDocument().AddEventHandler(PdfDocumentEvent.END_PAGE, handler); }
/* (non-Javadoc) * @see com.itextpdf.layout.renderer.DocumentRenderer#addNewPage(com.itextpdf.kernel.geom.PageSize) */ protected override PageSize AddNewPage(PageSize customPageSize) { PdfPage addedPage; int numberOfPages = document.GetPdfDocument().GetNumberOfPages(); PageContextProcessor nextProcessor = GetPageProcessor(numberOfPages + 1); if (customPageSize != null) { addedPage = document.GetPdfDocument().AddNewPage(customPageSize); } else { addedPage = document.GetPdfDocument().AddNewPage(nextProcessor.GetPageSize()); } nextProcessor.ProcessNewPage(addedPage); float[] margins = nextProcessor.ComputeLayoutMargins(); ApplyHtmlBodyStyles(addedPage, margins); SetProperty(Property.MARGIN_TOP, margins[0]); SetProperty(Property.MARGIN_RIGHT, margins[1]); SetProperty(Property.MARGIN_BOTTOM, margins[2]); SetProperty(Property.MARGIN_LEFT, margins[3]); return new PageSize(addedPage.GetTrimBox()); }
internal virtual void ProcessPage(PdfDocument pdfDoc, int pageNumber) { PageContextProcessor pageProcessor = htmlDocumentRenderer.GetPageProcessor(pageNumber); pageProcessor.ProcessPageEnd(pageNumber, pdfDoc, htmlDocumentRenderer); }