Welcome Guest Search | Active Topics | Sign In | Register

Manually scaling image Options
cdonlan
Posted: Wednesday, July 15, 2015 7:44:23 PM
Rank: Newbie
Groups: Member

Joined: 7/15/2015
Posts: 1
Hi, I need to make sure that all images are scaled to the size of a letter--8.5/11 inches--and, while auto-scaling works for some images, it does not work for all images. One set of images is too detailed, and is appearing zoomed in on the page.

The instructions say that to optionally scale the image, you must use the "Pdfmatrix"...but I cannot expose the pdfmatrix from pdfImageContent. How does one limit or force the image to fill an 8.5 by 11 inch page, in the format of the example code for image manipulation in the documentation?

The current code is:

PdfPage page = pdfDocument.Pages.Add();
System.Drawing.Image image;
EO.Pdf.Drawing.PdfImage pdfImage;
EO.Pdf.Contents.PdfImageContent content;
using (MemoryStream ms = new MemoryStream(buffer))
{
image = System.Drawing.Image.FromStream(ms);
pdfImage = new EO.Pdf.Drawing.PdfImage(image);
content = new EO.Pdf.Contents.PdfImageContent(pdfImage);
}
content.AutoScale();
eo_support
Posted: Wednesday, July 15, 2015 8:06:29 PM
Rank: Administration
Groups: Administration

Joined: 5/27/2007
Posts: 24,229
Hi,

Below is the source code of AutoScale:

Code: C#
public void AutoScale()
{
    PdfMatrix matrix = PdfMatrix.NewIdentity();

    if (m_Image != null)
    {
        System.Drawing.Image image = m_Image.Image;
        float dpiX = image.HorizontalResolution;
        float dpiY = image.VerticalResolution;

        //Here we assume user space is 1/72 inch.
        //This can change if user has set the
        //transform matrix, in that case user will
        //have to manually adjust this content's
        //matrix accordingly
        float scaleX = image.Width / dpiX * 72;
        float scaleY = image.Height / dpiX * 72;

        matrix.Scale(scaleX, scaleY);
    }

    this.GfxMatrix.Multiply(matrix);
}



Here m_Image is the PdfImage object. Hope this helps you understand how to scale the image.

Thanks


You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.