请问大佬们,有如下两个问题:
1,首先有一个PictureBox,已绘制图形,能将图转为Bitmap,现在需要将Bitmap转为PDF;
2,C# 如何使用PictureBox实现类似Word分页效果(思路即可)

解决方案 »

  1.   

    用itextsharp
      

  2.   

    新建一个pdf,然后写入图片……就这么简单……
    itextsharp和spire.pdf都可以
      

  3.   

    参考使用 免费版的Spire.Pdf for .NET来实现,下面就是使用该控件在PDF中插入Bitmap格式图片。
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using Spire.Pdf;
    using System.Drawing;
    using Spire.Pdf.Graphics;namespace DrawImage
    {
        class Program
        {
            static void Main(string[] args)
            {
                //新建PDF文档,添加一页
                PdfDocument doc = new PdfDocument();
                PdfPageBase page = doc.Pages.Add();            //加载图片到Image对象
                Image image = Image.FromFile(@"C:\Users\Administrator\Desktop\Sample.bmp");            //调整图片大小
                int width = image.Width;
                int height = image.Height;
                float scale = 0.8f;  //缩放比例
                Size size = new Size((int)(width * scale), (int)(height * scale));
                Bitmap scaledImage = new Bitmap(image, size);            //加载缩放后的图片到PdfImage对象
                PdfImage pdfImage = PdfImage.FromImage(scaledImage);            //设置图片位置
                float x = 0f;
                float y = 50f;            //在指定位置绘入图片
                page.Canvas.DrawImage(pdfImage, x, y);            //保存文档
                doc.SaveToFile("插入图片.pdf");
            }
        }
    }
      

  4.   

    参考使用 免费版的Spire.Pdf for .NET来实现,下面就是使用该控件在PDF中插入Bitmap格式图片。
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using Spire.Pdf;
    using System.Drawing;
    using Spire.Pdf.Graphics;namespace DrawImage
    {
        class Program
        {
            static void Main(string[] args)
            {
                //新建PDF文档,添加一页
                PdfDocument doc = new PdfDocument();
                PdfPageBase page = doc.Pages.Add();            //加载图片到Image对象
                Image image = Image.FromFile(@"C:\Users\Administrator\Desktop\Sample.bmp");            //调整图片大小
                int width = image.Width;
                int height = image.Height;
                float scale = 0.8f;  //缩放比例
                Size size = new Size((int)(width * scale), (int)(height * scale));
                Bitmap scaledImage = new Bitmap(image, size);            //加载缩放后的图片到PdfImage对象
                PdfImage pdfImage = PdfImage.FromImage(scaledImage);            //设置图片位置
                float x = 0f;
                float y = 50f;            //在指定位置绘入图片
                page.Canvas.DrawImage(pdfImage, x, y);            //保存文档
                doc.SaveToFile("插入图片.pdf");
            }
        }
    }

    免费吗?有水印吧
      

  5.   

    参考使用 免费版的Spire.Pdf for .NET来实现,下面就是使用该控件在PDF中插入Bitmap格式图片。
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using Spire.Pdf;
    using System.Drawing;
    using Spire.Pdf.Graphics;namespace DrawImage
    {
        class Program
        {
            static void Main(string[] args)
            {
                //新建PDF文档,添加一页
                PdfDocument doc = new PdfDocument();
                PdfPageBase page = doc.Pages.Add();            //加载图片到Image对象
                Image image = Image.FromFile(@"C:\Users\Administrator\Desktop\Sample.bmp");            //调整图片大小
                int width = image.Width;
                int height = image.Height;
                float scale = 0.8f;  //缩放比例
                Size size = new Size((int)(width * scale), (int)(height * scale));
                Bitmap scaledImage = new Bitmap(image, size);            //加载缩放后的图片到PdfImage对象
                PdfImage pdfImage = PdfImage.FromImage(scaledImage);            //设置图片位置
                float x = 0f;
                float y = 50f;            //在指定位置绘入图片
                page.Canvas.DrawImage(pdfImage, x, y);            //保存文档
                doc.SaveToFile("插入图片.pdf");
            }
        }
    }

    免费吗?有水印吧
    免费版的没有水印,只有使用收费版的试用过期了才会有水印
      

  6.   

    https://blog.csdn.net/breakbridge/article/details/87089830
      

  7.   

    参考使用 免费版的Spire.Pdf for .NET来实现,下面就是使用该控件在PDF中插入Bitmap格式图片。
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using Spire.Pdf;
    using System.Drawing;
    using Spire.Pdf.Graphics;namespace DrawImage
    {
        class Program
        {
            static void Main(string[] args)
            {
                //新建PDF文档,添加一页
                PdfDocument doc = new PdfDocument();
                PdfPageBase page = doc.Pages.Add();            //加载图片到Image对象
                Image image = Image.FromFile(@"C:\Users\Administrator\Desktop\Sample.bmp");            //调整图片大小
                int width = image.Width;
                int height = image.Height;
                float scale = 0.8f;  //缩放比例
                Size size = new Size((int)(width * scale), (int)(height * scale));
                Bitmap scaledImage = new Bitmap(image, size);            //加载缩放后的图片到PdfImage对象
                PdfImage pdfImage = PdfImage.FromImage(scaledImage);            //设置图片位置
                float x = 0f;
                float y = 50f;            //在指定位置绘入图片
                page.Canvas.DrawImage(pdfImage, x, y);            //保存文档
                doc.SaveToFile("插入图片.pdf");
            }
        }
    }
    请问为什么我用这个方法弄出来的PDF背景时黑色的,当我文字也是黑色的时候就看不到。而且我的图片背景时白色,显示出来也是黑色的
      

  8.   

    发一下源码来看看,好奇怪,你看看哪里有没有设置颜色black的
      

  9.   

    很简单的,用itextsharp和spire.pdf都可以
      

  10.   

            void BitmapToPDF(Bitmap bitmap)
            {
                //新建PDF文档,添加一页
                PdfDocument doc = new PdfDocument();
                PdfPageBase page = doc.Pages.Add();            doc.Pages.RemoveAt(0);//删除第一页,因为有水印            page = doc.Pages.Add();            page.BackgroundColor = Color.White;            Bitmap image = (Bitmap)Image.FromFile("tt.jpg");
                PdfImage pdfImage = PdfImage.FromImage(image);            //设置图片位置
                float x = 0;
                float y = 0;            //在指定位置绘入图片
                page.Canvas.DrawImage(pdfImage, x, y);            //保存文档
                doc.SaveToFile("d:/result.pdf");
                doc.Close();
                Process.Start("d:/result.pdf");
            }
    问题找到了,如果是用传过来的Bitmap就会出错,但是如果是Bitmap.Save()后再load,就正常。这是为什么呢?