Itext不渲染base64变换旋转图像

时间:2017-05-30 17:45:32

标签: html css image itext

我正在尝试使用变换旋转在html中旋转base64嵌入图像,图像在html页面中旋转正常,但是当我尝试使用itext在pdf中渲染相同时,转换属性无效。 下面是我的示例HTML代码。

<?xml version="1.0" encoding="utf-8"?>
<html>
    <head>
        <style type="text/css">
            body,div,td,th,span,h1,h2 {
                font:9pt/12pt "Roboto", serif;
            }
           .fleft {
                float:left;
                overflow-x: wrap;
            }
            .rotate90 {
                -webkit-transform: rotate(90deg);
                -moz-transform: rotate(90deg);
                -o-transform: rotate(90deg);
                -ms-transform: rotate(90deg);
                transform: rotate(90deg);
            }
            .gift-icon{
                width: 21mm;
                height: 21mm;
            }
        </style>
    </head>
    <body>
        <div>
            <img class="fleft gift-icon rotate90" alt="" src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAEAAAABACAYAAACqaXHeAAAACXBIWXMAAAsTAAALEwEAmpwYAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAACCtJREFUeNrsWltsFUUY/meLWNpSq4HCgwptEVCKralAixgKRXnBUNQHjJhgVUQJCT4Y0RgDicZrTInog9FKBE1IBIvigwFsQQyXILRAMJHaHgoSSn0A7CkK7f7OzN5mZmf3XFse3DmZM7szuzPzf/91/nMAohKVqEQlKlGJSlSiEpWoROV/WEimE/z6e2wxbRppnWh3NTu1avLEy9naqL1OvV2LaL3E1qVrrL9hANBNVdCmLWjcIKSZ8ArNFWV3+sA42XXuFgZcecnt7br32zq6FyNiPQKtyIn2lavxvnfm3Ff+6o0C4AvaLD9y6CA0vvsW5OXlQ9Wsarif1hnVNXRy+iFgtxYQtI1RotYwThJ7B5Q4Ti8da6RjdByWM6KBEk1bPh7r/AP2/rQb2Fp/9V6Eqpmz4KW1r8P1a//+c+rwL8saGhq2pUPDiAwlk4v9jzt38Jv+/jj83LIH9tOal58PM2bVwIya2TCTgUFIvUM0MQyOfDzeB/G+OBSPG0fJhEoKxSYGFt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PnO0+fpJdLw9JhKUmA/a+LWva/vCSDRH8C04723ISnkufz+k35+SSJZ5y/0N3VQYmP0dtvEhGfVo6b/RuLNmshzf/kDEPpsxOh2yAqUYlKVKISlaiElf8EGADHKf1yLEzw7QAAAABJRU5ErkJggg=="/>  
        </div>
    </body>
</html>

我正在使用ReplacedElementFactory重新生成图像,尽管图像的宽度和高度正在正确渲染,但图像不会旋转。 请在下面找到ReplacedElementFactory类。

public class B64ImgReplacedElementFactory implements ReplacedElementFactory {

    public ReplacedElement createReplacedElement(LayoutContext c, BlockBox box, UserAgentCallback uac, int cssWidth, int cssHeight) {
        Element e = box.getElement();
        if (e == null) {
            return null;
        }
        String nodeName = e.getNodeName();
        if (nodeName.equals("img")) {
            String attribute = e.getAttribute("src");
            FSImage fsImage;
            try {
                fsImage = buildImage(attribute, uac);
            } catch (BadElementException e1) {
                fsImage = null;
            } catch (IOException e1) {
                fsImage = null;
            }
            if (fsImage != null) {
                if (cssWidth != -1 || cssHeight != -1) {
                    fsImage.scale(cssWidth, cssHeight);
                }
                return new ITextImageElement(fsImage);
            }
        }
        return null;
    }

    protected FSImage buildImage(String srcAttr, UserAgentCallback uac) throws IOException, BadElementException {
        FSImage fsImage;
        if (srcAttr.startsWith("data:image/")) {
            String b64encoded = srcAttr.substring(srcAttr.indexOf("base64,") + "base64,".length(), srcAttr.length());
            byte[] decodedBytes = Base64.decode(b64encoded);
            fsImage = new ITextFSImage(Image.getInstance(decodedBytes));
        } else {
            fsImage = uac.getImageResource(srcAttr).getImage();
        }
        return fsImage;
    }

    public void remove(Element e) {
    }

    public void reset() {
    }

    @Override
    public void setFormSubmissionListener(FormSubmissionListener listener) {
    }
}

有人可以帮我解决这个问题吗? 提前致谢

0 个答案:

没有答案