PDFTOPDF

1. INTRODUCTION

There are two executable programs, "pdftopdf" and "pdf2pdf", in this package.
"pdftopdf" is a filter for CUPS. It reads PDF files, changes page layout
and output a new PDF file. "pdf2pdf" is a user command version of "pdftopdf".
This document describes about only "pdftopdf". See man/pdf2pdf.1 for "pdf2pdf".

When a input PDF file which is given to "pdftopdf" does not include some
required fonts, and if you set the font embedding option, "pdftopdf" embed
fonts in the new PDF file 

"pdftopdf" finds fonts to embed by fontconfig library.
"pdftopdf" now embed only TrueType format fonts.
PDF Standard fonts are not embedded .

Note: Do not embed fonts that the font licenses inhibit embedding.

"pdftopdf" does not support functions that are not related to printing
features, including interactive features and document interchange features.
Many of these operators and sections are just ignored.
Some of these may be output, but those functions are not assured.
Encryption feature is not supported.

2. LICENSE

Almost source files are under MIT like license. However, "pdftopdf" links
some "poppler" libraries, and these files are under GNU public license.
See copyright notice of each file for details.

3. COMMAND LINE

"pdftopdf" is a CUPS filter, and the command line arguments, environment
variables and configuration files are in accordance with the CUPS filter
interface.

pdftopdf <job> <user> <title> <num-copies> <options> [<filename>]

"pdftopdf" ignores <job> and <user>.
<title> is appended into the PDF dictionary as /Title.
<num-copies> specifies the number of document copies.
<options> is a CUPS option list.
<filename> is an input PDF file name.

When omit the <filename>, "pdftopdf" reads a PDF file from stdin,
and save it as a temporary file.


CUPS options defined in <options> are delimited by space. Boolean
type CUPS option is defined only by the option key, and other type
CUPS option are defined by pairs of key and value, <key>=<value>.

4. COMMAND OPTIONS

"pdftopdf" accepts the following CUPS standard options;

fiplot
mirror
PageSize
page-left, page-right, page-bottom, page-top
number-up
number-up-layout
page-border
OutputOrder
page-set
page-ranges
Collate
sides
cupsEvenDuplex

See the CUPS documents for details of these options.

Margin given by the page-left, page-right, page-bottom and page-top is
valid when fiplot or number-up option is set.

"pdftopdf" accepts the following original options;

pdftopdfFontEmbedding
  Boolean option.
  Force "pdftopdf" to embed fonts. "pdftopdf" does not embed fonts by default.

pdftopdfFontEmbeddingWhole
  Boolean option.
  Force "pdftopdf" to embed whole fonts.
  "pdftopdf" does not embed whole fonts by default.
  If this option is false, "pdftopdf" embed subset of the fonts.
  This option is valid only when the pdftopdfFontEmbedding option is true.

pdftopdfFontEmbeddingPreLoad
  Boolean option.
  Force "pdftopdf" to embed fonts specified as pre-loaded fonts in a PPD file.
  "pdftopdf" does not embed pre-loaded fonts by default.
  If this option is false, pdftopdf does not embed pre-loaded fonts.
  This option is valid only when the pdftopdfFontEmbedding option is true.

pdftopdfFontCompress
  Boolean option.
  Force "pdftopdf" to compress embed fonts.
  "pdftopdf" does not compress embed fonts by default.
  This option is valid only when the pdftopdfFontEmbedding option is true.

pdftopdfContentsCompress
  Boolean option.
  Force "pdftopdf" to compress page contents.
  "pdftopdf" does not compress page contents by default.

pdftopdfJCLBegin
  Boolean option.
  Force "pdftopdf" to create JCL info for the following PDF filter
  "pdftoopvp".

5. INFORMATION FOR DEVELOPERS

Following information is for developers, not for driver users.

5.1 Options handled by a printer or "pdftopdf"

Following options are handled by a printer or "pdftopdf".
  Collate, Copies, Duplex, OutputOrder

Which handles these options depends on following options and attributes.
  Collate, Copies, Duplex, OutputOrder, cupsEvenDuplex, cupsManualCopies

"pdftopdf" judges whether a printer can handle these options according to
the followings option settings in a PPD file.

Collate:
  If Collate is defined, "pdftopdf" judges the printer supports Collate.
Copies:
  If cupsManualCopies is defined as False, "pdftopdf" judges the printer
  does not support Copies feature.
Duplex:
  If Duplex is defined, "pdftopdf" judges the printer supports Duplex.
  If cupsEvenDuplex is True, Number of pages must be even.
OutputOrder:
  If OutputOrder is defined, "pdftopdf" judges the printer supports
  OutputOrder.

If the printer cannot handle these options, "pdftopdf" handles it.

Following pseudo program describes how "pdftopdf" judges to handle
these options.

Variables

Copies : specified Copies
Duplex : specified Duplex 
Collate : specified Collate
OutputOrder : specified OutputOrder
EvenDuplex : specified cupsEvenDuplex
pages : number of pages
number_up : specified number-up

device_copies : Copies passed to the printer
device_duplex : Duplex passed to the printer
device_collate : Collate passed to the printer
device_outputorder : OutputOrder passed to the printer

soft_copies : copies by pdftopdf


device_copies = 1;
device_duplex = False;
device_collate = False;
device_outputorder = False;

if (Copies == 1) {
  /* Collate is not needed. */
  Collate = False;
}

if (!Duplex) {
  /* EvenDuplex is not needed */
  EvenDuplex = False;
}


if (Copies > 1 && the printer can handle Copies) device_copies = Copies;
if (Duplex && the printer can handle Duplex) {
       device_duplex = True;
} else {
   /* pdftopdf cannot handle Duplex */
}
if (Collate && the printer can handle Collate) device_collate = True;
if (OutputOrder == Reverse && the printer can handle OutputOrder)
             device_outputorder = True;

if (Collate && !device_collate) {
   /* The printer cannot handle Collate.
      So pdftopdf handle Copies */
              device_copies = 1;
}

if (device_copies != Copies /* pdftopdf handle Copies */ && Duplex)
    /* Make pdftopdf handle Collate, otherwise both paper side may have
       same page */
              Collate = True;
              device_collate = False;
}

if (Duplex && Collate && !device_collate) {
   /* Handle EvenDuplex, otherwise the last page has
      the next copy's first page in the other side of the paper. */
   EvenDuplex = True;
}

if (Duplex && OutputOrder == Reverse && !device_outputorder) {
   /* Handle EvenDuplex, otherwise the first page's other side of paper
      is empty. */
   EvenDuplex = True;
}

soft_copies = device_copies > 1 ? 1 : Copies;

5.2 JCL

When you print PDF files to a PostScript(PS) printer, you can specify
device options in PS. In this case, you can write PS commands in a PPD file
like as follows.

*OpenUI *Resolution/Resolution : PickOne
*DefaultResolution: 600
*Resolution 300/300 dpi: "<</HWResolution[300 300]>>setpagedevice"
*Resolution 600/600 dpi: "<</HWResolution[600 600]>>setpagedevice"
*CloseUI: *Resolution

However, if options cannot be described in PS file, you can write JCLs
as follows;

*JCLOpenUI *JCLFrameBufferSize/Frame Buffer Size: PickOne
*DefaultJCLFrameBufferSize: Letter
*OrderDependency: 20 JCLSetup *JCLFrameBufferSize
*JCLFrameBufferSize Off: '@PJL SET PAGEPROTECT = OFF<0A>'
*JCLFrameBufferSize Letter: '@PJL SET PAGEPROTECT = LTR<0A>'
*JCLFrameBufferSize Legal: '@PJL SET PAGEPROTECT = LGL<0A>'
*JCLCloseUI: *JCLFrameBufferSize

Because PDF cannot specify device options in a PDF file, you have to define
all the device options as JCLs.

When a printer does not support PS nor PDF, you can use Ghostscript (GS).
In this case, you can specify device options like a PS printer.
If you want to use the same printer and same PPD file for both PDF and PS
printing, when you print a PS file, you can specify that GS handles it,
and when you print a PDF file, you can also specify that PDF filters handle
it in the same PPD file. However in this case, previous methods is not
appropriate to specify device options.

So, "pdftopdf" handles this case as follows;
(In following pseudo program, JCL option is a option specified with JCLOpenUI)

if (Both JCLBegin and JCLToPSInterpreter are specified in the PPD file) {
    output JCLs that marked JCL options.
}

if (pdftopdfJCLBegin attribute is specified in the PPD file) {
    output it's value
}

if (Copies option is specified in the PPD file) {
    mark Number of copies specified
} else if (pdftopdfJCLCopies is specified in the PPD file) {
    output JCL specified with JCLCopies
}

for (each marked options) {
    if (pdftopdfJCL<marked option's name> is specified in the PPD file) {
	output it's value as a JCL
    } else if (pdftopdfJCLBegin attributes is specified in the PPD file) {
	output "<option's name>=<marked choice>;" as a JCL
    }
}
output NEWLINE

Thus, if you want to use both PDF filters and GS by single PPD file,
what you should do is to add the following line in the PPD file;

*pdftopdfJCLBegin: "pdftoopvp jobInfo:"

Note:
  If you specify JCLBegin, you have to specify JCLToPSInterpreter as well.

Note:
  When you need to specify the value which is different from the choosen
  value based on the PPD into the jobInfo, you have to specify the values
  with the key started by "pdftopdfJCL" string.

  For example, if the page size is defined in a PPD file as following;

  *OpenUI *PageSize/Page Size: PickOne
  *DefaultPageSize: A4
  *PageSize A4/A4:
  *PageSize Letter/US Letter:
  *CloseUI: *PageSize

  if you choose the page size "Letter", the string "PageSize=Letter;" is
  added to jobInfo. On the other hand, if the driver requires the different
  value for the "Letter" size, for instance driver requires "PS=LT;"
  instead of "PageSize=Letter;" as the jobInfo value, the PPD file has to
  be defined as following;

  *OpenUI *PageSize/Page Size: PickOne
  *DefaultPageSize: A4
  *PageSize A4/A4:
  *pdftopdfJCLPageSize A4/A4: "PS=A4;"
  *PageSize Letter/US Letter:
  *pdftopdfJCLPageSize Letter/US Letter: "PS=LT;"
  *CloseUI: *PageSize

5.3 Special PDF comment

"pdftopdf" outputs the following special comments from the 4th line in the
created PDF data.

%%PDFTOPDFNumCopies : <copies> --- <copies> specified Number of Copies
%%PDFTOPDFCollate : <collate> --- <collate> is true or false

5.4 Temporally files location

"pdftopdf" creates temporally files if needed.　Temporary files are created
in the location specified by TMPDIR environment　variable. Default location
is "/tmp".

