如何合并两个pdf,一个用wicked_pdf创建,另一个用paperclip上传

时间:2017-11-03 05:38:11

标签: ruby-on-rails paperclip wicked-pdf

我通过wicked_pdf gem创建了一个pdf,现在我想将两个pdf合并为一个,一个用wicked_pdf创建,另一个用paperclip在数据库中上传。

2 个答案:

答案 0 :(得分:2)

您需要使用 combined_pdf gem

gem install combine_pdf

pdf = CombinePDF.new
pdf << CombinePDF.load("file1.pdf") # one way to combine, very fast.
pdf << CombinePDF.load("file2.pdf")
pdf.save "combined.pdf"

否则,如果您想在一行中执行上述代码

(CombinePDF.load("file1.pdf") << CombinePDF.load("file2.pdf") << CombinePDF.load("file3.pdf")).save("combined.pdf")

答案 1 :(得分:0)

您可以使用pdf merge gem。

public static Bitmap getRoundedCornerImage(Bitmap bitmap, int radius) {
    int w = bitmap.getWidth();
    int h = bitmap.getHeight();
    Bitmap output = Bitmap.createBitmap(w, h, Bitmap.Config.ARGB_8888);
    Canvas canvas = new Canvas(output);

    final Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG);
    final RectF rectF = new RectF(0, 0, w, h);

    canvas.drawRoundRect(rectF, radius, radius, paint);

    paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_IN));
    canvas.drawBitmap(bitmap, null, rectF, paint);

    /**
     * here to define your corners, this is for left bottom and right bottom corners
     */
    final Rect clipRect = new Rect(0, radius, w + radius, h + radius);
    paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC));
    canvas.drawRect(clipRect, paint);

    paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_IN));
    canvas.drawBitmap(bitmap, null, rectF, paint);

    bitmap.recycle();
    return output;
}

然后:

# Gemfile.rb
gem 'rjb'
gem 'pdf-merger'

您可以阅读有关此here的更多信息。