当前位置: 首页 > 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.jsqmd.com/news/11954/

相关文章:

  • 20251011 总结
  • 上课讲的部分 qoj 题记录
  • var与let
  • CSP-S 第二轮集训资料 **总结 + 专题细分精讲**_from_黄老师
  • AI元人文:迈向正负价值统一的文明架构
  • CSP-S 第二轮集训资料 **总结 + 专题细分精讲**。
  • Ubuntu Linux双网口主机实现在校园网环境下的网络共享
  • 251012
  • C# Avalonia 16- Animation- ExpandElement
  • DshanPI-A1 RK3576 armbian远程桌面
  • Ubuntu Linux双网卡实现在校园网环境下的网络共享
  • PVE8.x仅克隆虚拟机配置
  • SQL常用语句分类及示例
  • 台式机主板上的电池要更换啦
  • 微信小程序 app.js中onLaunch中方法执行完毕后再执行index首页数据请求
  • 轻量服务器Lighthouse + 1Panel 部署.NET 8 Web应用
  • bash alias 多引号问题
  • 关于近期调研各类游戏开发引擎的一些感想
  • Electron38-Vue3OS客户端OS系统|vite7+electron38+arco桌面os后台管理
  • 终于在vim中用上了molokai的炫酷色彩配置了(゚∀゚)
  • 我是如何在Vim8.1中安装好的NERDTree插件的
  • Kafka监控工具 EFAK-AI 介绍
  • 视频拍摄技巧 - 希区柯克变焦/滑动变焦 All In One
  • 信息化说课-教学设计(6)
  • 记录:git
  • P12012 [Ynoi April Fools Round 2025] 牢爱 题解
  • 实验1 现代C++编程初体验
  • 10.11总结
  • 2025年10月门窗十大品牌最新推荐榜单,十大品牌测评排名与选择指南
  • CF60E Mushroom Gnomes