链接:https://pan.baidu.com/s/1DO3k7nnx4jMrYQlpskqvxA
提取码:o2vb

 

01]PDF文件一定要放在exe相对应下的files目录下,

procedure TMainForm.UniFormBeforeShow(Sender: TObject);
begin
  UniPDFFrame1.Align:=alClient;
  UniPDFFrame1.PdfURL:= 'files/aaa.pdf';
end;

 否则会弹出错误

取消这些按钮:  要PDF能正常显示的情况下,再进行,否则会弹出JS错误

procedure TfrmSysDeptAdd.UniPDFFrame1FrameLoaded(Sender: TObject);
begin
  // download button
  UniSession.AddJS (UniPDFFrame1.JSName + '.iframe.contentWindow.document.'
       + 'getElementById ("download").style.display = "none"');
  UniSession.AddJS (UniPDFFrame1.JSName + '.iframe.contentWindow.document.'
       + 'getElementById ("secondaryDownload").style.display = "none"');

  // print button
  UniSession.AddJS (UniPDFFrame1.JSName + '.iframe.contentWindow.document.'
       + 'getElementById ("print").style.display = "none"');
  UniSession.AddJS (UniPDFFrame1.JSName + '.iframe.contentWindow.document.'
       + 'getElementById ("secondaryPrint").style.display = "none"');

  // open file button
  UniSession.AddJS (UniPDFFrame1.JSName + '.iframe.contentWindow.document.'
       + 'getElementById ("openFile").style.display = "none"');
  UniSession.AddJS (UniPDFFrame1.JSName + '.iframe.contentWindow.document.'
       + 'getElementById ("secondaryOpenFile").style.display = "none"');

  // view bookmark button
  UniSession.AddJS (UniPDFFrame1.JSName + '.iframe.contentWindow.document.'
       + 'getElementById ("viewBookmark").style.display = "none"');
  UniSession.AddJS (UniPDFFrame1.JSName + '.iframe.contentWindow.document.'
       + 'getElementById ("secondaryViewBookmark").style.display = "none"');

  // documentProperties
  UniSession.AddJS (UniPDFFrame1.JSName + '.iframe.contentWindow.document.'
       + 'getElementById ("documentProperties").style.display = "none"');

  // presentationMode
  UniSession.AddJS (UniPDFFrame1.JSName + '.iframe.contentWindow.document.'
       + 'getElementById ("presentationMode").style.display = "none"');

  // secondaryPresentationMode
  UniSession.AddJS (UniPDFFrame1.JSName + '.iframe.contentWindow.document.'
       + 'getElementById ("secondaryPresentationMode").style.display = "none"');
end;

 用代码实现按钮功能

procedure TMainForm.UniToolButton11Click(Sender: TObject);
begin   //打印所有页
UniSession.AddJS (UniPDFFrame1.JSName
+ '.iframe.contentWindow.document.' + 'getElementById ("print").click()');
//{或者}MainForm.UniPDFFrame1.JSInterface.JSCall('iframe.contentWindow.print', []);
end;

procedure TMainForm.UniToolButton1Click(Sender: TObject);
begin   //转到首页
UniSession.AddJS (UniPDFFrame1.JSName
     + '.iframe.contentWindow.document.'  + 'getElementById ("firstPage").click()');
end;

procedure TMainForm.UniToolButton3Click(Sender: TObject);
begin   //转到尾页
UniSession.AddJS (UniPDFFrame1.JSName
   + '.iframe.contentWindow.document.' + 'getElementById ("lastPage").click()');
end;

procedure TMainForm.UniToolButton5Click(Sender: TObject);
begin   //转到前一页
UniSession.AddJS (UniPDFFrame1.JSName + '.iframe.contentWindow.document.' + 'getElementById ("previous").click()');
end;

procedure TMainForm.UniToolButton6Click(Sender: TObject);
begin   //转到后一页
UniSession.AddJS (UniPDFFrame1.JSName + '.iframe.contentWindow.document.' + 'getElementById ("next").click()');
end;

procedure TMainForm.UniToolButton8Click(Sender: TObject);
begin  //转到某一页
UniSession.AddJS (UniPDFFrame1.JSName
+ '.iframe.contentWindow.PDFViewerApplication.page=' +  UniEdit1.Text);
end;

 

procedure TMainForm.UniToolButton13Click(Sender: TObject);
begin    //缩上放大 显示
 UniPDFFrame1.PdfURL := 'files/aaa.pdf#zoom=' +  UniComboBox1.Items[UniComboBox1.ItemIndex];  // 'files/aaa.pdf#page=1&zoom=50';
end;