Hi,
Im looking for a libary that can inspect PDF’s for a number of things. Aspose looks promising, but im getting wierd results when testing some of the provided examples.
Determine page color for example:
I created a word doc with 2 pages, with just a little text and printed it to PDF.
Made a test program with the examples provided here:
The code works, however it sees all pages as RGB, while BlackAndWhite was expected. Whats going on here?
Second, what values do page height/width represent. My test pdf is 210mm297mm, but the pageinfo gives me the values 595842 , how do i get these values in milimeters?
@bob.krusemeijer
It seems you’re encountering unexpected results when trying to determine the page color of your PDF using Aspose. Here are some insights that might help you understand the situation better:
-
Page Color Detection: The code you referenced is designed to check the color type of each page in a PDF document. If your PDF is being recognized as RGB instead of Black and White, it could be due to the way the PDF was generated. Even if the content appears to be black and white, the underlying color model might still be RGB. This can happen if the PDF contains any color information or if the text is rendered in a way that is interpreted as RGB by the library.
Here’s a snippet of the code that checks the color type:
Aspose.Pdf.ColorType pageColorType = pdfDocument.Pages[pageCount].ColorType;
switch (pageColorType)
{
case ColorType.BlackAndWhite:
Console.WriteLine("Page # -" + pageCount + " is Black and white..");
break;
case ColorType.Grayscale:
Console.WriteLine("Page # -" + pageCount + " is Gray Scale...");
break;
case ColorType.Rgb:
Console.WriteLine("Page # -" + pageCount + " is RGB..");
break;
case ColorType.Undefined:
Console.WriteLine("Page # -" + pageCount + " Color is undefined..");
break;
}
-
Page Dimensions: Regarding the page dimensions, the values you are seeing (595 x 842) are in points, which is a common unit in PDF documents. To convert these dimensions to millimeters, you can use the conversion factor where 1 point is equal to 0.352778 mm. Therefore, to convert the width and height from points to millimeters, you can use the following formula:
double widthInMm = page.GetPageRect(true).Width * 0.352778;
double heightInMm = page.GetPageRect(true).Height * 0.352778;
Console.WriteLine($"Width: {widthInMm} mm, Height: {heightInMm} mm");
By using this approach, you should be able to get the correct dimensions in millimeters.
If you continue to experience issues, consider checking the properties of the original document or the way it was exported to PDF, as this can affect how Aspose interprets the color and dimensions.
Feel free to reach out if you have more questions or need further assistance!
Sources:
[1]: Determine Page Color Example
[2]: Get Dimensions Example