当前位置: 首页 > news >正文

CSharp: itextsharp5 imge converter pdf

 

using iTextSharp.text;
using iTextSharp.text.pdf;
using System;
using System.Collections.Generic;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using static System.Net.Mime.MediaTypeNames;namespace HighCharts
{/// <summary>/// geovindu, Geovin Du,塗聚文,涂聚文/// </summary>public partial class itextimagecovertpdf : System.Web.UI.Page{/// <summary>/// /// </summary>/// <param name="sender"></param>/// <param name="e"></param>protected void Page_Load(object sender, EventArgs e){if (!IsPostBack){// Create a new PDF documentDocument doc = new Document(PageSize.A4);string outputPath = Server.MapPath("geovindu.pdf");// Initialize PdfWriterPdfWriter.GetInstance(doc, new FileStream(outputPath, FileMode.Create));// Open the documentdoc.Open();try{// Add a paragraph// doc.Add(new Paragraph("Adding an image to PDF using iTextSharp"));// Load the imagestring imagePath = Server.MapPath("~/AH9_1.png"); // Replace with your image pathiTextSharp.text.Image img = iTextSharp.text.Image.GetInstance(imagePath);// 获取图片尺寸float width = img.Width;float height = img.Height;// Set image propertiesimg.ScaleToFit(width, height); // Resize the imageimg.SetAbsolutePosition(0f, 0f); // Set position (x, y)img.Alignment = Element.ALIGN_CENTER; // Align the image// Add the image to the documentdoc.Add(img);}catch (Exception ex){Response.Write("Error: " + ex.Message);}finally{// Close the documentdoc.Close();}Response.Write("PDF created successfully at " + outputPath);Response.Redirect("output.pdf");}}}
}

  

http://www.rkmt.cn/news/19237.html

相关文章:

  • 20251011 总结
  • 上课讲的部分 qoj 题记录
  • var与let
  • CSP-S 第二轮集训资料 **总结 + 专题细分精讲**_from_黄老师
  • AI元人文:迈向正负价值统一的文明架构
  • CSP-S 第二轮集训资料 **总结 + 专题细分精讲**。
  • 251012
  • C# Avalonia 16- Animation- ExpandElement
  • PVE8.x仅克隆虚拟机配置
  • SQL常用语句分类及示例
  • Electron38-Vue3OS客户端OS系统|vite7+electron38+arco桌面os后台管理
  • 视频拍摄技巧 - 希区柯克变焦/滑动变焦 All In One
  • 记录:git
  • 2025年10月门窗十大品牌最新推荐榜单,十大品牌测评排名与选择指南
  • CF60E Mushroom Gnomes
  • LCPC12E - Johnnys Empire 题解
  • 美国能源部《生成式人工智能参考指南》解读
  • win10系统访问smb服务时提示密码错误
  • 《小说课》读书笔记
  • 鸡哥单人防守爽图7.0通关.
  • AtCoder Beginner Contest 427 ABCDEF 题目解析
  • zju博士资格考试考前复习(微分方程方向)ode 部分
  • 测试一下博客功能
  • NOIP 2024
  • ffplay数据结构解析
  • FileX和ThreadX精简版
  • ue4素材场景 - MKT
  • 阅读《构建之法》的思考与问题
  • 2025年9月22日优雅草蜻蜓I通讯水银版4.1.9版本正式发布-完成所有服务升级版本重构升级-修复大量漏洞-优化启动步骤-卓伊凡|bigniu|麻子|贝贝| - 指南
  • count down 84 days - 详解