←Select platform

Resolution Property

Summary
Resolution, in dots per inch, of this PDF document.
Syntax
C#
C++/CLI
Java
Python
public int Resolution { get; set; } 
public int getResolution(); 
public void setResolution( 
   int intValue 
); 
public: 
property int Resolution { 
   int get(); 
   void set (    int ); 
} 
Resolution # get and set (PDFDocument) 

Property Value

An System.Int32 that specifies the resolution in dots per inch of this PDF document. The default value is the value of the static PDFDocument.DefaultResolution property.

Remarks

A value of 0 means, "Use the current screen resolution" (usually, 96 DPI). High resolution values will render the document with greater detail 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 are equivalent 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 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 size of the page in inches is 8.5" by 11" - Obtained by dividing 612 and 792 by 72

  • The size of the page in pixels is 1275 by 1650 - Obtained by multiplying 8.5" and 11" by 150, the current resolution

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 what is needed. For example, a PDF viewer may set Resolution to a low value, (for example, 96) and call GetPageImage to render the PDF page on the screen when the image is zoomed out and not a lot of details will be viewed. When the user zooms in onto the page, a higher quality with finer details is required. The viewer can then 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

This example will show how changing the resolution affecta PDFDocumentPage.WidthPixels, PDFDocumentPage.HeightPixels and GetPageImage.

C#
Java
using Leadtools; 
using Leadtools.Codecs; 
using Leadtools.Controls; 
using Leadtools.Pdf; 
using Leadtools.Svg; 
using Leadtools.WinForms; 
 
 
public void PDFDocumentResolutionExample() 
{ 
   string pdfFileName = Path.Combine(LEAD_VARS.ImagesDir, @"Leadtools.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:\LEADTOOLS23\Resources\Images"; 
} 
 
import java.io.BufferedWriter; 
import java.io.Console; 
import java.io.File; 
import java.io.FileWriter; 
import java.io.IOException; 
import java.io.OutputStream; 
import java.io.OutputStreamWriter; 
import java.nio.Buffer; 
import java.nio.file.Files; 
import java.nio.file.Path; 
import java.nio.file.Paths; 
import java.nio.file.StandardOpenOption; 
import java.sql.Date; 
import java.text.SimpleDateFormat; 
import java.time.LocalDateTime; 
import java.util.ArrayList; 
import java.util.List; 
 
import javax.xml.validation.Schema; 
 
import org.apache.lucene.store.Directory; 
import org.junit.*; 
import org.junit.runner.JUnitCore; 
import org.junit.runner.Result; 
import org.junit.runner.notification.Failure; 
import static org.junit.Assert.*; 
 
import leadtools.*; 
import leadtools.barcode.*; 
import leadtools.codecs.*; 
import leadtools.pdf.*; 
import leadtools.svg.*; 
 
 
public void pdfDocumentResolutionExample() { 
   String LEAD_VARS_ImagesDir = "C:\\LEADTOOLS23\\Resources\\Images"; 
   String pdfFileName = combine(LEAD_VARS_ImagesDir, "Leadtools.pdf"); 
   String outFileName1 = combine(LEAD_VARS_ImagesDir, "PageAt150.png"); 
   String outFileName2 = combine(LEAD_VARS_ImagesDir, "PageAt300.png"); 
 
   // Create a PDF document for file 
   PDFDocument document = new PDFDocument(pdfFileName); 
   // Get the first page in the document 
   List<PDFDocumentPage> pages = document.getPages(); 
   PDFDocumentPage page = pages.get(0); 
 
   RasterCodecs codecs = new RasterCodecs(); 
   // Use a resolution of 150 
   document.setResolution(150); 
   System.out.println("Page size in pixels at " + document.getResolution() + " is " + page.getWidthPixels() + " by " 
         + page.getHeightPixels()); 
 
   // Save this page at this resolution 
   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.setResolution(300); 
   System.out.printf("Page size in pixels at %1s is %2s by %3s%n", document.getResolution(), page.getWidthPixels(), 
         page.getHeightPixels()); 
 
   // Save this page at this resolution 
   RasterImage image2 = document.getPageImage(codecs, 1); 
   codecs.save(image2, outFileName2, RasterImageFormat.PNG, 32); 
 
   // Open both PNG files and notice that PageAt300.png has more details that 
   // PageAt150.png 
 
} 
Requirements

Target Platforms

Help Version 23.0.2024.2.29
Products | Support | Contact Us | Intellectual Property Notices
© 1991-2024 LEAD Technologies, Inc. All Rights Reserved.

Leadtools.Pdf Assembly
Products | Support | Contact Us | Intellectual Property Notices
© 1991-2023 LEAD Technologies, Inc. All Rights Reserved.