コード例 #1
0
        /* (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()));
        }
コード例 #2
0
 private void ApplyHtmlBodyStyles(PdfPage page, float[] defaultMargins) {
     BodyHtmlStylesContainer[] styles = new BodyHtmlStylesContainer[2];
     styles[0] = ((IPropertyContainer)document).GetProperty<BodyHtmlStylesContainer>(Html2PdfProperty.HTML_STYLING
         );
     styles[1] = ((IPropertyContainer)document).GetProperty<BodyHtmlStylesContainer>(Html2PdfProperty.BODY_STYLING
         );
     int firstBackground = ApplyFirstBackground(page, defaultMargins, styles);
     for (int i = 0; i < 2; i++) {
         if (styles[i] != null) {
             if (styles[i].HasContentToDraw()) {
                 DrawSimulatedDiv(page, styles[i].properties, defaultMargins, firstBackground != i);
             }
             for (int j = 0; j < 4; j++) {
                 defaultMargins[j] += styles[i].GetTotalWidth()[j];
             }
         }
     }
 }