0

VS 2010、C#、iTextSharp の使用

さまざまな既存の PDF ドキュメントを開き、それらから画像を抽出し、それらを新しい PDF ドキュメントに挿入して、PDF ドキュメントを作成しています。私の問題は、新しいPDFドキュメントのスペースを最も効率的に使用するために(ソース画像の幅と高さに応じて)新しいPDFドキュメントでいくつかの画像を回転させようとしていることです(最終的には一連のステッカーを印刷するために使用されます)。出力ファイルを見ると、ステッカーが回転しているように見えますが、ステッカーの右端がドキュメントの上部から消えて、画像が大きなスラッシュのように見えます/ドキュメントの左下から上部まで。

画像を回転させない元のコード (そして完全に動作します)

画像の x、y (sourceXStart、sourceYStart) 座標は動的に計算されます。

既存のコード - No Rotation - は完全に機能します

if ((sourceXStart + pdfInReader.GetPageSizeWithRotation(1).Width + 10) >= (thePageWidth - 5))
{
    sourceXStart = 5;
    sourceYStart = sourceYStart + lastHeight + 30;
    lastHeight = 0;
}

cb.AddTemplate(page, sourceXStart, sourceYStart);  // Add the image
sourceXStart = sourceXStart + pdfInReader.GetPageSizeWithRotation(1).Width + 10;
if (pdfInReader.GetPageSizeWithRotation(1).Width > lastHeight)
{ // Note the maximum height of any sticker in the row
    lastHeight = pdfInReader.GetPageSizeWithRotation(1).Width;
}

新しいコード - 幅と高さに応じて 90 度の回転を試みる

if (pdfInReader.GetPageSizeWithRotation(1).Width < pdfInReader.GetPageSizeWithRotation(1).Height)  // Tall Stickers
{ // First we need to check if this image will fit in the width of the page
    if ((sourceXStart + pdfInReader.GetPageSizeWithRotation(1).Height + 10) >= (thePageWidth - 5))
    {
        sourceXStart = 5;
        sourceYStart = sourceYStart + pdfInReader.GetPageSizeWithRotation(1).Width + 30;
        lastHeight = 0;
    }

    cb.AddTemplate(page, 0, -1f, 1f, sourceXStart, sourceYStart,    pdfInReader.GetPageSizeWithRotation(1).Width);
    sourceXStart = sourceXStart + pdfInReader.GetPageSizeWithRotation(1).Width + 5;
    if (pdfInReader.GetPageSizeWithRotation(1).Width > lastHeight)
    {
        lastHeight = pdfInReader.GetPageSizeWithRotation(1).Width;
    }
}
4

0 に答える 0