2019年3月24日 星期日

system.web/identity@impersonate 設定為 true。


http://www.programmer-club.com.tw/ShowSameTitleN/aspdotnet/9363.html

https://www.itread01.com/p/1421669.html


HTTP 錯誤 500.24 - Internal Server Error的解決方法 錯誤提示:

最可能的原因:   system.web/identity@impersonate 設定為 true。    
解決辦法: 現在經典模式 連微軟都幾乎放棄了  
原設想是為iis不斷升級 提供的一種相容模式。即是相容模式,一定要放棄一些原有的設定————讓所有經典模式的站點使用經典程式池。這樣就容易造成記憶體混淆。 
所以最好是用整合模式。 
對於500.24 可以通過在配置檔案中確保存在 
<system.webServer>  
<validation validateIntegratedModeConfiguration="false"/>  
</system.webServer>

百聞不如一見,百見不如一做,只有做了,才知道問題出現在哪兒,才能去解決問題。


<configuration>
  <system.web>
    <compilation debug="true" targetFramework="4.6.1"/>
    <httpRuntime targetFramework="4.6.1"/>
    <identity impersonate="true"/>
  </system.web>
  <system.codedom>
    <compilers>
      <compiler language="c#;cs;csharp" extension=".cs"
        type="Microsoft.CodeDom.Providers.DotNetCompilerPlatform.CSharpCodeProvider, Microsoft.CodeDom.Providers.DotNetCompilerPlatform, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
        warningLevel="4" compilerOptions="/langversion:default /nowarn:1659;1699;1701"/>
      <compiler language="vb;vbs;visualbasic;vbscript" extension=".vb"
        type="Microsoft.CodeDom.Providers.DotNetCompilerPlatform.VBCodeProvider, Microsoft.CodeDom.Providers.DotNetCompilerPlatform, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
        warningLevel="4" compilerOptions="/langversion:default /nowarn:41008 /define:_MYTYPE=\&quot;Web\&quot; /optionInfer+"/>
    </compilers>
  </system.codedom>
  <system.webServer>
    <validation validateIntegratedModeConfiguration="false"/>
  </system.webServer>
</configuration>


[咨询站长] ASP.NET 怎么实现pdf转jpg [复制链接]

http://www.sufeinet.com/thread-18284-1-1.html

C#技术分享【PDF转换成图片——13种方案】(2013-07-25重新整理) .
Acrobat.dllc#PDFPDFRender4NET.dllpdf转图片
写在最前面:为了节约大家时间,博主把最常用的方法写在第一条,如果不满足您的需要,您可以继续往后看。

如果看完全文还是不能解决您的问题,欢迎加博主的微博、QQ群(274281457)、QQ(605494869)进行讨论。

关注微博(http://weibo.com/605494869)的童鞋,可以直接找博主索取全部DLL和测试工程(请原谅我合理刷粉)。

GitHub Clone Adress : https://github.com/stone0090/OfficeTools.Pdf2Image.Word2Image.git (you get it).



前段时间公司安排了个任务:要求交付一个DLL,实现【PDF转换成图片】,最好的效果是能够掌握所有源码,实在不行才交付第三方DLL。研究了6个工作日+1双休+每晚9点下班,逛遍了国内外各种论坛,还是没能成功整出源码,但发现了很多有用的工具和其他工具,在此分享给大家。



1、【O2S.Components.PDFRender4NET.dll】,第三方DLL,可以实现PDF转图片,支持32位系统、64位系统(部分第三方dll在64位系统下运行报错)。

官方试用版的dll左上角会有一排红色水印,下面这个是破解版的没有水印,博主使用了一年多基本没有出过问题,推荐使用。

DLL 下载地址:http://download.csdn.net/detail/shi0090/4066107
测试工程 下载地址:http://download.csdn.net/detail/shi0090/4068558



2、【Acrobat.dll】,Adobe官方提供的接口,可以实现PDF转图片。这个方法需要安装Adobe Acrobat X Pro,从安装文件找到Acrobat.dll引用到项目中。

毕竟是Adobe官方提供的接口,其转换效率要比其他的DLL要快多了,而且应该更可靠一些,但是在IIS下运行会比较麻烦(QQ群里有朋友已经实现了)

如果对转换速度、图片质量要求很高的童鞋,可以参考此方案,但是实现过程太麻烦,大家自己权衡,博主对此方法并没有深入研究了。

测试工程 下载地址: http://download.csdn.net/detail/shi0090/4068502

参考地址:http://www.codeproject.com/Artic ... -from-PDF-Documents


3、【PDFLibNet.dll】,第三方DLL,只支持32位系统,可以实现PDF转图片,下面这个版本没有水印。

DLL 下载地址:http://download.csdn.net/detail/shi0090/4066096

测试工程 下载地址:http://download.csdn.net/detail/shi0090/4068522



4、【SautinSoft.PdfFocus.dll】,第三方DLL,可以实现PDF转图片,但转出来的图片左上角有一排红色水印。

DLL 下载地址:http://download.csdn.net/detail/shi0090/4066111
测试工程 下载地址:http://download.csdn.net/detail/shi0090/4068561



5、【TallComponents.PDF.Rasterizer.dll】,第三方DLL,可以实现PDF转图片,但转出来的图片有个较大的水印。

DLL 下载地址:http://download.csdn.net/detail/shi0090/4066112

测试工程 下载地址:http://download.csdn.net/detail/shi0090/4068563



6、【Apitron.PDF.Rasterizer.dll】,第三方DLL,可以实现PDF转图片,但转出来的图片有个较大的红色水印。

DLL 下载地址:http://download.csdn.net/detail/shi0090/5814803

测试工程 下载地址:http://download.csdn.net/detail/shi0090/5814857



7、【XpdfRasterizer.dll】,第三方DLL,可以实现PDF转图片。

DLL 下载地址:http://download.csdn.net/detail/shi0090/4066115
测试工程 下载地址:这个弄不见了,如果使用要使用这个的话,一定要注意Regsvr32注册,要不然转换会失败的。



8、【abcpdf.dll】,第三方DLL,可以实现PDF转图片,但是需要安装abcpdf,所以使用起来不算太放方便。

DLL 下载地址:http://download.csdn.net/detail/shi0090/4066144
测试工程 下载地址:http://download.csdn.net/detail/shi0090/4068564



9、【Ghostscript】,第三方DLL,可以实现PDF转图片,只支持32位系统,貌似网上很多人都会采用这个方法(据说功能强大),个人觉得代码太麻烦没有采用,没有深入研究。

DLL  下载地址:http://download.csdn.net/detail/shi0090/4066005
测试工程 下载地址:http://download.csdn.net/detail/shi0090/4068486
参考地址:http://www.codeproject.com/Artic ... s-using-Csharp.aspx
参考地址:http://www.codeproject.com/Artic ... ing-Ghostscript-API



10、【ImageMagick】,C语言开源PDF处理工具,可以将实现PDF转换图片,因为博主使用的C#,所以C语言的工具就没有深入研究了。

DLL和源码 下载地址:http://download.csdn.net/detail/shi0090/4066040



11、【iTextSharp.dll】,C# 开源PDF处理工具,可以任意操作PDF,并可以提取PDF中的文字和图片,但不能直接将PDF转换成图片。
DLL和源码 下载地址:http://download.csdn.net/detail/shi0090/4065982
中文帮助文档 下载地址:http://download.csdn.net/detail/shi0090/4065986
提取文字测试工程 下载地址:http://download.csdn.net/detail/shi0090/4068429
提取图片测试工程 下载地址:http://download.csdn.net/detail/shi0090/4068428
官方网站:http://itextpdf.com/



12、【PdfSharp.dll】,C# 开源PDF处理工具,可以任意操作PDF,也可以实现从PDF提取图片,但不能直接将PDF转换成图片。
DLL和源码 下载地址:http://download.csdn.net/detail/shi0090/4066060 
提取图片测试工程 下载地址:http://download.csdn.net/detail/shi0090/4068448 

以上两个开源C#工具都可以很好处理PDF文档,但不满足我的要求直接把PDF转成IMAGE。



13、QQ群里有人推荐【PDFToX.dll】速度和质量都不错,就是不太稳定,有兴趣的朋友可以自行研究一下~

官方网站:http://www.ycanpdf.cn/

官方下载:http://www.ycanpdf.cn/software/PDFtoX.rar

2019年3月22日 星期五

c#,將pdf文件轉換成圖片文件

http://www.aspphp.online/bianchen/dnet/cxiapu/cxprm/201701/192161.html

本文采用Adobe Acrobat9.0的COM組件,將Pdf文件的每一頁轉換成對應的圖片文件。
開發環境:VS2010,.Net Framework4.0,Adobe Acrobat9.0。
工程中添加COM引用:Adobe Acrobat 9.0 Type Library(必須裝了Adobe Acrobat9.0才會有)。

思路:
1、需要用到的COM對象:
    1)CAcroPDDoc:Acrobat文檔對象。
    2)CAcroPDPage:頁對象。
    3)CAcroRect:用來描述頁中一個矩形區域的對象。
    4)CAcroPoint:實際上代表的是Size。

2、轉換過程:
   1)打開文檔。
   2)取出每一頁。
   3)獲取每一頁的大小,生成一個表示該頁的矩形區域。
   4)將當前頁的指定區域編碼成圖片,並且復制到剪貼板中。
   5)將剪貼板中的圖片取出,保存為圖片文件。

轉換函數代碼:
        public static void ConvertPdf2Image(string pdfFilePath, string imageDirectoryPath,
            int beginPageNum, int endPageNum, ImageFormat format, double zoom = 1) {
          
            Acrobat.CAcroPDDoc pdfDoc = null;
            Acrobat.CAcroPDPage pdfPage = null;
            Acrobat.CAcroRect pdfRect = null;
            Acrobat.CAcroPoint pdfPoint = null;
            //1)
            //生成操作Pdf文件的Com對象
              pdfDoc = (Acrobat.CAcroPDDoc)Microsoft.VisualBasic.Interaction.CreateObject("AcroExch.PDDoc", "");
            //檢查輸入參數
              if (!pdfDoc.Open(pdfFilePath)) {
                throw new FileNotFoundException(string.Format("源文件{0}不存在!", pdfFilePath));
            }
            if (!Directory.Exists(imageDirectoryPath)) {
                Directory.CreateDirectory(imageDirectoryPath);
            }
            if (beginPageNum <= 0) {
                beginPageNum = 1;
            }
            if (endPageNum > pdfDoc.GetNumPages() || endPageNum <= 0) {
                endPageNum = pdfDoc.GetNumPages();
            }
            if (beginPageNum > endPageNum) {
                throw new ArgumentException("參數\"beginPageNum\"必須小於\"endPageNum\"!");
            }
            if (format == null) {
                format = ImageFormat.Png;
            }
            if (zoom <= 0) {
                zoom = 1;
            }
            //轉換
              for (int i = beginPageNum; i <= endPageNum; i++) {
                //2)
                //取出當前頁
                  pdfPage = (Acrobat.CAcroPDPage)pdfDoc.AcquirePage(i - 1);
                //3)
                //得到當前頁的大小
                   pdfPoint = (Acrobat.CAcroPoint)pdfPage.GetSize();
                //生成一個頁的裁剪區矩形對象
                   pdfRect = (Acrobat.CAcroRect)Microsoft.VisualBasic.Interaction.CreateObject("AcroExch.Rect", "");
                //計算當前頁經縮放後的實際寬度和高度,zoom==1時,保持原比例大小
                   int imgWidth = (int)((double)pdfPoint.x * zoom);
                int imgHeight = (int)((double)pdfPoint.y * zoom);
                //設置裁剪矩形的大小為當前頁的大小
                   pdfRect.Left = 0;
                pdfRect.right = (short)imgWidth;
                pdfRect.Top = 0;
                pdfRect.bottom = (short)imgHeight;
                //4)
                //將當前頁的裁剪區的內容編成圖片後復制到剪貼板中
                  pdfPage.CopyToClipboard(pdfRect, 0, 0, (short)(100 * zoom));
                //5)
                IDataObject clipboardData = Clipboard.GetDataObject();
                //檢查剪貼板中的對象是否是圖片,如果是圖片則將其保存為指定格式的圖片文件
                  if (clipboardData.GetDataPresent(DataFormats.Bitmap)) {
                    Bitmap pdfBitmap = (Bitmap)clipboardData.GetData(DataFormats.Bitmap);
                    pdfBitmap.Save(
                        Path.Combine(imageDirectoryPath, i.ToString("0000") + "." + format.ToString()), format);
                    pdfBitmap.Dispose();
                }
            }
            //關閉和釋放相關COM對象
              pdfDoc.Close();
            Marshal.ReleaseComObject(pdfRect);
            Marshal.ReleaseComObject(pdfPoint);
            Marshal.ReleaseComObject(pdfPage);
            Marshal.ReleaseComObject(pdfDoc);
        }

2019年3月20日 星期三

[c#]自製排程器

https://dotblogs.com.tw/eaglewolf/2011/07/26/32133

StackTrace 及 執行緒-System.Threading.Timer的使用

https://dotblogs.com.tw/yc421206/2010/10/24/18546

https://dotblogs.com.tw/brooke/2015/10/12/153547

https://ithelp.ithome.com.tw/articles/10195452?sc=rss.qu

using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Threading;
using System.Timers;
using System.Windows.Forms;
//匯入命名空間
using ThreadingTimer = System.Threading.Timer;
using TimersTimer = System.Timers.Timer;


namespace ThreadTimer
{
    public partial class Form1 : Form
    {
        //程式開始
        ThreadingTimer _ThreadTimer = null;
        TimersTimer _TimersTimer = null;
        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            Thread t = Thread.CurrentThread;
            bool IsThreadPool = t.IsThreadPoolThread;
            bool IsBackground = t.IsBackground;
            t.Name = "Main Thread";
            string msg = string.Format("Thread[{0}]:{1},Is ThreadPool=[{2}],Is Background=[{3}]", t.ManagedThreadId, t.ThreadState, IsThreadPool, IsBackground);
            this.Text = msg;
         
        }

        private void button2_Click(object sender, EventArgs e)
        {
         
            this._TimersTimer = new TimersTimer();
            this._TimersTimer.Interval = 100;
            this._TimersTimer.Elapsed += new System.Timers.ElapsedEventHandler(_TimersTimer_Elapsed);
            this._TimersTimer.Start();
         
        }
       
        private void _TimersTimer_Elapsed(object sender, ElapsedEventArgs e)
        {
           
            Thread t = Thread.CurrentThread;
            bool IsThreadPool = t.IsThreadPoolThread;
            bool IsBackground = t.IsBackground;
            string msg = string.Format("Thread[{0}]:{1},Is ThreadPool=[{2}],Is Background=[{3}]", t.ManagedThreadId, t.ThreadState, IsThreadPool, IsBackground);
            if (this.listBox2.InvokeRequired)
            {
                listBox2.Invoke(new Action<string>(s => {
                    this.listBox2.Items.Add(s);
                }), msg);
            }
            else
            {
                this.listBox2.Items.Add(msg);

            }
           
        }

        private void button1_Click(object sender, EventArgs e)
        {
            string currentName = new StackTrace(true).GetFrame(0).GetMethod().Name;
            //TimerCallback委派可用來指定 Timer 呼叫的方法, 1.等多久再開始  100.隔多久反覆執行
            this._ThreadTimer = new ThreadingTimer( new System.Threading.TimerCallback(CallbackMethod), currentName, 1, 100);
        }
        void CallbackMethod(object State)
        {
            string methodName = State.ToString();
            Thread t = Thread.CurrentThread;
            bool IsThreadPool = t.IsThreadPoolThread;
            bool IsBackground = t.IsBackground;
            string msg = string.Format("Thread[{0}]:{1},Is ThreadPool=[{2}],Is Background=[{3}]", t.ManagedThreadId, t.ThreadState, IsThreadPool, IsBackground);
            this.BeginInvoke(new UpdateControl(_mUpdateControl), new object[] { this.listBox1, msg });
        }
        delegate void UpdateControl(Control Ctrl, string Msg);
        private object _objLock = new object();
        void _mUpdateControl(Control Ctrl, string Msg)
        {
            //多執行續同時進行時,叫用這個方法時,看有沒有被lock,如有被lock,等他然後再跑裡面的東西
            lock (this._objLock)
            {
                if (Ctrl is ListBox)
                    ((ListBox)Ctrl).Items.Add(Msg);
            }
        }
    }
}

2019年3月16日 星期六

[C#] ComboBox 預設值

http://jengting.blogspot.com/2016/11/ComboBox-DefaultValue.html

https://adon988.logdown.com/posts/7798906-winforms-c-combobox-several-ways-to-set-values

WPF聊天室应用(ASP.NET Core SignalR)

  WPF聊天室应用(ASP.NET Core SignalR) https://www.bilibili.com/video/BV1Q741187Si?p=2 https://www.bilibili.com/video/BV1UV411e75T?from=search...