Setting auto-height/width for converted Jpeg from PDF using GhostScript

后端 未结 2 1896
一生所求
一生所求 2021-01-05 06:17

I am using GS to do conversion from PDF to JPEG and following is the command that I use:

gs -sDEVICE=jpeg -dNOPAUSE -dBATCH -g500x300 -dPDFFitPage -sOutputFi         


        
2条回答
  •  礼貌的吻别
    2021-01-05 06:25

    You could write a PostScript program to do this readily enough. Here is a start:

    %!
    % usage: gs -sFile=____.pdf  scale.ps
    
    /File where not {
      (\n   *** Missing source file. \(use -sFile=____.pdf\)\n) =
      Usage
    } {
      pop
    }ifelse
    
    % Get the width and height of a PDF page
    %
    /GetSize {
      pdfgetpage currentpagedevice
      1 index get_any_box 
      exch pop dup 2 get exch 3 get
      /PDFHeight exch def
      /PDFWidth exch def
    } def
    
    
    %
    % The main loop
    % For every page in the original PDF file
    %
    1 1 PDFPageCount 
    {
      /PDFPage exch def
      PDFPage GetSize
    
    % In here, knowing the desired destination size
    % calculate a scale factor for the PDF to fit
    % either the width or height, or whatever
    % The width and height are stored in PDFWidht and PDFHeight
      PDFPage pdfgetpage
      pdfshowpage
    } for
    

    pdfgetpage and pdfshowpage are internal Ghostscript extensions to the PostScript language for handling PDF files.

提交回复
热议问题