本文整理汇总了Java中javax.print.attribute.standard.MediaSize.findMedia方法的典型用法代码示例。如果您正苦于以下问题:Java MediaSize.findMedia方法的具体用法?Java MediaSize.findMedia怎么用?Java MediaSize.findMedia使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.print.attribute.standard.MediaSize
的用法示例。
在下文中一共展示了MediaSize.findMedia方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: CPaper
import javax.print.attribute.standard.MediaSize; //导入方法依赖的package包/类
/**
* Constructor.
* Derive Paper from PageForamt
* @param pf PageFormat
*/
public CPaper (PageFormat pf)
{
super();
m_landscape = pf.getOrientation() != PageFormat.PORTRAIT;
// try to find MediaSize
float x = (float)pf.getWidth();
float y = (float)pf.getHeight();
MediaSizeName msn = MediaSize.findMedia (x/72, y/72, MediaSize.INCH);
MediaSize ms = null;
if (msn == null)
msn = MediaSize.findMedia (y/72, x/72, MediaSize.INCH); // flip it
if (msn != null)
ms = MediaSize.getMediaSizeForName(msn);
setMediaSize(ms, m_landscape);
// set size directly
setSize(pf.getWidth(), pf.getHeight());
setImageableArea(pf.getImageableX(), pf.getImageableY(),
pf.getImageableWidth(), pf.getImageableHeight());
}
示例2: getSupportedMediaSizeNames
import javax.print.attribute.standard.MediaSize; //导入方法依赖的package包/类
public static MediaSizeName[] getSupportedMediaSizeNames(final long handle)
throws PrintException {
final MediaSizeName[] names;
final int[] sizes = getSupportedPaperSizes(handle);
final Vector<MediaSizeName> v = new Vector<MediaSizeName>(
sizes.length / 2);
for (int i = 0; i < sizes.length; i += 2) {
if ((sizes[i] > 0) && (sizes[i + 1] > 0)) {
final MediaSizeName name = MediaSize.findMedia(sizes[i] / 10,
sizes[i + 1] / 10, Size2DSyntax.MM);
if ((name != null) && !v.contains(name)) {
v.add(name);
}
}
}
names = new MediaSizeName[v.size()];
return v.toArray(names);
}
示例3: loadDefaultPrinterProperties
import javax.print.attribute.standard.MediaSize; //导入方法依赖的package包/类
/**
* Loads/set the media size name derived from the properties manager.
* Otherwise a default paper size of NA Letter is returned
*
* @return a MediaSizeName given the conditions above.
*/
private MediaSizeName loadDefaultPrinterProperties() {
int printMediaUnit =
PropertiesManager.checkAndStoreIntegerProperty(
propertiesManager,
PropertiesManager.PROPERTY_PRINT_MEDIA_SIZE_UNIT,
1000);
double printMediaWidth =
PropertiesManager.checkAndStoreDoubleProperty(
propertiesManager,
PropertiesManager.PROPERTY_PRINT_MEDIA_SIZE_WIDTH,
215.9);
double printMediaHeight =
PropertiesManager.checkAndStoreDoubleProperty(
propertiesManager,
PropertiesManager.PROPERTY_PRINT_MEDIA_SIZE_HEIGHT,
279.4);
// get the closed matching media name.
return MediaSize.findMedia((float) printMediaWidth,
(float) printMediaHeight,
printMediaUnit);
}
示例4: CustomMediaSizeName
import javax.print.attribute.standard.MediaSize; //导入方法依赖的package包/类
public CustomMediaSizeName(String name, String choice,
float width, float length) {
super(nextValue(name));
choiceName = choice;
customEnumTable.add(this);
mediaName = null;
try {
mediaName = MediaSize.findMedia(width, length,
MediaSize.INCH);
} catch (IllegalArgumentException iae) {
}
// The public API method finds a closest match even if it not
// all that close. Here we want to be sure its *really* close.
if (mediaName != null) {
MediaSize sz = MediaSize.getMediaSizeForName(mediaName);
if (sz == null) {
mediaName = null;
} else {
float w = sz.getX(MediaSize.INCH);
float h = sz.getY(MediaSize.INCH);
float dw = Math.abs(w - width);
float dh = Math.abs(h - length);
if (dw > 0.1 || dh > 0.1) {
mediaName = null;
}
}
}
}
示例5: CustomMediaSizeName
import javax.print.attribute.standard.MediaSize; //导入方法依赖的package包/类
public CustomMediaSizeName(String name, String choice,
float width, float length) {
super(nextValue(name));
choiceName = choice;
customEnumTable.add(this);
mediaName = null;
try {
mediaName = MediaSize.findMedia(width, length,
MediaSize.INCH);
} catch (IllegalArgumentException iae) {
}
}
示例6: getAttrsForPageFormat
import javax.print.attribute.standard.MediaSize; //导入方法依赖的package包/类
protected HashPrintRequestAttributeSet
getAttrsForPageFormat(PageFormat page) {
HashPrintRequestAttributeSet lattrs=new HashPrintRequestAttributeSet();
/* Add Orientation attribute */
switch (page.getOrientation()) {
case PageFormat.LANDSCAPE:
lattrs.add(OrientationRequested.LANDSCAPE);
break;
case PageFormat.PORTRAIT:
lattrs.add(OrientationRequested.PORTRAIT);
break;
case PageFormat.REVERSE_LANDSCAPE:
lattrs.add(OrientationRequested.REVERSE_LANDSCAPE);
break;
}
/* Add Media attribute */
MediaSizeName media = MediaSize.findMedia(
(float) (page.getWidth() / 72.0),
(float) (page.getHeight() / 72.0),
Size2DSyntax.INCH);
if (media != null) {
lattrs.add(media);
}
/* Add MediaMargins attribute */
lattrs.add(new MediaMargins((float) (page.getImageableX() / 72.0),
(float) (page.getImageableY() / 72.0),
(float) ((page.getWidth() - page.getImageableX() -
page.getImageableWidth()) / 72.0),
(float) ((page.getHeight() - page.getImageableHeight() -
page.getImageableY()) / 72.0),
MediaMargins.INCH));
return lattrs;
}
示例7: setPaperSize
import javax.print.attribute.standard.MediaSize; //导入方法依赖的package包/类
/**
* Sets the paper size.
*
* @param service The {@link PrintService} to use.
* @param set The {@link PrintRequestAttributeSet} to use.
* @param size The size of the paper.
* @param units The type of units being used.
*/
public static void setPaperSize(PrintService service, PrintRequestAttributeSet set, double[] size, LengthUnits units) {
double[] margins = getPaperMargins(service, set, units);
MediaSizeName mediaSizeName = MediaSize.findMedia((float) LengthUnits.IN.convert(units, size[0]), (float) LengthUnits.IN.convert(units, size[1]), Size2DSyntax.INCH);
if (mediaSizeName == null) {
mediaSizeName = MediaSizeName.NA_LETTER;
}
set.add(mediaSizeName);
setPaperMargins(service, set, margins, units);
}
示例8: getMediaSizeName
import javax.print.attribute.standard.MediaSize; //导入方法依赖的package包/类
public static MediaSizeName getMediaSizeName(PDDocument document) throws IOException {
PDFRenderer renderer = new PDFRenderer(document);
BufferedImage image = renderer.renderImageWithDPI(0, 72f);
float w, h, swp;
w = image.getWidth() / 72f;
h = image.getHeight() / 72f;
if (w > h) {
swp = w;
w = h;
h = swp;
}
return MediaSize.findMedia(w, h, Size2DSyntax.INCH);
}