Skip to content

Commit b45a5c3

Browse files
authored
Merge pull request #52 from Qatleph/add_page_direction
Implement process of adding "Direction" ViewerPreferences
2 parents 5f755a6 + af4fe05 commit b45a5c3

1 file changed

Lines changed: 23 additions & 1 deletion

File tree

Libraries/Itext/Sources/Internal/Writer.cs

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,29 @@ private void SetMetadata(Metadata src, PdfDocument dest)
179179
.SetCreator(src.Creator);
180180

181181
var pl = src.Options.ToPageLayout();
182-
if (pl != ViewerOption.None) _ = dest.GetCatalog().SetPageLayout(new(pl.ToName()));
182+
if (pl != ViewerOption.None)
183+
{
184+
PdfName pageLayout = new(pl.ToName());
185+
_ = dest.GetCatalog().SetPageLayout(pageLayout);
186+
187+
var viewerPreferences = dest.GetCatalog().GetViewerPreferences();
188+
if (viewerPreferences is null)
189+
{
190+
// Init ViewerPreferences
191+
viewerPreferences = new PdfViewerPreferences();
192+
dest.GetCatalog().SetViewerPreferences(viewerPreferences);
193+
}
194+
195+
// Add Direction to ViewerPreferences
196+
if (pl == ViewerOption.TwoColumnRight || pl == ViewerOption.TwoPageRight)
197+
{
198+
viewerPreferences.SetDirection(PdfViewerPreferences.PdfViewerPreferencesConstants.RIGHT_TO_LEFT);
199+
}
200+
else
201+
{
202+
viewerPreferences.SetDirection(PdfViewerPreferences.PdfViewerPreferencesConstants.LEFT_TO_RIGHT);
203+
}
204+
}
183205

184206
var pm = src.Options.ToPageMode();
185207
if (pm != ViewerOption.None) _ = dest.GetCatalog().SetPageMode(new(pm.ToName()));

0 commit comments

Comments
 (0)