+#include <stdio.h>
+#include <string.h>
#include "../gfxdevice.h"
#include "../gfxsource.h"
#include "../devices/rescale.h"
#include "../args.h"
static double zoom = 72; /* xpdf: 86 */
-static int jpeg_dpi = 0;
-static int ppm_dpi = 0;
+static int zoomtowidth = 0;
static int multiply = 1;
static char* global_page_range = 0;
typedef struct _pdf_doc_internal
{
- int config_bitmap_optimizing;
- int config_full_bitmap_optimizing;
+ char config_bitmap_optimizing;
+ char config_full_bitmap_optimizing;
+ char config_print;
parameterlist_t parameters;
int protect;
int nocopy;
+ int noprint;
PDFDoc*doc;
Object docinfo;
pdf_doc_internal_t*pi = (pdf_doc_internal_t*)page->parent->internal;
gfxsource_internal_t*i = (gfxsource_internal_t*)pi->parent->internal;
- if(pi->nocopy) {
- msg("<fatal> PDF disallows copying");
- exit(0);
- }
+ if(!pi->config_print && pi->nocopy) {msg("<fatal> PDF disallows copying");exit(0);}
+ if(pi->config_print && pi->noprint) {msg("<fatal> PDF disallows printing");exit(0);}
CommonOutputDev*outputDev = 0;
if(pi->config_full_bitmap_optimizing) {
}
outputDev->setDevice(dev);
- pi->doc->displayPage((OutputDev*)outputDev, page->nr, zoom*multiply, zoom*multiply, /*rotate*/0, true, true, /*doLinks*/(int)1);
+ pi->doc->displayPage((OutputDev*)outputDev, page->nr, zoom*multiply, zoom*multiply, /*rotate*/0, true, true, pi->config_print);
pi->doc->processLinks((OutputDev*)outputDev, page->nr);
outputDev->finishPage();
outputDev->setDevice(0);
i->config_bitmap_optimizing = atoi(value);
} else if(!strcmp(name, "bitmapfonts") || !strcmp(name, "bitmap")) {
i->config_full_bitmap_optimizing = atoi(value);
+ } else if(!strcmp(name, "asprint")) {
+ i->config_print = 1;
} else {
storeDeviceParameter(&i->parameters, name, value);
}
sprintf(buf, "%.1f", i->doc->getPDFVersion());
return strdup(buf);
}
- return 0;
+ return strdup("");
}
+/* shortcut to InfoOutputDev.cc */
+extern int config_addspace;
+extern int config_fontquality;
+extern int config_bigchar;
+
static void pdf_set_parameter(gfxsource_t*src, const char*name, const char*value)
{
gfxsource_internal_t*i = (gfxsource_internal_t*)src->internal;
- parameterlist_t*p = &i->parameters;
+
msg("<verbose> setting parameter %s to \"%s\"", name, value);
if(!strncmp(name, "fontdir", strlen("fontdir"))) {
addGlobalFontDir(value);
+ } else if(!strcmp(name, "detectspaces")) {
+ config_addspace = atoi(value);
+ } else if(!strcmp(name, "fontquality")) {
+ config_fontquality = atoi(value);
+ } else if(!strcmp(name, "bigchar")) {
+ config_bigchar = atoi(value);
} else if(!strcmp(name, "pages")) {
global_page_range = strdup(value);
} else if(!strncmp(name, "font", strlen("font")) && name[4]!='q') {
addGlobalFont(value);
} else if(!strncmp(name, "languagedir", strlen("languagedir"))) {
addGlobalLanguageDir(value);
+ } else if(!strcmp(name, "zoomtowidth")) {
+ zoomtowidth = atoi(value);
} else if(!strcmp(name, "zoom")) {
char buf[80];
zoom = atof(value);
- sprintf(buf, "%f", (double)jpeg_dpi/(double)zoom);
- storeDeviceParameter(p, "jpegsubpixels", buf);
- sprintf(buf, "%f", (double)ppm_dpi/(double)zoom);
- storeDeviceParameter(p, "ppmsubpixels", buf);
- } else if(!strcmp(name, "jpegdpi")) {
- char buf[80];
- jpeg_dpi = atoi(value);
- sprintf(buf, "%f", (double)jpeg_dpi/(double)zoom);
- storeDeviceParameter(p, "jpegsubpixels", buf);
- } else if(!strcmp(name, "ppmdpi")) {
- char buf[80];
- ppm_dpi = atoi(value);
- sprintf(buf, "%f", (double)ppm_dpi/(double)zoom);
- storeDeviceParameter(p, "ppmsubpixels", buf);
+ } else if(!strcmp(name, "jpegdpi") || !strcmp(name, "ppmdpi")) {
+ msg("<error> %s not supported anymore. Please use jpegsubpixels/ppmsubpixels");
} else if(!strcmp(name, "multiply")) {
multiply = atoi(value);
} else if(!strcmp(name, "help")) {
i->filename = strdup(filename);
char*x = 0;
- if((x = strchr(filename, '|'))) {
+ if((x = strchr((char*)filename, '|'))) {
*x = 0;
userPassword = x+1;
}
if(!i->doc->okToCopy()) {
i->nocopy = 1;
}
+ if(!i->doc->okToPrint()) {
+ i->noprint = 1;
+ }
if(!i->doc->okToChange() || !i->doc->okToAddNotes())
i->protect = 1;
}
+
+ if(zoomtowidth && i->doc->getNumPages()) {
+ Page*page = i->doc->getCatalog()->getPage(1);
+ PDFRectangle *r = page->getCropBox();
+ double width_before = r->x2 - r->x1;
+ zoom = 72.0 * zoomtowidth / width_before;
+ msg("<notice> Rendering at %f DPI. (Page width at 72 DPI: %f, target width: %d)", zoom, width_before, zoomtowidth);
+ }
i->info = new InfoOutputDev(i->doc->getXRef());
int t;
memset(i->pages,0,sizeof(pdf_page_info_t)*pdf_doc->num_pages);
for(t=1;t<=pdf_doc->num_pages;t++) {
if(!global_page_range || is_in_range(t, global_page_range)) {
- i->doc->displayPage((OutputDev*)i->info, t, zoom, zoom, /*rotate*/0, /*usemediabox*/true, /*crop*/true, /*doLinks*/(int)1);
+ i->doc->displayPage((OutputDev*)i->info, t, zoom, zoom, /*rotate*/0, /*usemediabox*/true, /*crop*/true, i->config_print);
i->doc->processLinks((OutputDev*)i->info, t);
i->pages[t-1].xMin = i->info->x1;
i->pages[t-1].yMin = i->info->y1;