利用PDFLIB開發庫生成PDF文件

void CPDFXXXDlg::OnConvert()
{
 // TODO: Add your control notification handler code here
 try
 {
  int iFont;
  PDFlib pPDF;
  CFileDialog m_FileDlg(FALSE,"pdf","",OFN_OVERWRITEPROMPT,"Adobe Acrobat PDF 文件(*.pdf)|*.pdf|所有文件(*.*)|*.*||",this);
  char pFileName[255];
  
  CEdit* pPDFText=(CEdit*)GetDlgItem(IDC_EDITPDF);
  CString strPDFText;
  pPDFText->GetWindowText(strPDFText);
  char pPDFInfo[1024];
  sprintf(pPDFInfo,"%s",strPDFText);

  char pAttachFileName[255];
  sprintf(pAttachFileName,"%s",m_AttachFileName);
  if(m_FileDlg.DoModal()==IDOK)
  {
   m_PDFFileName=m_FileDlg.GetFileName();
   sprintf(pFileName,m_PDFFileName);
   if(pPDF.open_file(pFileName)==-1)
   {
    //
   }
   pPDF.set_parameter("hypertextencoding","host");
   pPDF.set_info("Creator","DigitalSky");
   pPDF.set_info("Author","DigitalTitan");
   pPDF.set_info("Title","Title");
   pPDF.begin_page((float)a4_width,(float)a4_height);
   iFont=pPDF.load_font("Helvetica-Bold","host","");
   pPDF.setfont(iFont,12);
   pPDF.set_text_pos(50,a4_height-50);
   pPDF.setcolor("fill","rgb",0,0,1,0);
   pPDF.show("Version 1.0 (C) CopyRight By Digitaltitan");
   iFont=pPDF.findfont("STSong-Light","GB-EUC-H",0);
   pPDF.setcolor("fill","rgb",0,0,0,0);
   pPDF.setfont(iFont,24);
   pPDF.continue_text("轉換文檔生成爲");
   
   pPDF.setcolor("stroke","rgb",0.24f,0.51f,0.047f,0);
   pPDF.moveto(50,a4_height-80);
   pPDF.lineto(a4_width-50,a4_height-80);
   pPDF.moveto(50,a4_height-78);
   pPDF.lineto(a4_width-50,a4_height-78);
   pPDF.stroke();
   pPDF.attach_file(a4_width-50,0,0,a4_height-90,pAttachFileName,"DigitalSky","DigitalTitan","doc","paperclip");

   pPDF.set_text_pos(50,a4_height-100);
   iFont=pPDF.findfont("STSong-Light","GB-EUC-H",0);
   pPDF.setcolor("fill","rgb",0,0,0,0);
   pPDF.setfont(iFont,12);
   pPDF.continue_text(pPDFInfo);
   
   //

   pPDF.end_page();
   pPDF.close();
  }
 }
    catch(PDFlib::Exception &ex)
 {
  //  
    }
}

發佈了54 篇原創文章 · 獲贊 1 · 訪問量 15萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章