mirror of
https://github.com/UglyToad/PdfPig.git
synced 2025-10-15 19:54:52 +08:00
include rotation in page object #42
we need to apply rotation to the crop and media box and therefore find the correct width and height. but for now correctly deriving the rotation from the page tree should help consumers.
This commit is contained in:
@@ -29,6 +29,11 @@
|
||||
|
||||
internal CropBox CropBox { get; }
|
||||
|
||||
/// <summary>
|
||||
/// The rotation of the page in degrees (clockwise). Valid values are 0, 90, 180 and 270.
|
||||
/// </summary>
|
||||
public int Rotation { get; }
|
||||
|
||||
internal PageContent Content { get; }
|
||||
|
||||
/// <summary>
|
||||
@@ -67,7 +72,7 @@
|
||||
[NotNull]
|
||||
public Experimental ExperimentalAccess { get; }
|
||||
|
||||
internal Page(int number, DictionaryToken dictionary, MediaBox mediaBox, CropBox cropBox, PageContent content,
|
||||
internal Page(int number, DictionaryToken dictionary, MediaBox mediaBox, CropBox cropBox, int rotation, PageContent content,
|
||||
AnnotationProvider annotationProvider)
|
||||
{
|
||||
if (number <= 0)
|
||||
@@ -75,11 +80,17 @@
|
||||
throw new ArgumentOutOfRangeException(nameof(number), "Page number cannot be 0 or negative.");
|
||||
}
|
||||
|
||||
if (rotation != 0 && rotation != 90 && rotation != 180 && rotation != 270)
|
||||
{
|
||||
throw new ArgumentOutOfRangeException(nameof(rotation), $"Rotation must be 0, 90, 180 or 270. Got: {rotation}.");
|
||||
}
|
||||
|
||||
Dictionary = dictionary ?? throw new ArgumentNullException(nameof(dictionary));
|
||||
|
||||
Number = number;
|
||||
MediaBox = mediaBox;
|
||||
CropBox = cropBox;
|
||||
Rotation = rotation;
|
||||
Content = content;
|
||||
Text = GetText(content);
|
||||
|
||||
|
@@ -11,5 +11,7 @@
|
||||
}
|
||||
|
||||
public MediaBox MediaBox { get; set; }
|
||||
|
||||
public int Rotation { get; set; }
|
||||
}
|
||||
}
|
@@ -106,6 +106,11 @@
|
||||
pageTreeMembers.MediaBox = new MediaBox(mediaBox.ToRectangle());
|
||||
}
|
||||
|
||||
if (currentPageDictionary.TryGet(NameToken.Rotate, pdfScanner, out NumericToken rotateToken))
|
||||
{
|
||||
pageTreeMembers.Rotation = rotateToken.Int;
|
||||
}
|
||||
|
||||
if (!currentPageDictionary.TryGet(NameToken.Kids, out var kids)
|
||||
|| !(kids is ArrayToken kidsArray))
|
||||
{
|
||||
|
@@ -53,6 +53,12 @@
|
||||
throw new InvalidOperationException($"Page {number} had its type specified as {type} rather than 'Page'.");
|
||||
}
|
||||
|
||||
var rotation = pageTreeMembers.Rotation;
|
||||
if (dictionary.TryGet(NameToken.Rotate, pdfScanner, out NumericToken rotateToken))
|
||||
{
|
||||
rotation = rotateToken.Int;
|
||||
}
|
||||
|
||||
MediaBox mediaBox = GetMediaBox(number, dictionary, pageTreeMembers, isLenientParsing);
|
||||
CropBox cropBox = GetCropBox(dictionary, pageTreeMembers, mediaBox, isLenientParsing);
|
||||
|
||||
@@ -110,7 +116,7 @@
|
||||
content = GetContent(bytes, cropBox, userSpaceUnit, isLenientParsing);
|
||||
}
|
||||
|
||||
var page = new Page(number, dictionary, mediaBox, cropBox, content, new AnnotationProvider(pdfScanner, dictionary, isLenientParsing));
|
||||
var page = new Page(number, dictionary, mediaBox, cropBox, rotation, content, new AnnotationProvider(pdfScanner, dictionary, isLenientParsing));
|
||||
|
||||
return page;
|
||||
}
|
||||
|
Reference in New Issue
Block a user