C1PDF How to convert pixels to the DPI

Posted by: inexcon on 7 August 2017, 7:59 am EST

  • Posted 7 August 2017, 7:59 am EST

    Hi C1!

    I try to draw an image of the current canvas. I set the Width and Height of the canvas to fit the C1PDF.PageSize (currently it gives me 612 x 792). Then I make a WriteableBitmap and write it into the C1PDF (For testing purpose I do not count margin). I finally call DrawImage function to write the image. I do not want to stretch because the layout is ugly, so I set Stretch = None. However, the PaperSize does not seems to be in pixel, so the final PDF have a smaller image inside. Is there a way to convert the PaperSize in Pixel?

    What I want to do is draw in the PDF the image of the canvas but keep the original size, with no stretching.

    PDF.DrawImage(MyImage, PDF.PageRectangle, C1.Silverlight.Pdf.ContentAlignment.MiddleCenter, Stretch.None)

    The size of MyImage is 612x792 in Pixel, but in the PDF document 612x792 are not pixels, so the image is smaller.

    I attached the PDF file I have generated. You will see that 612x792 pixels for the image makes the image smaller than the page.

    2011/07/Test.pdf

  • Posted 7 August 2017, 7:59 am EST

    Hi,

    PageSize is in points, but PDF and Silverlight disagree on what a point is. For PDF, there are 72 points per inch, for Silverlight, 96. Use C1PdfDocument.ToPixels() and ToPoints() to convert. For example, To Pixels is defined as

        public static double ToPixels(double points)
        {
            return points / 72.0 * 96.0;
        }
    

    Hope this helps,

    Bruno

  • Posted 7 August 2017, 7:59 am EST

    OK, thank you Bruno, it works for me!

  • Posted 27 February 2022, 12:47 pm EST

    Pixelart123 is a website where you can find hundreds of pixel art templates that you can easily create and print, copy or create from scratch. There are templates for drawing - from rainbow unicorns to planets in the solar system. Pixel art has never been so easy! Visit Pixelart123 now: https://pixelart123.de/

Need extra support?

Upgrade your support plan and get personal unlimited phone support with our customer engagement team

Learn More

Forum Channels