Android中合多图片和文字合成PDF文件---路很长

本文介绍在Android中如何将多图片和文字合并成PDF文件。提供了所需技术,包括iTextpdf.jar库用于PDF编辑,以及谷歌提供的PDF预览库。示例代码展示了图片与文字的合并,支持编辑和设置PDF格式。
摘要由CSDN通过智能技术生成

一, Android中合多图片和文字合成PDF文件

如果遇到什么问题可以留言,欢迎你留言,我希望能帮助到你。一直怀着感恩的心,感谢路途遇到过的贵人。


效果图如下:
这个Demo中实现了图片和文字,当然单纯的文字和图片都可以合成pdf。这里我只是展示了图片和文字的合并。文字是写死的。当然你可以通过editText来进行编辑。

image

image

如上图就是我们项目中的需求:这一篇我先写pdf的合成。后面关于智能裁剪方面的我会单独写一篇博客。

第二:需要技术:

1.pdf编辑jar:
iTextpdf.jar这个百度很多,很多csdn都需要钱的。这里需要的直接到我项目里面下载或者去官网下载都免费的。提供了图片和文字合成pdf格式文件,以及文件内容的编辑设置,文字居中标题内容等等。以及图片大小和图片的宽高比例,pdf的页面宽度等。都可以让我们编辑出好看的pdf文件。

**2.pdf文件预览:**谷歌提供了预览pdf文件的库

implementation 'com.github.barteksc:android-pdf-viewer:3.1.0-beta.1'

第三:代码部分:源码:

public class Document implements DocListener, IAccessibleElement {
    public static boolean compress = true;
    public static boolean plainRandomAccess = false;
    public static float wmfFontCorrection = 0.86F;
    protected ArrayList<DocListener> listeners;
    protected boolean open;
    protected boolean close;
    protected Rectangle pageSize;
    protected float marginLeft;
    protected float marginRight;
    protected float marginTop;
    protected float marginBottom;
    protected boolean marginMirroring;
    protected boolean marginMirroringTopBottom;
    protected String javaScript_onLoad;
    protected String javaScript_onUnLoad;
    protected String htmlStyleClass;
    protected int pageN;
    protected int chapternumber;
    protected PdfName role;
    protected HashMap<PdfName, PdfObject> accessibleAttributes;
    protected AccessibleElementId id;

    public Document() {
        this(PageSize.A4);
    }
    /**通过这些构造方法,我想一个pfd的创建随随便便来了吧。
    1.第一个默认的是a4纸的大小。
    2.第二个是默认距离边缘left,top,right,bootom大小。
    3.第三个是设置了很多参数。自己可以看其意思。
    **/
    public Document(Rectangle pageSize) {
        this(pageSize, 36.0F, 36.0F, 36.0F, 36.0F);
    }

    public Document(Rectangle pageSize, float marginLeft, float marginRight, float marginTop, float marginBottom) {
        this.listeners = new ArrayList();
        this.marginLeft = 0.0F;
        this.marginRight = 0.0F;
        this.marginTop = 0.0F;
        this.marginBottom = 0.0F;
        this.marginMirroring = false;
        this.marginMirroringTopBottom = false;
        this.javaScript_onLoad = null;
        this.javaScript_onUnLoad = null;
        this.htmlStyleClass = null;
        this.pageN = 0;
        this.chapternumber = 0;
        this.role = PdfName.DOCUMENT;
        this.accessibleAttributes = null;
        this.id = new AccessibleElementId();
        this.pageSize = pageSize;
        this.marginLeft = marginLeft;
        this.marginRight = marginRight;
        this.marginTop = marginTop;
        this.marginBottom = marginBottom;
    }

    public void addDocListener(DocListener listener) {
        this.listeners.add(listener);
        if (listener instanceof IAccessibleElement) {
            IAccessibleElement ae = (IAccessibleElement)listener;
            ae.setRole(this.role);
            ae.setId(this.id);
            if (this.accessibleAttributes != null) {
                Iterator i$ = this.accessibleAttributes.keySet().iterator();

                while(i$.hasNext()) {
                    PdfName key = (PdfName)i$.next();
                    ae.setAccessibleAttribute(key, (PdfObject)this.accessibleAttributes.get(key))
  • 3
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值