当前位置: 首页 > 工具软件 > SharpPDF > 使用案例 >

C#利用PdfSharp开源类库将图片转换为Pdf并且上传至指定FTP

夏弘义
2023-12-01
                PdfDocument _pdfDoc = new PdfDocument();
                _pdfDoc.AddPage(new PdfPage());
                XGraphics _g = XGraphics.FromPdfPage(_pdfDoc.Pages[0]);
                Bitmap _b = new Bitmap(@"D:\Download\***.jpg");
                using (MemoryStream _stream = new MemoryStream())
                {
                    _b.Save(_stream, ImageFormat.Jpeg);
                    XImage _img = XImage.FromStream(_stream);
                    _g.DrawImage(_img, new XPoint(0, 0));
                }

                var request = (FtpWebRequest)WebRequest.Create("ftp://127.0.0.1/test.pdf");
                request.Credentials = new NetworkCredential("FTP账号", "FTP密码");
                request.Method = WebRequestMethods.Ftp.UploadFile;

                using (var ftpStream = request.GetRequestStream())
                {
                    using (MemoryStream _pdfStream = new MemoryStream())
                    {
                        _pdfDoc.Save(_pdfStream);
                        _pdfStream.CopyTo(ftpStream);
                    }
                }
                using (var response = request.GetResponse())
                {
                }

 

 类似资料: