我试图使用gem combine_pdf
来合并我的应用中的大量PDF。它们位于assets/forms/packages/1.pdf 2.pdf 3.pdf
。
我试图关注gem的指南,但代码会产生错误:
@pdfForms = CombinePDF.new
@pdfForms << CombinePDF.new('assets/forms/packages/1.pdf')
我收到运行时错误:
root is unknown - cannot determine if file is Encrypted
非常感谢任何帮助,或者合并pdf的其他方式。由于宝石pdf-merge
依赖于rjb
,因此我的应用程序失败了state.info <- data.frame(name = state.name, long = state.center$x, lat = state.center$y,
area = state.x77[, "Area"],
population = 1000 * state.x77[, "Population"])
state.info$density <- with(state.info, population / area)
library("maps")
state.map <- map("state", plot=FALSE, fill = FALSE)
panel.3dmap <- function(..., rot.mat, distance, xlim, ylim, zlim, xlim.scaled,
ylim.scaled, zlim.scaled) { scaled.val <- function(x, original, scaled) {
scaled[1] + (x - original[1]) * diff(scaled) / diff(original) }
m <- ltransform3dto3d(rbind(scaled.val(state.map$x, xlim, xlim.scaled),
scaled.val(state.map$y, ylim, ylim.scaled), zlim.scaled[1]), rot.mat, distance)
panel.lines(m[1,], m[2,], col = "grey76") }
cloud(density ~ long + lat, state.info, subset = !(name %in% c("Alaska", "Hawaii")),
panel.3d.cloud = function(...) { panel.3dmap(...)
panel.3dscatter(...) },
type = "h", scales = list(draw = FALSE), zoom = 1.1, xlim = state.map$range[1:2],
ylim = state.map$range[3:4], xlab = NULL, ylab = NULL, zlab = NULL,
aspect = c(diff(state.map$range[3:4]) / diff(state.map$range[1:2]), 0.3),
panel.aspect = 0.75, lwd = 2, screen = list(z = 30, x = -60),
par.settings = list(axis.line = list(col = "transparent"),
box.3d = list(col = "transparent", alpha = 0)))
。
谢谢!
答案 0 :(得分:2)
尝试使用
打开文件File.open(&#34;资产/形式/包/次数1.pdf&#34)
如果这不起作用,那么您的文件路径是错误的。 如果此pdf文件位于应用程序的app / assets文件夹中,则可以使用以下命令访问它:
file_path = Rails.root.join("app", "assets", "forms", "packages","1.pdf")
File.open(file_path)
答案 1 :(得分:0)
尝试使用CombinePDF.load
代替CombinePDF.new
。
new
将尝试加载文件并解析字符串 - 因此您不会看到文件加载异常。
可能是文件路径错误而且CombinePDF正在尝试解析资产/表单/包/ 1.pdf&#39;好像它是PDF文件的内容。
您的代码应如下所示:
@pdfForms = CombinePDF.new
@pdfForms << CombinePDF.load('assets/forms/packages/1.pdf')