我必须在
@L_301_0@上将一些文本和一个小图像转换为PDF文档,为此我使用API 19中添加的PdfDocument.
与此相关的是,由此生成的PDF大约是在iOS上生成的PDF的3倍(文件大小).
此外,我尝试使用在线免费压缩工具压缩Android和iOS PDF文件,结果如下:
> iOS:压缩无法做任何事情因为已经足够压缩了
> Android:结果PDF与iOS版相同(约小3倍)
即使我从文档中删除了图像,生成的Android PDF也比iOS中包含图像的PDF大约多2倍的空间(正如我所说,图像很小).
我可以看到,没有方法或属性可以设置来改变PDF文件的质量或压缩..有没有人也有这个问题?
你能给我一些建议吗?也许一些可以压缩pdf的java库?
谢谢!
PS:我不想为PDF使用付费库,我知道有iText库,但我想使用原生库.
UPDATE
Here你发现两个PDF样本一个用于Android,一个用于iOS.
// Create a shiny new (but blank) PDF document in memory PdfDocument document = new PdfDocument(); // crate a page description PdfDocument.PageInfo pageInfo = new PdfDocument.PageInfo.Builder(612,792,1).create(); // create a new page from the PageInfo PdfDocument.Page page = document.startPage(pageInfo); TextPaint textPaint = new TextPaint(); textPaint.setColor(Color.BLACK); textPaint.setTextSize(12); textPaint.setTextAlign(Paint.Align.LEFT); Typeface textTypeface = Typeface.create(Typeface.MONOSPACE,Typeface.NORMAL); textPaint.setTypeface(textTypeface); String text = "Lorem ipsum dolor sit amet,consectetuer adipiscing elit,sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat. Ut wisi enim ad minim veniam,quis nostrud exerci tation ullamcorper suscipit lobortis nisl ut aliquip ex ea commodo consequat. Duis autem vel eum iriure dolor in hendrerit in vulputate velit esse molestie consequat,vel illum dolore eu feugiat nulla facilisis at vero eros et accumsan et iusto odio dignissim qui blandit praesent luptatum zzril delenit augue duis dolore te feugait nulla facilisi. Nam liber tempor cum soluta nobis eleifend option congue nihil imperdiet doming id quod mazim placerat facer possim assum. Typi non habent claritatem insitam; est usus legentis in iis qui facit eorum claritatem. Investigationes demonstraverunt lectores legere me lius quod ii legunt SAEpius. Claritas est etiam processus dynamicus,qui sequitur mutationem consuetudium lectorum. Mirum est notare quam littera gothica,quam nunc putamus parum claram,anteposuerit litterarum formas humanitatis per seacula quarta decima et quinta decima. Eodem modo typi,qui nunc nobis videntur parum clari,fiant sollemnes in futurum."; StaticLayout mTextLayout = new StaticLayout(text,textPaint,page.getCanvas().getWidth(),Layout.Alignment.ALIGN_NORMAL,1.0f,0.0f,false); mTextLayout.draw(page.getCanvas()); // do final processing of the page document.finishPage(page); mPDFFilePath = new File(getFilesDir(),"demo_android.pdf"); try { FileOutputStream mFileOutStream = new FileOutputStream(mPDFFilePath); // write the document content document.writeTo(mFileOutStream); mFileOutStream.flush(); mFileOutStream.close(); } catch(Exception e) { Log.v("log_tag",e.toString()); } //close the document document.close();
再次感谢!