Java Code Examples for javax.print.PrintService#getDefaultAttributeValue()

The following examples show how to use javax.print.PrintService#getDefaultAttributeValue() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Win32PrintJob.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
public void pageableJob(Pageable pageable) throws PrintException {
    try {
        synchronized(this) {
            if (job != null) { // shouldn't happen
                throw new PrintException("already printing");
            } else {
                job = new sun.awt.windows.WPrinterJob();
            }
        }
        PrintService svc = getPrintService();
        job.setPrintService(svc);
        if (copies == 0) {
            Copies c = (Copies)svc.getDefaultAttributeValue(Copies.class);
            copies = c.getValue();
        }
        job.setCopies(copies);
        job.setJobName(jobName);
        job.setPageable(pageable);
        job.print(reqAttrSet);
        notifyEvent(PrintJobEvent.DATA_TRANSFER_COMPLETE);
        return;
    } catch (PrinterException pe) {
        notifyEvent(PrintJobEvent.JOB_FAILED);
        throw new PrintException(pe);
    } finally {
        printReturned = true;
        notifyEvent(PrintJobEvent.NO_MORE_EVENTS);
    }
}
 
Example 2
Source File: PreferredDefaultsImpl.java    From swingsane with Apache License 2.0 5 votes vote down vote up
private boolean isA4PaperSize() {

    String timezone = System.getProperty("user.timezone");
    if ((timezone != null) && (timezone.length() > 0)) {
      return !System.getProperty("user.timezone").startsWith("America");
    }

    try {
      PrintService pservice = PrintServiceLookup.lookupDefaultPrintService();
      Object obj = pservice.getDefaultAttributeValue(Media.class);
      if (obj instanceof MediaSizeName) {
        MediaSizeName mediaSizeName = (MediaSizeName) obj;
        return mediaSizeName.equals(MediaSizeName.ISO_A4);
      }

    } catch (Exception ex) {
      LOG.info(ex.getLocalizedMessage());
    }

    String country = Locale.getDefault().getCountry();
    if ((country.equals("US")) || (country.equals("CA"))) {
      return false;
    }

    // default to true
    return true;
  }
 
Example 3
Source File: Win32PrintJob.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
public void pageableJob(Pageable pageable) throws PrintException {
    try {
        synchronized(this) {
            if (job != null) { // shouldn't happen
                throw new PrintException("already printing");
            } else {
                job = new sun.awt.windows.WPrinterJob();
            }
        }
        PrintService svc = getPrintService();
        job.setPrintService(svc);
        if (copies == 0) {
            Copies c = (Copies)svc.getDefaultAttributeValue(Copies.class);
            copies = c.getValue();
        }
        job.setCopies(copies);
        job.setJobName(jobName);
        job.setPageable(pageable);
        job.print(reqAttrSet);
        notifyEvent(PrintJobEvent.DATA_TRANSFER_COMPLETE);
        return;
    } catch (PrinterException pe) {
        notifyEvent(PrintJobEvent.JOB_FAILED);
        throw new PrintException(pe);
    } finally {
        printReturned = true;
        notifyEvent(PrintJobEvent.NO_MORE_EVENTS);
    }
}
 
Example 4
Source File: RasterPrinterJob.java    From jdk8u_jdk with GNU General Public License v2.0 5 votes vote down vote up
protected MediaSize getMediaSize(Media media, PrintService service,
        PageFormat page) {
    if (media == null) {
        media = (Media)service.getDefaultAttributeValue(Media.class);
    }
    if (!(media instanceof MediaSizeName)) {
        media = MediaSizeName.NA_LETTER;
    }
    MediaSize size = MediaSize.getMediaSizeForName((MediaSizeName) media);
    return size != null ? size : MediaSize.NA.LETTER;
}
 
Example 5
Source File: Win32PrintJob.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
public void pageableJob(Pageable pageable) throws PrintException {
    try {
        synchronized(this) {
            if (job != null) { // shouldn't happen
                throw new PrintException("already printing");
            } else {
                job = new sun.awt.windows.WPrinterJob();
            }
        }
        PrintService svc = getPrintService();
        job.setPrintService(svc);
        if (copies == 0) {
            Copies c = (Copies)svc.getDefaultAttributeValue(Copies.class);
            copies = c.getValue();
        }
        job.setCopies(copies);
        job.setJobName(jobName);
        job.setPageable(pageable);
        job.print(reqAttrSet);
        notifyEvent(PrintJobEvent.DATA_TRANSFER_COMPLETE);
        return;
    } catch (PrinterException pe) {
        notifyEvent(PrintJobEvent.JOB_FAILED);
        throw new PrintException(pe);
    } finally {
        printReturned = true;
        notifyEvent(PrintJobEvent.NO_MORE_EVENTS);
    }
}
 
Example 6
Source File: Win32PrintJob.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
public void pageableJob(Pageable pageable) throws PrintException {
    try {
        synchronized(this) {
            if (job != null) { // shouldn't happen
                throw new PrintException("already printing");
            } else {
                job = new sun.awt.windows.WPrinterJob();
            }
        }
        PrintService svc = getPrintService();
        job.setPrintService(svc);
        if (copies == 0) {
            Copies c = (Copies)svc.getDefaultAttributeValue(Copies.class);
            copies = c.getValue();
        }
        job.setCopies(copies);
        job.setJobName(jobName);
        job.setPageable(pageable);
        job.print(reqAttrSet);
        notifyEvent(PrintJobEvent.DATA_TRANSFER_COMPLETE);
        return;
    } catch (PrinterException pe) {
        notifyEvent(PrintJobEvent.JOB_FAILED);
        throw new PrintException(pe);
    } finally {
        printReturned = true;
        notifyEvent(PrintJobEvent.NO_MORE_EVENTS);
    }
}
 
Example 7
Source File: Win32PrintJob.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
public void pageableJob(Pageable pageable) throws PrintException {
    try {
        synchronized(this) {
            if (job != null) { // shouldn't happen
                throw new PrintException("already printing");
            } else {
                job = new sun.awt.windows.WPrinterJob();
            }
        }
        PrintService svc = getPrintService();
        job.setPrintService(svc);
        if (copies == 0) {
            Copies c = (Copies)svc.getDefaultAttributeValue(Copies.class);
            copies = c.getValue();
        }
        job.setCopies(copies);
        job.setJobName(jobName);
        job.setPageable(pageable);
        job.print(reqAttrSet);
        notifyEvent(PrintJobEvent.DATA_TRANSFER_COMPLETE);
        return;
    } catch (PrinterException pe) {
        notifyEvent(PrintJobEvent.JOB_FAILED);
        throw new PrintException(pe);
    } finally {
        printReturned = true;
        notifyEvent(PrintJobEvent.NO_MORE_EVENTS);
    }
}
 
Example 8
Source File: Win32PrintJob.java    From jdk8u-dev-jdk with GNU General Public License v2.0 5 votes vote down vote up
public void pageableJob(Pageable pageable) throws PrintException {
    try {
        synchronized(this) {
            if (job != null) { // shouldn't happen
                throw new PrintException("already printing");
            } else {
                job = new sun.awt.windows.WPrinterJob();
            }
        }
        PrintService svc = getPrintService();
        job.setPrintService(svc);
        if (copies == 0) {
            Copies c = (Copies)svc.getDefaultAttributeValue(Copies.class);
            copies = c.getValue();
        }
        job.setCopies(copies);
        job.setJobName(jobName);
        job.setPageable(pageable);
        job.print(reqAttrSet);
        notifyEvent(PrintJobEvent.DATA_TRANSFER_COMPLETE);
        return;
    } catch (PrinterException pe) {
        notifyEvent(PrintJobEvent.JOB_FAILED);
        throw new PrintException(pe);
    } finally {
        printReturned = true;
        notifyEvent(PrintJobEvent.NO_MORE_EVENTS);
    }
}
 
Example 9
Source File: RasterPrinterJob.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
protected MediaSize getMediaSize(Media media, PrintService service,
        PageFormat page) {
    if (media == null) {
        media = (Media)service.getDefaultAttributeValue(Media.class);
    }
    if (!(media instanceof MediaSizeName)) {
        media = MediaSizeName.NA_LETTER;
    }
    MediaSize size = MediaSize.getMediaSizeForName((MediaSizeName) media);
    return size != null ? size : MediaSize.NA.LETTER;
}
 
Example 10
Source File: Win32PrintJob.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
public void pageableJob(Pageable pageable) throws PrintException {
    try {
        synchronized(this) {
            if (job != null) { // shouldn't happen
                throw new PrintException("already printing");
            } else {
                job = new sun.awt.windows.WPrinterJob();
            }
        }
        PrintService svc = getPrintService();
        job.setPrintService(svc);
        if (copies == 0) {
            Copies c = (Copies)svc.getDefaultAttributeValue(Copies.class);
            copies = c.getValue();
        }
        job.setCopies(copies);
        job.setJobName(jobName);
        job.setPageable(pageable);
        job.print(reqAttrSet);
        notifyEvent(PrintJobEvent.DATA_TRANSFER_COMPLETE);
        return;
    } catch (PrinterException pe) {
        notifyEvent(PrintJobEvent.JOB_FAILED);
        throw new PrintException(pe);
    } finally {
        printReturned = true;
        notifyEvent(PrintJobEvent.NO_MORE_EVENTS);
    }
}
 
Example 11
Source File: Win32PrintJob.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
public void pageableJob(Pageable pageable) throws PrintException {
    try {
        synchronized(this) {
            if (job != null) { // shouldn't happen
                throw new PrintException("already printing");
            } else {
                job = new sun.awt.windows.WPrinterJob();
            }
        }
        PrintService svc = getPrintService();
        job.setPrintService(svc);
        if (copies == 0) {
            Copies c = (Copies)svc.getDefaultAttributeValue(Copies.class);
            copies = c.getValue();
        }
        job.setCopies(copies);
        job.setJobName(jobName);
        job.setPageable(pageable);
        job.print(reqAttrSet);
        notifyEvent(PrintJobEvent.DATA_TRANSFER_COMPLETE);
        return;
    } catch (PrinterException pe) {
        notifyEvent(PrintJobEvent.JOB_FAILED);
        throw new PrintException(pe);
    } finally {
        printReturned = true;
        notifyEvent(PrintJobEvent.NO_MORE_EVENTS);
    }
}
 
Example 12
Source File: UnixPrintJob.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
UnixPrintJob(PrintService service) {
    this.service = service;
    mDestination = service.getName();
    if (PrintServiceLookupProvider.isMac()) {
        mDestination = ((IPPPrintService)service).getDest();
    }
    mDestType = UnixPrintJob.DESTPRINTER;
    JobSheets js = (JobSheets)(service.
                                  getDefaultAttributeValue(JobSheets.class));
    if (js != null && js.equals(JobSheets.NONE)) {
        mNoJobSheet = true;
    }
}
 
Example 13
Source File: Win32PrintJob.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
public void pageableJob(Pageable pageable) throws PrintException {
    try {
        synchronized(this) {
            if (job != null) { // shouldn't happen
                throw new PrintException("already printing");
            } else {
                job = new sun.awt.windows.WPrinterJob();
            }
        }
        PrintService svc = getPrintService();
        job.setPrintService(svc);
        if (copies == 0) {
            Copies c = (Copies)svc.getDefaultAttributeValue(Copies.class);
            copies = c.getValue();
        }
        job.setCopies(copies);
        job.setJobName(jobName);
        job.setPageable(pageable);
        job.print(reqAttrSet);
        notifyEvent(PrintJobEvent.DATA_TRANSFER_COMPLETE);
        return;
    } catch (PrinterException pe) {
        notifyEvent(PrintJobEvent.JOB_FAILED);
        throw new PrintException(pe);
    } finally {
        printReturned = true;
        notifyEvent(PrintJobEvent.NO_MORE_EVENTS);
    }
}
 
Example 14
Source File: Win32PrintJob.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
public void pageableJob(Pageable pageable) throws PrintException {
    try {
        synchronized(this) {
            if (job != null) { // shouldn't happen
                throw new PrintException("already printing");
            } else {
                job = new sun.awt.windows.WPrinterJob();
            }
        }
        PrintService svc = getPrintService();
        job.setPrintService(svc);
        if (copies == 0) {
            Copies c = (Copies)svc.getDefaultAttributeValue(Copies.class);
            copies = c.getValue();
        }
        job.setCopies(copies);
        job.setJobName(jobName);
        job.setPageable(pageable);
        job.print(reqAttrSet);
        notifyEvent(PrintJobEvent.DATA_TRANSFER_COMPLETE);
        return;
    } catch (PrinterException pe) {
        notifyEvent(PrintJobEvent.JOB_FAILED);
        throw new PrintException(pe);
    } finally {
        printReturned = true;
        notifyEvent(PrintJobEvent.NO_MORE_EVENTS);
    }
}
 
Example 15
Source File: Win32PrintJob.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
public void pageableJob(Pageable pageable) throws PrintException {
    try {
        synchronized(this) {
            if (job != null) { // shouldn't happen
                throw new PrintException("already printing");
            } else {
                job = new sun.awt.windows.WPrinterJob();
            }
        }
        PrintService svc = getPrintService();
        job.setPrintService(svc);
        if (copies == 0) {
            Copies c = (Copies)svc.getDefaultAttributeValue(Copies.class);
            copies = c.getValue();
        }
        job.setCopies(copies);
        job.setJobName(jobName);
        job.setPageable(pageable);
        job.print(reqAttrSet);
        notifyEvent(PrintJobEvent.DATA_TRANSFER_COMPLETE);
        return;
    } catch (PrinterException pe) {
        notifyEvent(PrintJobEvent.JOB_FAILED);
        throw new PrintException(pe);
    } finally {
        printReturned = true;
        notifyEvent(PrintJobEvent.NO_MORE_EVENTS);
    }
}
 
Example 16
Source File: RasterPrinterJob.java    From openjdk-8-source with GNU General Public License v2.0 4 votes vote down vote up
/**
 * The passed in PageFormat will be copied and altered to describe
 * the default page size and orientation of the PrinterJob's
 * current printer.
 * Platform subclasses which can access the actual default paper size
 * for a printer may override this method.
 */
public PageFormat defaultPage(PageFormat page) {
    PageFormat newPage = (PageFormat)page.clone();
    newPage.setOrientation(PageFormat.PORTRAIT);
    Paper newPaper = new Paper();
    double ptsPerInch = 72.0;
    double w, h;
    Media media = null;

    PrintService service = getPrintService();
    if (service != null) {
        MediaSize size;
        media =
            (Media)service.getDefaultAttributeValue(Media.class);

        if (media instanceof MediaSizeName &&
           ((size = MediaSize.getMediaSizeForName((MediaSizeName)media)) !=
            null)) {
            w =  size.getX(MediaSize.INCH) * ptsPerInch;
            h =  size.getY(MediaSize.INCH) * ptsPerInch;
            newPaper.setSize(w, h);
            newPaper.setImageableArea(ptsPerInch, ptsPerInch,
                                      w - 2.0*ptsPerInch,
                                      h - 2.0*ptsPerInch);
            newPage.setPaper(newPaper);
            return newPage;

        }
    }

    /* Default to A4 paper outside North America.
     */
    String defaultCountry = Locale.getDefault().getCountry();
    if (!Locale.getDefault().equals(Locale.ENGLISH) && // ie "C"
        defaultCountry != null &&
        !defaultCountry.equals(Locale.US.getCountry()) &&
        !defaultCountry.equals(Locale.CANADA.getCountry())) {

        double mmPerInch = 25.4;
        w = Math.rint((210.0*ptsPerInch)/mmPerInch);
        h = Math.rint((297.0*ptsPerInch)/mmPerInch);
        newPaper.setSize(w, h);
        newPaper.setImageableArea(ptsPerInch, ptsPerInch,
                                  w - 2.0*ptsPerInch,
                                  h - 2.0*ptsPerInch);
    }

    newPage.setPaper(newPaper);

    return newPage;
}
 
Example 17
Source File: RasterPrinterJob.java    From openjdk-8 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * The passed in PageFormat will be copied and altered to describe
 * the default page size and orientation of the PrinterJob's
 * current printer.
 * Platform subclasses which can access the actual default paper size
 * for a printer may override this method.
 */
public PageFormat defaultPage(PageFormat page) {
    PageFormat newPage = (PageFormat)page.clone();
    newPage.setOrientation(PageFormat.PORTRAIT);
    Paper newPaper = new Paper();
    double ptsPerInch = 72.0;
    double w, h;
    Media media = null;

    PrintService service = getPrintService();
    if (service != null) {
        MediaSize size;
        media =
            (Media)service.getDefaultAttributeValue(Media.class);

        if (media instanceof MediaSizeName &&
           ((size = MediaSize.getMediaSizeForName((MediaSizeName)media)) !=
            null)) {
            w =  size.getX(MediaSize.INCH) * ptsPerInch;
            h =  size.getY(MediaSize.INCH) * ptsPerInch;
            newPaper.setSize(w, h);
            newPaper.setImageableArea(ptsPerInch, ptsPerInch,
                                      w - 2.0*ptsPerInch,
                                      h - 2.0*ptsPerInch);
            newPage.setPaper(newPaper);
            return newPage;

        }
    }

    /* Default to A4 paper outside North America.
     */
    String defaultCountry = Locale.getDefault().getCountry();
    if (!Locale.getDefault().equals(Locale.ENGLISH) && // ie "C"
        defaultCountry != null &&
        !defaultCountry.equals(Locale.US.getCountry()) &&
        !defaultCountry.equals(Locale.CANADA.getCountry())) {

        double mmPerInch = 25.4;
        w = Math.rint((210.0*ptsPerInch)/mmPerInch);
        h = Math.rint((297.0*ptsPerInch)/mmPerInch);
        newPaper.setSize(w, h);
        newPaper.setImageableArea(ptsPerInch, ptsPerInch,
                                  w - 2.0*ptsPerInch,
                                  h - 2.0*ptsPerInch);
    }

    newPage.setPaper(newPaper);

    return newPage;
}
 
Example 18
Source File: RasterPrinterJob.java    From jdk8u-dev-jdk with GNU General Public License v2.0 4 votes vote down vote up
/**
 * The passed in PageFormat will be copied and altered to describe
 * the default page size and orientation of the PrinterJob's
 * current printer.
 * Platform subclasses which can access the actual default paper size
 * for a printer may override this method.
 */
public PageFormat defaultPage(PageFormat page) {
    PageFormat newPage = (PageFormat)page.clone();
    newPage.setOrientation(PageFormat.PORTRAIT);
    Paper newPaper = new Paper();
    double ptsPerInch = 72.0;
    double w, h;
    Media media = null;

    PrintService service = getPrintService();
    if (service != null) {
        MediaSize size;
        media =
            (Media)service.getDefaultAttributeValue(Media.class);

        if (media instanceof MediaSizeName &&
           ((size = MediaSize.getMediaSizeForName((MediaSizeName)media)) !=
            null)) {
            w =  size.getX(MediaSize.INCH) * ptsPerInch;
            h =  size.getY(MediaSize.INCH) * ptsPerInch;
            newPaper.setSize(w, h);
            newPaper.setImageableArea(ptsPerInch, ptsPerInch,
                                      w - 2.0*ptsPerInch,
                                      h - 2.0*ptsPerInch);
            newPage.setPaper(newPaper);
            return newPage;

        }
    }

    /* Default to A4 paper outside North America.
     */
    String defaultCountry = Locale.getDefault().getCountry();
    if (!Locale.getDefault().equals(Locale.ENGLISH) && // ie "C"
        defaultCountry != null &&
        !defaultCountry.equals(Locale.US.getCountry()) &&
        !defaultCountry.equals(Locale.CANADA.getCountry())) {

        double mmPerInch = 25.4;
        w = Math.rint((210.0*ptsPerInch)/mmPerInch);
        h = Math.rint((297.0*ptsPerInch)/mmPerInch);
        newPaper.setSize(w, h);
        newPaper.setImageableArea(ptsPerInch, ptsPerInch,
                                  w - 2.0*ptsPerInch,
                                  h - 2.0*ptsPerInch);
    }

    newPage.setPaper(newPaper);

    return newPage;
}
 
Example 19
Source File: RasterPrinterJob.java    From jdk8u_jdk with GNU General Public License v2.0 4 votes vote down vote up
/**
 * The passed in PageFormat will be copied and altered to describe
 * the default page size and orientation of the PrinterJob's
 * current printer.
 * Platform subclasses which can access the actual default paper size
 * for a printer may override this method.
 */
public PageFormat defaultPage(PageFormat page) {
    PageFormat newPage = (PageFormat)page.clone();
    newPage.setOrientation(PageFormat.PORTRAIT);
    Paper newPaper = new Paper();
    double ptsPerInch = 72.0;
    double w, h;
    Media media = null;

    PrintService service = getPrintService();
    if (service != null) {
        MediaSize size;
        media =
            (Media)service.getDefaultAttributeValue(Media.class);

        if (media instanceof MediaSizeName &&
           ((size = MediaSize.getMediaSizeForName((MediaSizeName)media)) !=
            null)) {
            w =  size.getX(MediaSize.INCH) * ptsPerInch;
            h =  size.getY(MediaSize.INCH) * ptsPerInch;
            newPaper.setSize(w, h);
            newPaper.setImageableArea(ptsPerInch, ptsPerInch,
                                      w - 2.0*ptsPerInch,
                                      h - 2.0*ptsPerInch);
            newPage.setPaper(newPaper);
            return newPage;

        }
    }

    /* Default to A4 paper outside North America.
     */
    String defaultCountry = Locale.getDefault().getCountry();
    if (!Locale.getDefault().equals(Locale.ENGLISH) && // ie "C"
        defaultCountry != null &&
        !defaultCountry.equals(Locale.US.getCountry()) &&
        !defaultCountry.equals(Locale.CANADA.getCountry())) {

        double mmPerInch = 25.4;
        w = Math.rint((210.0*ptsPerInch)/mmPerInch);
        h = Math.rint((297.0*ptsPerInch)/mmPerInch);
        newPaper.setSize(w, h);
        newPaper.setImageableArea(ptsPerInch, ptsPerInch,
                                  w - 2.0*ptsPerInch,
                                  h - 2.0*ptsPerInch);
    }

    newPage.setPaper(newPaper);

    return newPage;
}
 
Example 20
Source File: RasterPrinterJob.java    From jdk8u-jdk with GNU General Public License v2.0 4 votes vote down vote up
/**
 * The passed in PageFormat will be copied and altered to describe
 * the default page size and orientation of the PrinterJob's
 * current printer.
 * Platform subclasses which can access the actual default paper size
 * for a printer may override this method.
 */
public PageFormat defaultPage(PageFormat page) {
    PageFormat newPage = (PageFormat)page.clone();
    newPage.setOrientation(PageFormat.PORTRAIT);
    Paper newPaper = new Paper();
    double ptsPerInch = 72.0;
    double w, h;
    Media media = null;

    PrintService service = getPrintService();
    if (service != null) {
        MediaSize size;
        media =
            (Media)service.getDefaultAttributeValue(Media.class);

        if (media instanceof MediaSizeName &&
           ((size = MediaSize.getMediaSizeForName((MediaSizeName)media)) !=
            null)) {
            w =  size.getX(MediaSize.INCH) * ptsPerInch;
            h =  size.getY(MediaSize.INCH) * ptsPerInch;
            newPaper.setSize(w, h);
            newPaper.setImageableArea(ptsPerInch, ptsPerInch,
                                      w - 2.0*ptsPerInch,
                                      h - 2.0*ptsPerInch);
            newPage.setPaper(newPaper);
            return newPage;

        }
    }

    /* Default to A4 paper outside North America.
     */
    String defaultCountry = Locale.getDefault().getCountry();
    if (!Locale.getDefault().equals(Locale.ENGLISH) && // ie "C"
        defaultCountry != null &&
        !defaultCountry.equals(Locale.US.getCountry()) &&
        !defaultCountry.equals(Locale.CANADA.getCountry())) {

        double mmPerInch = 25.4;
        w = Math.rint((210.0*ptsPerInch)/mmPerInch);
        h = Math.rint((297.0*ptsPerInch)/mmPerInch);
        newPaper.setSize(w, h);
        newPaper.setImageableArea(ptsPerInch, ptsPerInch,
                                  w - 2.0*ptsPerInch,
                                  h - 2.0*ptsPerInch);
    }

    newPage.setPaper(newPaper);

    return newPage;
}