为什么在使用Android中的iText库将图像转换为PDF时会被裁剪掉图像

问题描述 投票:6回答:2

在我的应用程序中,我希望将用户选择的图像转换为一个PDF文件。我正在使用许多人建议的iText库。用户选择多张图像,并以此创建一个pdf,其中每张图像均为1 pdf页面。

我正在使用的代码如下:>

    Document document = new Document(PageSize.A4);
            try {

                String path = Environment.getExternalStorageDirectory()+"/PDFile.pdf";

                File file= new File(path);

                if(file.exists())
                {

                }
                else
                {
                    file.createNewFile();
                }


                PdfWriter.getInstance(document,new FileOutputStream(path));

                document.open();

                for(int i =0; i<pdfImage.size();i++)
                {
                    Image image = Image.getInstance(pdfImage.get(i));
                    image.scaleAbsolute(PageSize.A4);
                    image.setAbsolutePosition(0, 0);
                    document.add(image);

                }

                document.close();



            } catch (Exception e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }

正在生成pdf,但是图像被裁剪。仅可见图像的一半,其余部分被裁剪。

我是否需要为pdf设置任何尺寸以采用图像尺寸?

或者我是否必须更改或调整图像大小以采用pdf页面大小?

请帮助!!我不知道该如何解决???

在我的应用程序中,我希望将用户选择的图像转换为一个PDF文件。我正在使用许多人建议的iText库。用户选择了多个图像,一个pdf是...

android pdf itext
2个回答
11
投票

执行此操作时:

Document document = new Document();

0
投票

[这是一篇旧文章,您可能已经对此进行了整理,但是另一种选择是在iText中使用表格。

© www.soinside.com 2019 - 2024. All rights reserved.