diff --git a/djvu.c b/djvu.c index 46394debd..78d9200e3 100644 --- a/djvu.c +++ b/djvu.c @@ -490,9 +490,11 @@ static int reflowPage(lua_State *L) { int rotation = luaL_checkint(L, 16); double quality = luaL_checknumber(L, 17); double defect_size = luaL_checknumber(L, 18); + int trim_page = luaL_checkint(L, 19); k2pdfopt_set_params(width, height, font_size, page_margin, line_spacing, word_spacing, \ - text_wrap, straighten, justification, detect_indent, columns, contrast, rotation, quality, defect_size); + text_wrap, straighten, justification, detect_indent, columns, contrast, rotation, \ + quality, defect_size, trim_page); k2pdfopt_djvu_reflow(page->page_ref, page->doc->context, mode, page->doc->pixelformat); k2pdfopt_rfbmp_size(&width, &height); k2pdfopt_rfbmp_zoom(&dc->zoom); diff --git a/k2pdfopt.c b/k2pdfopt.c index 97db67cc2..01a1bcbc9 100644 --- a/k2pdfopt.c +++ b/k2pdfopt.c @@ -560,7 +560,7 @@ void k2pdfopt_set_params(int bb_width, int bb_height, \ int justification, int detect_indent,\ int columns, double contrast, \ int rotation, double quality, \ - double defect_size) { + double defect_size, int trim_page) { dst_userwidth = bb_width; // dst_width is adjusted in adjust_params_init dst_userheight = bb_height; zoom_value = font_size; @@ -575,6 +575,18 @@ void k2pdfopt_set_params(int bb_width, int bb_height, \ src_dpi = (int)300*quality; defect_size_pts = defect_size; + if (trim_page == 0) { + mar_left = 0; + mar_top = 0; + mar_right = 0; + mar_bot = 0; + } else { + mar_left = -1; + mar_top = -1; + mar_right = -1; + mar_bot = -1; + } + // margin dst_mar = page_margin; dst_martop = -1.0; diff --git a/k2pdfopt.h b/k2pdfopt.h index dafc4e6d3..b3a6d6a08 100644 --- a/k2pdfopt.h +++ b/k2pdfopt.h @@ -33,7 +33,7 @@ void k2pdfopt_set_params(int bb_width, int bb_height, \ int justification, int detect_indent, \ int columns, double contrast, \ int rotation, double quality, \ - double defect_size); + double defect_size, int trim_page); void k2pdfopt_mupdf_reflow(fz_document *doc, fz_page *page, fz_context *ctx); void k2pdfopt_djvu_reflow(ddjvu_page_t *page, ddjvu_context_t *ctx, ddjvu_render_mode_t mode, ddjvu_format_t *fmt); void k2pdfopt_rfbmp_size(int *width, int *height); diff --git a/pdf.c b/pdf.c index 7f77654d4..d51332927 100644 --- a/pdf.c +++ b/pdf.c @@ -530,9 +530,11 @@ static int reflowPage(lua_State *L) { int rotation = luaL_checkint(L, 16); double quality = luaL_checknumber(L, 17); double defect_size = luaL_checknumber(L, 18); + int trim_page = luaL_checkint(L, 19); k2pdfopt_set_params(width, height, font_size, page_margin, line_spacing, word_spacing, \ - text_wrap, straighten, justification, detect_indent, columns, contrast, rotation, quality, defect_size); + text_wrap, straighten, justification, detect_indent, columns, contrast, rotation, \ + quality, defect_size, trim_page); k2pdfopt_mupdf_reflow(page->doc->xref, page->page, page->doc->context); k2pdfopt_rfbmp_size(&width, &height); k2pdfopt_rfbmp_zoom(&dc->zoom);