When the input format is other than pdf(like ps), pdftopdf is unable to set orientation
for crop-to-fit and fill. New function is_landsape is added to get orientation
of input file and orientation is set accordingly.
static const Rotation ipp2rot[4]={ROT_0, ROT_90, ROT_270, ROT_180};
param.orientation=ipp2rot[ipprot-3];
}
+ } else {
+ param.noOrientation = true;
}
ppd_size_t *pagesize;
if(param.fillprint||param.cropfit){
fprintf(stderr,"[DEBUG]: Cropping input pdf and Enabling fitplot.\n");
+ if(param.noOrientation&&pages.size())
+ {
+ bool land = pages[0]->is_landscape(param.orientation);
+ if(land)
+ param.orientation = param.normal_landscape;
+ }
for(int i=0;i<(int)pages.size();i++)
{
std::shared_ptr<PDFTOPDF_PageHandle> page = pages[i];
fitplot(false),
fillprint(false), //print-scaling = fill
cropfit(false),
+ noOrientation(false),
orientation(ROT_0),normal_landscape(ROT_270),
paper_is_landscape(false),
duplex(false),
bool fitplot;
bool fillprint; //print-scaling = fill
bool cropfit; // -o crop-to-fit
+ bool noOrientation;
PageRect page;
Rotation orientation,normal_landscape; // normal_landscape (i.e. default direction) is e.g. needed for number-up=2
bool paper_is_landscape;
virtual void add_border_rect(const PageRect &rect,BorderType border,float fscale) =0;
// TODO?! add standalone crop(...) method (not only for subpages)
virtual Rotation crop(const PageRect &cropRect,Rotation orientation,Position xpos,Position ypos,bool scale) =0;
+ virtual bool is_landscape(Rotation orientation) =0 ;
virtual void add_subpage(const std::shared_ptr<PDFTOPDF_PageHandle> &sub,float xpos,float ypos,float scale,const PageRect *crop=NULL) =0;
virtual void mirror() =0;
virtual void rotate(Rotation rot) =0;
return getRotate(page);
}
+bool QPDF_PDFTOPDF_PageHandle::is_landscape(Rotation orientation)
+{
+ page.assertInitialized();
+ if(orientation==ROT_0||orientation==ROT_180)
+ page.replaceOrRemoveKey("/Rotate",makeRotate(ROT_90));
+ else
+ page.replaceOrRemoveKey("/Rotate",makeRotate(ROT_0));
+
+ PageRect currpage= getBoxAsRect(getTrimBox(page));
+ double width = currpage.right-currpage.left;
+ double height = currpage.top-currpage.bottom;
+ if(width>height)
+ return true;
+ return false;
+}
+
// TODO: better cropping
// TODO: test/fix with qsub rotation
void QPDF_PDFTOPDF_PageHandle::add_subpage(const std::shared_ptr<PDFTOPDF_PageHandle> &sub,float xpos,float ypos,float scale,const PageRect *crop) // {{{
virtual void rotate(Rotation rot);
virtual void add_label(const PageRect &rect, const std::string label);
virtual Rotation crop(const PageRect &cropRect,Rotation orientation,Position xpos,Position ypos,bool scale);
+ virtual bool is_landscape(Rotation orientation);
void debug(const PageRect &rect,float xpos,float ypos);
private:
bool isExisting() const;