Analyzing your prompt, please hold on...
An error occurred while retrieving the results. Please refresh the page and try again.
Aspose.PDF for .NETを使用すると、既存のPDFファイルにヘッダーとフッターを追加できます。PDF文書に画像やテキストを追加することができます。また、C#を使用して1つのPDFファイルに異なるヘッダーを追加することも試してみてください。
次のコードスニペットは、Aspose.PDF.Drawingライブラリでも動作します。
TextStampクラスを使用して、PDFファイルのヘッダーにテキストを追加できます。TextStampクラスは、フォントサイズ、フォントスタイル、フォントカラーなど、テキストベースのスタンプを作成するために必要なプロパティを提供します。ヘッダーにテキストを追加するには、必要なプロパティを使用してDocumentオブジェクトとTextStampオブジェクトを作成する必要があります。その後、PDFのヘッダーにテキストを追加するために、PageのAddStampメソッドを呼び出すことができます。
ヘッダー領域にテキストを調整するようにTopMarginプロパティを設定する必要があります。また、HorizontalAlignmentをCenter、VerticalAlignmentをTopに設定する必要があります。
次のコードスニペットは、C#を使用してPDFファイルのヘッダーにテキストを追加する方法を示しています。
// For complete examples and data files, visit https://github.com/aspose-pdf/Aspose.PDF-for-.NET
private static void AddHeaderText()
{
// The path to the documents directory
var dataDir = RunExamples.GetDataDir_AsposePdf_StampsWatermarks();
// Open PDF document
using (var document = new Aspose.Pdf.Document(dataDir + "TextinHeader.pdf"))
{
// Create header as a TextStamp
var textStamp = new Aspose.Pdf.TextStamp("Header Text")
{
TopMargin = 10,
HorizontalAlignment = Aspose.Pdf.HorizontalAlignment.Center,
VerticalAlignment = Aspose.Pdf.VerticalAlignment.Top
};
// Add header on all pages
foreach (var page in document.Pages)
{
page.AddStamp(textStamp);
}
// Save PDF document
document.Save(dataDir + "TextinHeader_out.pdf");
}
}
PDFファイルのフッターにテキストを追加するには、TextStampクラスを使用できます。TextStampクラスは、フォントサイズ、フォントスタイル、フォントカラーなど、テキストベースのスタンプを作成するために必要なプロパティを提供します。フッターにテキストを追加するには、必要なプロパティを使用してDocumentオブジェクトとTextStampオブジェクトを作成する必要があります。その後、PDFのフッターにテキストを追加するために、PageのAddStampメソッドを呼び出すことができます。
次のコードスニペットは、C#を使用してPDFファイルのフッターにテキストを追加する方法を示しています。
// For complete examples and data files, visit https://github.com/aspose-pdf/Aspose.PDF-for-.NET
private static void AddFooterText()
{
// The path to the documents directory
var dataDir = RunExamples.GetDataDir_AsposePdf_StampsWatermarks();
// Open PDF document
using (var document = new Aspose.Pdf.Document(dataDir + "TextinFooter.pdf"))
{
// Create footer as a TextStamp
var textStamp = new Aspose.Pdf.TextStamp("Footer Text")
{
BottomMargin = 10,
HorizontalAlignment = Aspose.Pdf.HorizontalAlignment.Center,
VerticalAlignment = Aspose.Pdf.VerticalAlignment.Bottom
};
// Add footer on all pages
foreach (var page in document.Pages)
{
page.AddStamp(textStamp);
}
// Save PDF document
document.Save(dataDir + "TextinFooter_out.pdf");
}
}
ImageStampクラスを使用して、PDFファイルのヘッダーに画像を追加できます。Image Stampクラスは、フォントサイズ、フォントスタイル、フォントカラーなど、画像ベースのスタンプを作成するために必要なプロパティを提供します。ヘッダーに画像を追加するには、必要なプロパティを使用してDocumentオブジェクトとImage Stampオブジェクトを作成する必要があります。その後、PDFのヘッダーに画像を追加するために、PageのAddStampメソッドを呼び出すことができます。
次のコードスニペットは、C#を使用してPDFファイルのヘッダーに画像を追加する方法を示しています。
// For complete examples and data files, visit https://github.com/aspose-pdf/Aspose.PDF-for-.NET
private static void AddImageHeader()
{
// The path to the documents directory
var dataDir = RunExamples.GetDataDir_AsposePdf_StampsWatermarks();
// Open PDF document
using (var document = new Aspose.Pdf.Document(dataDir + "ImageinHeader.pdf"))
{
// Create header as an ImageStamp
var imageStamp = new Aspose.Pdf.ImageStamp(dataDir + "aspose-logo.jpg")
{
TopMargin = 10,
HorizontalAlignment = Aspose.Pdf.HorizontalAlignment.Center,
VerticalAlignment = Aspose.Pdf.VerticalAlignment.Top
};
// Add image header on all pages
foreach (var page in document.Pages)
{
page.AddStamp(imageStamp);
}
// Save PDF document
document.Save(dataDir + "ImageinHeader_out.pdf");
}
}
PDFファイルのフッターに画像を追加するには、Image Stampクラスを使用できます。Image Stampクラスは、フォントサイズ、フォントスタイル、フォントカラーなど、画像ベースのスタンプを作成するために必要なプロパティを提供します。フッターに画像を追加するには、必要なプロパティを使用してDocumentオブジェクトとImage Stampオブジェクトを作成する必要があります。その後、PDFのフッターに画像を追加するために、PageのAddStampメソッドを呼び出すことができます。
Center
、VerticalAlignmentをBottom
に設定する必要があります。
次のコードスニペットは、C#を使用してPDFファイルのフッターに画像を追加する方法を示しています。
// For complete examples and data files, visit https://github.com/aspose-pdf/Aspose.PDF-for-.NET
private static void AddImageFooter()
{
// The path to the documents directory
var dataDir = RunExamples.GetDataDir_AsposePdf_StampsWatermarks();
// Open PDF document
using (var document = new Aspose.Pdf.Document(dataDir + "ImageInFooter.pdf"))
{
// Create footer as an ImageStamp
var imageStamp = new Aspose.Pdf.ImageStamp(dataDir + "aspose-logo.jpg")
{
BottomMargin = 10,
HorizontalAlignment = Aspose.Pdf.HorizontalAlignment.Center,
VerticalAlignment = Aspose.Pdf.VerticalAlignment.Bottom
};
// Add image footer on all pages
foreach (var page in document.Pages)
{
page.AddStamp(imageStamp);
}
// Save PDF document
document.Save(dataDir + "ImageInFooter_out.pdf");
}
}
ヘッダー/フッターセクションにTextStampを追加するためにTopMarginまたはBottom Marginプロパティを使用できることは知っていますが、時には1つのPDF文書に複数のヘッダー/フッターを追加する必要がある場合があります。Aspose.PDF for .NETは、これを行う方法を説明します。
この要件を達成するために、個別のTextStampオブジェクトを作成し(オブジェクトの数は必要なヘッダー/フッターの数によります)、それらをPDF文書に追加します。また、個々のスタンプオブジェクトに異なる書式情報を指定することもできます。次の例では、Documentオブジェクトと3つのTextStampオブジェクトを作成し、PageのAddStampメソッドを使用してPDFのヘッダーセクションにテキストを追加しました。次のコードスニペットは、Aspose.PDF for .NETを使用してPDFファイルのフッターに画像を追加する方法を示しています。
// For complete examples and data files, visit https://github.com/aspose-pdf/Aspose.PDF-for-.NET
private static void AddDifferentHeaders()
{
// The path to the documents directory
var dataDir = RunExamples.GetDataDir_AsposePdf_StampsWatermarks();
// Open PDF document
using (var document = new Aspose.Pdf.Document(dataDir + "AddingDifferentHeaders.pdf"))
{
// Create three stamps
var stamp1 = new Aspose.Pdf.TextStamp("Header 1");
var stamp2 = new Aspose.Pdf.TextStamp("Header 2");
var stamp3 = new Aspose.Pdf.TextStamp("Header 3");
// Set stamp1 properties (Header 1)
stamp1.VerticalAlignment = Aspose.Pdf.VerticalAlignment.Top;
stamp1.HorizontalAlignment = Aspose.Pdf.HorizontalAlignment.Center;
stamp1.TextState.FontStyle = Aspose.Pdf.Text.FontStyles.Bold;
stamp1.TextState.ForegroundColor = Aspose.Pdf.Color.Red;
stamp1.TextState.FontSize = 14;
// Set stamp2 properties (Header 2)
stamp2.VerticalAlignment = Aspose.Pdf.VerticalAlignment.Top;
stamp2.HorizontalAlignment = Aspose.Pdf.HorizontalAlignment.Center;
stamp2.Zoom = 10;
// Set stamp3 properties (Header 3)
stamp3.VerticalAlignment = Aspose.Pdf.VerticalAlignment.Top;
stamp3.HorizontalAlignment = Aspose.Pdf.HorizontalAlignment.Center;
stamp3.RotateAngle = 35;
stamp3.TextState.BackgroundColor = Aspose.Pdf.Color.Pink;
stamp3.TextState.Font = Aspose.Pdf.Text.FontRepository.FindFont("Verdana");
// Add the stamps to specific pages
document.Pages[1].AddStamp(stamp1);
document.Pages[2].AddStamp(stamp2);
document.Pages[3].AddStamp(stamp3);
// Save PDF document
document.Save(dataDir + "MultiHeader_out.pdf");
}
}
Analyzing your prompt, please hold on...
An error occurred while retrieving the results. Please refresh the page and try again.