国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 開發 > 綜合 > 正文

用C#讀取PDF,PDG

2024-07-21 02:26:04
字體:
來源:轉載
供稿:網友
//創建pdf文件  
  using   system;  
  using   system.io;  
  using   system.text;  
  using   system.collections;  
   
  namespace   paladin.utility  
  {  
  ///   <summary>  
  ///   topdf   的摘要說明。  
  ///   </summary>  
  public   class   topdf  
  {  
  static   float   pagewidth   =   594.0f;  
  static   float   pagedepth   =   828.0f;  
  static   float   pagemargin   =   30.0f;  
  static   float   fontsize   =   20.0f;  
  static   float   leadsize   =   10.0f;  
   
  static   memorystream   mpdf=   new   memorystream();  
   
  public   topdf()  
  {  
  //  
  //   todo:   在此處添加構造函數邏輯  
  //  
  }  
   
  static   void   converttobyteandaddtostream(string   strmsg)  
  {  
  byte[]   buffer=null;  
  buffer=asciiencoding.ascii.getbytes(strmsg);  
  mpdf.write(buffer,0,buffer.length);    
  buffer=null;  
  }  
   
  static   string   xrefformatting(long   xvalue)  
  {  
  string   strmsg   =xvalue.tostring();  
  int   ilen=strmsg.length;  
  if   (ilen<10)  
  {  
  stringbuilder   s=new   stringbuilder();  
  int   i=10-ilen;  
  s.append('0',i);  
  strmsg=s.tostring()   +   strmsg;  
  }  
  return   strmsg;  
  }  
   
  static   public   void   createpdf(string   filepath)  
  {  
  streamwriter   ppdf=new   streamwriter(filepath);  
   
  arraylist   xrefs=new   arraylist();  
  //byte[]   buffer=null;  
  float   ypos   =0f;  
  long   streamstart=0;  
  long   streamend=0;  
  long   streamlen   =0;  
  string   strpdfmessage=null;  
  //pdf文檔頭信息  
  strpdfmessage="%pdf-1.1/n";  
  converttobyteandaddtostream(strpdfmessage);  
   
  xrefs.add(mpdf.length);  
  strpdfmessage="1   0   obj/n";  
  converttobyteandaddtostream(strpdfmessage);  
  strpdfmessage="<<   /length   2   0   r   >>/n";  
  converttobyteandaddtostream(strpdfmessage);  
  strpdfmessage="stream/n";  
  converttobyteandaddtostream(strpdfmessage);  
  ////////pdf文檔描述  
  streamstart=mpdf.length;  
  //字體  
  strpdfmessage="bt/n/f0   "   +   fontsize   +"   tf/n";  
  converttobyteandaddtostream(strpdfmessage);  
  //pdf文檔實體高度  
  ypos   =   pagedepth   -   pagemargin;  
  strpdfmessage=pagemargin   +   "   "   +   ypos   +"   td/n"   ;  
  converttobyteandaddtostream(strpdfmessage);  
  strpdfmessage=   leadsize+"   tl/n"   ;  
  converttobyteandaddtostream(strpdfmessage);  
   
  //實體內容  
  strpdfmessage=   "(http://www.wenhui.org)tj/n"   ;  
  converttobyteandaddtostream(strpdfmessage);  
  strpdfmessage=   "et/n";  
  converttobyteandaddtostream(strpdfmessage);  
  streamend=mpdf.length;  
   
  streamlen=streamend-streamstart;  
  strpdfmessage=   "endstream/nendobj/n";  
  converttobyteandaddtostream(strpdfmessage);  
  //pdf文檔的版本信息  
  xrefs.add(mpdf.length);  
  strpdfmessage="2   0   obj/n"+   streamlen   +   "/nendobj/n";  
  converttobyteandaddtostream(strpdfmessage);  
   
  xrefs.add(mpdf.length);  
  strpdfmessage="3   0   obj/n<</type/page/parent   4   0   r/contents   1   0   r>>/nendobj/n";  
  converttobyteandaddtostream(strpdfmessage);  
   
  xrefs.add(mpdf.length);  
  strpdfmessage="4   0   obj/n<</type   /pages   /count   1/n";  
  converttobyteandaddtostream(strpdfmessage);  
  strpdfmessage="/kids[/n3   0   r/n]/n";  
  converttobyteandaddtostream(strpdfmessage);  
  strpdfmessage="/resources<</procset[/pdf/text]/font<</f0   5   0   r>>   >>/n";  
  converttobyteandaddtostream(strpdfmessage);  
  strpdfmessage="/mediabox   [   0   0   "+   pagewidth   +   "   "   +   pagedepth   +   "   ]/n>>/nendobj/n";  
  converttobyteandaddtostream(strpdfmessage);  
   
  xrefs.add(mpdf.length);  
  strpdfmessage="5   0   obj/n<</type/font/subtype/type1/basefont/courier/encoding/winansiencoding>>/nendobj/n";  
  converttobyteandaddtostream(strpdfmessage);  
   
  xrefs.add(mpdf.length);  
  strpdfmessage="6   0   obj/n<</type/catalog/pages   4   0   r>>/nendobj/n";  
  converttobyteandaddtostream(strpdfmessage);  
   
  streamstart=mpdf.length;  
  strpdfmessage="xref/n0   7/n0000000000   65535   f   /n";  
  for(int   i=0;i<xrefs.count;i++)  
  {  
  strpdfmessage+=xrefformatting((long)   xrefs[i])+"   00000   n   /n";  
  }  
  converttobyteandaddtostream(strpdfmessage);  
  strpdfmessage="trailer/n<</n/size   "+   (xrefs.count+1)+"/n/root   6   0   r/n>>/n";  
  converttobyteandaddtostream(strpdfmessage);  
   
  strpdfmessage="startxref/n"   +   streamstart+"/n%%eof/n";  
  converttobyteandaddtostream(strpdfmessage);  
  mpdf.writeto(ppdf.basestream);  
   
  mpdf.close();  
  ppdf.close();  
  }  
  }  
  }   
  • 本文來源于網頁設計愛好者web開發社區http://www.html.org.cn收集整理,歡迎訪問。
  • 發表評論 共有條評論
    用戶名: 密碼:
    驗證碼: 匿名發表
    主站蜘蛛池模板: 弥渡县| 方山县| 甘谷县| 宁化县| 湟源县| 泸溪县| 上林县| 新建县| 民丰县| 项城市| 望都县| 东方市| 繁昌县| 保靖县| 威信县| 河间市| 永康市| 天门市| 太谷县| 甘德县| 鸡泽县| 廊坊市| 加查县| 晴隆县| 东方市| 佳木斯市| 海盐县| 太原市| 醴陵市| 沙河市| 永善县| 闸北区| 紫阳县| 宜兴市| 林州市| 上思县| 涟水县| 嘉兴市| 梅河口市| 寻甸| 伊川县|