一部のテキストが左右の境界線に非常に近い PDF があり、iTextSharp を使用して PDF の各ページの上下左右の境界線に空白を追加したいと考えています。
これは iTextSharp を使用して可能ですか、それとももっと良い方法がありますか?
一部のテキストが左右の境界線に非常に近い PDF があり、iTextSharp を使用して PDF の各ページの上下左右の境界線に空白を追加したいと考えています。
これは iTextSharp を使用して可能ですか、それとももっと良い方法がありますか?
私はなんとか答えを見つけることができました。以下のコードは、ページのサイズを調整します。
var inputPdf = new PdfReader(inputFile); // Get input document
int pageCount = inputPdf.NumberOfPages;
if (end < start || end > pageCount)
end = pageCount;
var inputDoc = new Document(inputPdf.GetPageSizeWithRotation(1));
using (var fs = new FileStream(outputFile, FileMode.Create))
{
var outputWriter = PdfWriter.GetInstance(inputDoc, fs);
inputDoc.Open();
PdfContentByte cb1 = outputWriter.DirectContent;
// Copy pages from input to output document
for (int i = start; i <= end; i++)
{
var existingRec = inputPdf.GetPageSizeWithRotation(i);
var newRec = new Rectangle(0.0f, 0.0f, existingRec.Width + 50, existingRec.Height + 25, 0);
inputDoc.SetPageSize(newRec);
inputDoc.NewPage();
PdfImportedPage page = outputWriter.GetImportedPage(inputPdf, i);
int rotation = inputPdf.GetPageRotation(i);
if (rotation == 90 || rotation == 270)
cb1.AddTemplate(page, 0, -1f, 1f, 0, 0, inputPdf.GetPageSizeWithRotation(i).Height);
else cb1.AddTemplate(page, 1f, 0, 0, 1f, 25, 13);
}
inputDoc.Close();
}
これが誰かを助けることを願っています。