ここに私のコードです。それは正しく私が望む画像を追加し、すべてを除いて、画像が元の解像度を使用しているので、画像が大きい場合はページに合わせてトリミングされています。iTextSharpを使用してPDFに画像を追加し、適切に拡大縮小してください。
ズーム機能を使用して画像をストレッチして縦横比を維持する方法はありますか?私はそこに行方不明のものがなければならない。 :P
は、ここで問題を説明するための画像です:
using System;
using System.IO;
using iTextSharp.text;
using iTextSharp.text.pdf;
using System.Drawing;
using System.Collections.Generic;
namespace WinformsPlayground
{
public class PDFWrapper
{
public void CreatePDF(List<System.Drawing.Image> images)
{
if (images.Count >= 1)
{
Document document = new Document(PageSize.LETTER);
try
{
// step 2:
// we create a writer that listens to the document
// and directs a PDF-stream to a file
PdfWriter.GetInstance(document, new FileStream("Chap0101.pdf", FileMode.Create));
// step 3: we open the document
document.Open();
foreach (var image in images)
{
iTextSharp.text.Image pic = iTextSharp.text.Image.GetInstance(image, System.Drawing.Imaging.ImageFormat.Jpeg);
document.Add(pic);
document.NewPage();
}
}
catch (DocumentException de)
{
Console.Error.WriteLine(de.Message);
}
catch (IOException ioe)
{
Console.Error.WriteLine(ioe.Message);
}
// step 5: we close the document
document.Close();
}
}
}
}
だから、あなたの場合には、それは次のようになります。pic.ScaleAbsolute (幅高さ); – Hps
このメソッドは絶対的なスケールになっているので使いません。それは画像を伸ばすとそれを歪ませます。アスペクト比を維持しながらドキュメント内に収めるためには、サイズを大きくする方法が必要です。 –
ここにiTextSharpの画像解像度に関する記事があります。私はそれを使用していない。しかし、あなたは試すことができます。 http://www.mikesdotnetting.com/Article/87/iTextSharp-Working-with-images – Hps