com.lowagie.text.Image.getScaledWidth()方法的使用及代码示例

x33g5p2x  于2022-01-21 转载在 其他  
字(7.5k)|赞(0)|评价(0)|浏览(135)

本文整理了Java中com.lowagie.text.Image.getScaledWidth()方法的一些代码示例,展示了Image.getScaledWidth()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Image.getScaledWidth()方法的具体详情如下:
包路径:com.lowagie.text.Image
类名称:Image
方法名:getScaledWidth

Image.getScaledWidth介绍

[英]Gets the scaled width of the image.
[中]获取图像的缩放宽度。

代码示例

代码示例来源:origin: com.github.librepdf/openpdf

/**
 * Returns the width of a certain character of this font.
 *
 * @param        character    a certain character
 * @return        a width in Text Space
 */

float width(int character) {
  if (image == null)
    return font.getWidthPoint(character, size) * hScale;
  else
    return image.getScaledWidth();
}

代码示例来源:origin: fr.opensagres.xdocreport.itext-gae/itext-gae

float width(String s) {
  if (image == null)
    return font.getWidthPoint(s, size) * hScale;
  else
    return image.getScaledWidth();
}

代码示例来源:origin: fr.opensagres.xdocreport.itext-gae/itext-gae

/**
 * Returns the width of a certain character of this font.
 *
 * @param        character    a certain character
 * @return        a width in Text Space
 */

float width(int character) {
  if (image == null)
    return font.getWidthPoint(character, size) * hScale;
  else
    return image.getScaledWidth();
}

代码示例来源:origin: es.gob.afirma/afirma-crypto-pdf-itext

float width(String s) {
  if (image == null)
    return font.getWidthPoint(s, size) * hScale;
  else
    return image.getScaledWidth();
}

代码示例来源:origin: com.github.librepdf/openpdf

float width(String s) {
  if (image == null)
    return font.getWidthPoint(s, size) * hScale;
  else
    return image.getScaledWidth();
}

代码示例来源:origin: es.gob.afirma/afirma-crypto-pdf-itext

/**
 * Returns the width of a certain character of this font.
 *
 * @param        character    a certain character
 * @return        a width in Text Space
 */

float width(int character) {
  if (image == null)
    return font.getWidthPoint(character, size) * hScale;
  else
    return image.getScaledWidth();
}

代码示例来源:origin: stackoverflow.com

Image image = Image.getInstance(IMAGE);
float width = image.getScaledWidth();
float height = image.getScaledHeight();

代码示例来源:origin: stackoverflow.com

PdfContentByte cb = writer.getDirectContent();
Image img = createBarcode(cb, "This is a 2D barcode", 1, 1);
document.add(new Paragraph(
  String.format("This barcode measures %s by %s user units",
    img.getScaledWidth(), img.getScaledHeight())));
document.add(img);
img = createBarcode(cb, "This is NOT a raster image", 3, 3);
document.add(new Paragraph(
  String.format("This barcode measures %s by %s user units",
    img.getScaledWidth(), img.getScaledHeight())));
document.add(img);
img = createBarcode(cb, "This is vector data drawn on a PDF page", 1, 3);
document.add(new Paragraph(
  String.format("This barcode measures %s by %s user units",
    img.getScaledWidth(), img.getScaledHeight())));

代码示例来源:origin: fr.opensagres.xdocreport.itext-gae/itext-gae

/**
 * Gets the width of the <CODE>PdfChunk</CODE> taking into account the
 * extra character and word spacing.
 * @param charSpacing the extra character spacing
 * @param wordSpacing the extra word spacing
 * @return the calculated width
 */
  
  public float getWidthCorrected(float charSpacing, float wordSpacing)
  {
    if (image != null) {
      return image.getScaledWidth() + charSpacing;
    }
    int numberOfSpaces = 0;
    int idx = -1;
    while ((idx = value.indexOf(' ', idx + 1)) >= 0)
      ++numberOfSpaces;
    return width() + (value.length() * charSpacing + numberOfSpaces * wordSpacing);
  }

代码示例来源:origin: stackoverflow.com

public Image getWatermarkedImage(PdfContentByte cb, Image img, String watermark) throws DocumentException {
  float width = img.getScaledWidth();
  float height = img.getScaledHeight();
  PdfTemplate template = cb.createTemplate(width, height);
  template.addImage(img, width, 0, 0, height, 0, 0);
  ColumnText.showTextAligned(template, Element.ALIGN_CENTER,
      new Phrase(watermark, FONT), width / 2, height / 2, 30);
  return Image.getInstance(template);
}

代码示例来源:origin: stackoverflow.com

public Image cropImage(PdfWriter writer, Image image, float leftReduction, float rightReduction, float topReduction, float bottomReduction) throws DocumentException {
  float width = image.getScaledWidth();
  float height = image.getScaledHeight();
  PdfTemplate template = writer.getDirectContent().createTemplate(
      width - leftReduction - rightReduction,
      height - topReduction - bottomReduction);
  template.addImage(image,
      width, 0, 0,
      height, -leftReduction, -bottomReduction);
  return Image.getInstance(template);
}

代码示例来源:origin: stackoverflow.com

public void createPdf(String dest) throws IOException, DocumentException {
  Document document = new Document(PageSize.A4.rotate());
  PdfWriter.getInstance(document, new FileOutputStream(dest));
  document.open();
  Image img = Image.getInstance(IMAGE);
  img.scaleToFit(770, 523);
  float offsetX = (770 - img.getScaledWidth()) / 2;
  float offsetY = (523 - img.getScaledHeight()) / 2;
  img.setAbsolutePosition(36 + offsetX, 36 + offsetY);
  document.add(img);
  document.close();
}

代码示例来源:origin: stackoverflow.com

Document document = new Document();
 // step 2
 PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(filename));
 // step 3
 document.open();
 // step 4
 // Adding a series of images
 Image img;
 for (int i = 0; i < RESOURCES.length; i++) {
   img = Image.getInstance(String.format("resources/img/%s", RESOURCES[i]));
   if (img.getScaledWidth() > 300 || img.getScaledHeight() > 300) {
     img.scaleToFit(300, 300);
   }
   document.add(new Paragraph(
       String.format("%s is an image of type %s", RESOURCES[i], img.getClass().getName())));
   document.add(img);
 }

代码示例来源:origin: stackoverflow.com

public static Image cropImage(Image image, PdfWriter writer, float x, float y, float width, float height) throws DocumentException {
  PdfContentByte cb = writer.getDirectContent();
  PdfTemplate t = cb.createTemplate(width, height);
  float origWidth = image.getScaledWidth();
  float origHeight = image.getScaledHeight();
  t.addImage(image, origWidth, 0, 0, origHeight, -x, -y);
  return Image.getInstance(t);
}

代码示例来源:origin: com.github.librepdf/openpdf

/**
 * Scales the image so that it fits a certain width and height.
 *
 * @param fitWidth
 *            the width to fit
 * @param fitHeight
 *            the height to fit
 */
public void scaleToFit(float fitWidth, float fitHeight) {
  scalePercent(100);
  float percentX = (fitWidth * 100) / getScaledWidth();
  float percentY = (fitHeight * 100) / getScaledHeight();
  scalePercent(percentX < percentY ? percentX : percentY);
  setWidthPercentage(0);
}

代码示例来源:origin: es.gob.afirma/afirma-crypto-pdf-itext

/**
 * Scales the image so that it fits a certain width and height.
 * 
 * @param fitWidth
 *            the width to fit
 * @param fitHeight
 *            the height to fit
 */
public void scaleToFit(float fitWidth, float fitHeight) {
  scalePercent(100);
  float percentX = (fitWidth * 100) / getScaledWidth();
  float percentY = (fitHeight * 100) / getScaledHeight();
  scalePercent(percentX < percentY ? percentX : percentY);
  setWidthPercentage(0);
}

代码示例来源:origin: fr.opensagres.xdocreport.itext-gae/itext-gae

/**
 * Scales the image so that it fits a certain width and height.
 * 
 * @param fitWidth
 *            the width to fit
 * @param fitHeight
 *            the height to fit
 */
public void scaleToFit(float fitWidth, float fitHeight) {
  scalePercent(100);
  float percentX = (fitWidth * 100) / getScaledWidth();
  float percentY = (fitHeight * 100) / getScaledHeight();
  scalePercent(percentX < percentY ? percentX : percentY);
  setWidthPercentage(0);
}

代码示例来源:origin: com.github.librepdf/openpdf

/**
 * Gets the width of the Chunk in points.
 * 
 * @return a width in points
 */
public float getWidthPoint() {
  if (getImage() != null) {
    return getImage().getScaledWidth();
  }
  return font.getCalculatedBaseFont(true).getWidthPoint(getContent(),
      font.getCalculatedSize())
      * getHorizontalScaling();
}

代码示例来源:origin: es.gob.afirma/afirma-crypto-pdf-itext

/**
 * Gets the width of the Chunk in points.
 * 
 * @return a width in points
 */
public float getWidthPoint() {
  if (getImage() != null) {
    return getImage().getScaledWidth();
  }
  return font.getCalculatedBaseFont(true).getWidthPoint(getContent(),
      font.getCalculatedSize())
      * getHorizontalScaling();
}

代码示例来源:origin: fr.opensagres.xdocreport.itext-gae/itext-gae

/**
 * Gets the width of the Chunk in points.
 * 
 * @return a width in points
 */
public float getWidthPoint() {
  if (getImage() != null) {
    return getImage().getScaledWidth();
  }
  return font.getCalculatedBaseFont(true).getWidthPoint(getContent(),
      font.getCalculatedSize())
      * getHorizontalScaling();
}

相关文章

微信公众号

最新文章

更多

Image类方法