我确实从jpg图像生成了一个pdf文件。但jpg图像具有官方文件的大小。当我打开pdf时,图像太大了。我需要pdf文件是官方纸张大小。有解决方案吗(panel1具有官方纸张的大小。我需要这个尺寸等于官方纸张的尺寸)
SaveFileDialog saveFileDialog1 = new SaveFileDialog();
saveFileDialog1.Filter = "PDF Files|*.pdf";
string fileName = string.Empty;
saveFileDialog1.FileName = "name.pdf";
btnGerarPDF.Visible = false;
using (Bitmap bitmap = new Bitmap(panel1.ClientSize.Width,
panel1.ClientSize.Height))
{
panel1.DrawToBitmap(bitmap, panel1.ClientRectangle);
bitmap.Save("C:\\" + (nPaginasPDF + 1) + ".bmp", ImageFormat.Bmp);
}
if (saveFileDialog1.ShowDialog() == DialogResult.OK)
{
fileName = saveFileDialog1.FileName;
Document doc = new Document();
PdfWriter.GetInstance(doc, new FileStream(fileName, FileMode.Create));
doc.Open();
for (int iCnt = 0; iCnt < nPaginasPDF+1; iCnt++)
{
iTextSharp.text.Image image1 = iTextSharp.text.Image.GetInstance("C:\\" + (iCnt + 1) + ".bmp");
image1.ScalePercent(75f);
doc.NewPage();
doc.Add(image1);
}
doc.Close();
}
答案 0 :(得分:1)
您可以在创建文档时设置pagesize:
Document doc = new Document(PageSize.A4);