如何将bmp保存为pdf?

时间:2013-01-28 15:26:58

标签: c# visual-studio

我正在保存图片,但我需要将此图片转换为pdf并保存。我怎么能这样做?

以下是我使用过的代码:

private void button3_Click(object sender, EventArgs e)
    {
        SaveFileDialog saveFileDialog1 = new SaveFileDialog();
        saveFileDialog1.FileName = "image.bmp";
        if (saveFileDialog1.ShowDialog() == DialogResult.OK)
        {

            Bitmap bitmap = new Bitmap(this.Width, this.Height);
            this.DrawToBitmap(bitmap, this.ClientRectangle);
            using (var Stream = saveFileDialog1.OpenFile())
            {
                bitmap.Save(Stream, ImageFormat.Bmp);
            }

        }
}

3 个答案:

答案 0 :(得分:3)

您需要使用PDF库,例如PDFSharp

以下是将图像添加到PDF的sample code

void DrawImage(XGraphics gfx, int number)
{
  BeginBox(gfx, number, "DrawImage (original)");

  XImage image = XImage.FromFile(jpegSamplePath);

  // Left position in point
  double x = (250 - image.PixelWidth * 72 / image.HorizontalResolution) / 2;
  gfx.DrawImage(image, x, 0);

  EndBox(gfx);
}

答案 1 :(得分:0)

我使用iTextSharp转换为PDF

答案 2 :(得分:0)

Pdf是一种容器格式。所以无法将位图保存为一个pdf,而是将位图嵌入 pdf

iTextSharp非常适合这种情况 见Insert an Image in PDF using ITextSharp