LEADTOOLS PDF (Leadtools.Pdf assembly)
LEAD Technologies, Inc

Resolution Property

Example 





Gets or sets the resolution in dots per inch of this PDF document.
Syntax
public int Resolution {get; set;}
'Declaration
 
Public Property Resolution As Integer
'Usage
 
Dim instance As PDFDocument
Dim value As Integer
 
instance.Resolution = value
 
value = instance.Resolution
public int Resolution {get; set;}
 get_Resolution();
set_Resolution(value);
public:
property int Resolution {
   int get();
   void set (    int value);
}

Property Value

A System.Int32 that specifies the resolution in dots per inch of this PDF document. The default value is the value of the static (Shared in Visual Basic) PDFDocument.DefaultResolution property.
Remarks

A value of 0 means "Use current screen resolution", usually, 96. High resolution values will render the document with greater details at the expense of using more system resources. Typical resolution values are 72, 96, 150, 200, 300 and 600.

PDF documents do not have a resolution. Instead, all locations and sizes are stored in PDF units which equivalant to 1/72 of an inch. To convert a PDF unit to a physical value such as pixels, you must provide an external value for the resolution.

Physical values such as pixels are typically needed when a PDF document is rendered to the screen. To convert from logical to physical units, a resolution must be provided. Resolution is the value of dots (pixels) per inch to use when converting logical to physical values. For a example, if a PDF document has a page width and height of 612 by 792 units and the resolution value set in Resolution is 150, then:

The PDFDocumentPage.ConvertPoint and PDFDocumentPage.ConvertRect uses the value of Resolution when converting to and from pixels. Also, the GetPageImage method will also use this resolution when calculating the page size in pixels.

You can change the Resolution value at any time based on your need. For example, a PDF viewer may set Resolution to a low value, for example, 96, and calls GetPageImage to render the PDF page on the screen when the image is zoomed out and not alot of details will be viewed. When the user zooms in into the page, a higher quality with finer details is required, the viewer then can obtain a new version of the image with a higher resolution by setting a new value into Resolution, such as 200, and calling GetPageImage again.

Example
 
Public Sub PDFDocumentResolutionExample()
      Dim pdfFileName As String = Path.Combine(LEAD_VARS.ImagesDir, "LEAD.pdf")
      Dim outFileName1 As String = Path.Combine(LEAD_VARS.ImagesDir, "PageAt150.png")
      Dim outFileName2 As String = Path.Combine(LEAD_VARS.ImagesDir, "PageAt300.png")

      ' Create a PDF document for file
      Using document As New PDFDocument(pdfFileName)

         ' Get the first page in the document
         Dim page As PDFDocumentPage = document.Pages(0)

         Using codecs As New RasterCodecs()
            ' Use a resolution of 150
            document.Resolution = 150
            Console.WriteLine("Page size in pixels at {0} is {1} by {2}", document.Resolution, page.WidthPixels, page.HeightPixels)

            ' Save this page at this resolution
            Using image As RasterImage = document.GetPageImage(codecs, 1)
               codecs.Save(image, outFileName1, RasterImageFormat.Png, 32)
            End Using

            ' Use a resolution of 300, the new size should be twice as much as the previous one
            document.Resolution = 300
            Console.WriteLine("Page size in pixels at {0} is {1} by {2}", document.Resolution, page.WidthPixels, page.HeightPixels)

            ' Save this page at this resolution
            Using image As RasterImage = document.GetPageImage(codecs, 1)
               codecs.Save(image, outFileName2, RasterImageFormat.Png, 32)
            End Using
         End Using

         ' Open both PNG files and notice that PageAt300.png has more details that PageAt150.png
      End Using
   End Sub

Public NotInheritable Class LEAD_VARS
   Public Const ImagesDir As String = "C:\Users\Public\Documents\LEADTOOLS Images"
End Class
public void PDFDocumentResolutionExample()
   {
      string pdfFileName = Path.Combine(LEAD_VARS.ImagesDir, @"LEAD.pdf");
      string outFileName1 = Path.Combine(LEAD_VARS.ImagesDir, @"PageAt150.png");
      string outFileName2 = Path.Combine(LEAD_VARS.ImagesDir, @"PageAt300.png");

      // Create a PDF document for file
      using(PDFDocument document = new PDFDocument(pdfFileName))
      {
         // Get the first page in the document
         PDFDocumentPage page = document.Pages[0];

         using(RasterCodecs codecs = new RasterCodecs())
         {
            // Use a resolution of 150
            document.Resolution = 150;
            Console.WriteLine("Page size in pixels at {0} is {1} by {2}", document.Resolution, page.WidthPixels, page.HeightPixels);

            // Save this page at this resolution
            using(RasterImage image = document.GetPageImage(codecs, 1))
            {
               codecs.Save(image, outFileName1, RasterImageFormat.Png, 32);
            }

            // Use a resolution of 300, the new size should be twice as much as the previous one
            document.Resolution = 300;
            Console.WriteLine("Page size in pixels at {0} is {1} by {2}", document.Resolution, page.WidthPixels, page.HeightPixels);

            // Save this page at this resolution
            using(RasterImage image = document.GetPageImage(codecs, 1))
            {
               codecs.Save(image, outFileName2, RasterImageFormat.Png, 32);
            }
         }

         // Open both PNG files and notice that PageAt300.png has more details that PageAt150.png
      }
   }

static class LEAD_VARS
{
   public const string ImagesDir = @"C:\Users\Public\Documents\LEADTOOLS Images";
}
Requirements

Target Platforms: Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

See Also

Reference

PDFDocument Class
PDFDocument Members

 

 


Products | Support | Contact Us | Copyright Notices

© 2006-2012 All Rights Reserved. LEAD Technologies, Inc.