.NETでPDFのテキストとページを回転
PDFのテキストやページの回転とは、PDFドキュメント内の全ページまたは特定のテキスト要素の向きを変更することを指します。 この回転は度単位で行うことができます(通常は 90度、180度、または 270度)内容を時計回りまたは反時計回りに再配置します。
IronPDFを始めましょう
今日から無料トライアルでIronPDFをあなたのプロジェクトで使い始めましょう。
C#でPDFファイルを回転する方法
- IronPDF C# PDFライブラリをダウンロードする PDFを回転する
- 指定されたメソッドを使用してページの回転を設定します。
- プログラムによるPDFページの回転
- CSS3を使用してPDFテキストを回転
- PDFドキュメントを表示
PDFページを回転する
SetPageRotation
、SetPageRotations
、SetAllPageRotations
メソッドを使用して、それぞれ単一ページ、複数ページ、およびすべてのページの回転を設定します。 これらのメソッドは、指定された度数に従って、現在のページ回転を完全に上書きします。度数は時計回りに測定されます。元のページ回転が希望の度数に設定されている場合、これらのメソッドは出力ファイルに影響を与えません。
:path=/static-assets/pdf/content-code-examples/how-to/rotating-text-set-page-rotation.cs
using IronPdf;
using IronPdf.Rendering;
using System.Linq;
// Import PDF
PdfDocument pdf = PdfDocument.FromFile("multi-page.pdf");
// Set rotation for a single page
pdf.SetPageRotation(0, PdfPageRotation.Clockwise90);
// Set rotation for multiple pages
pdf.SetPageRotations(Enumerable.Range(1,3), PdfPageRotation.Clockwise270);
// Set rotation for the entire document
pdf.SetAllPageRotations(PdfPageRotation.Clockwise180);
pdf.SaveAs("rotated.pdf");
Imports IronPdf
Imports IronPdf.Rendering
Imports System.Linq
' Import PDF
Private pdf As PdfDocument = PdfDocument.FromFile("multi-page.pdf")
' Set rotation for a single page
pdf.SetPageRotation(0, PdfPageRotation.Clockwise90)
' Set rotation for multiple pages
pdf.SetPageRotations(Enumerable.Range(1,3), PdfPageRotation.Clockwise270)
' Set rotation for the entire document
pdf.SetAllPageRotations(PdfPageRotation.Clockwise180)
pdf.SaveAs("rotated.pdf")
CSS3を使用してテキストを回転させる
.NETでHTMLをPDFに変換した後、プログラムを使ってテキストやページ全体を回転させる必要があるかもしれません。 よくある要求として、HTML5およびCSS3を使用してPDFに縦方向に配置されたテキストをレンダリングすることがあります。これを実現する方法は次の通りです。
CSS3 は、PDF を HTML に変換した後、テキストを任意の角度に回転させることができます。IronPDF .NET ライブラリ以前にインストールしました。 これは、任意のHTML要素を任意の角度に回転させることができるCSS3スタイルの -webkit-transform: rotate
を使用して実現されます。
-webkit-transformHTML要素に多くのタイプの3Dおよび3D回転変換とエフェクトを許可します。 C# HTMLをPDFに変換し、テキストを180度回転させた簡単な例は次の通りです:
:path=/static-assets/pdf/content-code-examples/how-to/rotating-text-css.cs
using IronPdf;
var renderer = new IronPdf.ChromePdfRenderer();
var pdf = renderer.RenderHtmlAsPdf(@"
<html>
<head>
<style>
.rotated{
-webkit-transform: rotate(-180deg);
width:400;
height:400;
}
</style>
</head>
<body>
<p class='rotated'>Rotated Text</p>
</body>
</html>
");
pdf.SaveAs("rotated.pdf");
Imports IronPdf
Private renderer = New IronPdf.ChromePdfRenderer()
Private pdf = renderer.RenderHtmlAsPdf("
<html>
<head>
<style>
.rotated{
-webkit-transform: rotate(-180deg);
width:400;
height:400;
}
</style>
</head>
<body>
<p class='rotated'>Rotated Text</p>
</body>
</html>
")
pdf.SaveAs("rotated.pdf")