iTextSharp.text.Image.ScaleToFit C# (CSharp) Метод

ScaleToFit() публичный Метод

Scales the image so that it fits a certain width and height.
public ScaleToFit ( float fitWidth, float fitHeight ) : void
fitWidth float the width to fit
fitHeight float the height to fit
Результат void
        public void ScaleToFit(float fitWidth, float fitHeight)
        {
            ScalePercent(100);
            float percentX = (fitWidth * 100) / this.ScaledWidth;
            float percentY = (fitHeight * 100) / this.ScaledHeight;
            ScalePercent(percentX < percentY ? percentX : percentY);
            WidthPercentage = 0;
        }

Usage Example

Пример #1
0
        // output the PDF file
        public void print()
        {
            string tempDir   = "";
            int    fileCount = 0;

            // save the image file, get the directory
            tempDir = temporaryImageOutput(filePath, ref fileCount);
            // link the file to PDF
            if (tempDir == "Error")
            {
                MessageBox.Show("Duplicated file name");
                return;
            }
            Document _pdfDocument = new Document(PageSize.A4, 10, 10, 25, 25);

            PdfWriter.GetInstance(_pdfDocument, new FileStream(filePath, FileMode.Create));
            _pdfDocument.Open();

            // output the PDF

            _pdfDocument.Add(new Paragraph(description[0]));
            iTextSharp.text.Image imm = iTextSharp.text.Image.GetInstance(tempDir + "\\" + 1 + ".png");
            imm.ScaleToFit(PageSize.A5);
            _pdfDocument.Add(imm);
            for (int i = 2; i <= fileCount; i++)
            {
                _pdfDocument.NewPage();
                _pdfDocument.Add(new Paragraph(description[i - 1]));
                iTextSharp.text.Image ima = iTextSharp.text.Image.GetInstance(tempDir + "\\" + i + ".png");
                ima.ScaleToFit(PageSize.A5);
                _pdfDocument.Add(ima);
            }
            _pdfDocument.Close();
        }
All Usage Examples Of iTextSharp.text.Image::ScaleToFit