PHP または Perl を使用して、クリック追跡と位置隠蔽機能を備えた PDF をブラウザーに表示するにはどうすればよいですか?

Susan Sarandon
リリース: 2024-10-19 18:13:01
オリジナル
439 人が閲覧しました

How to Display PDFs in Browsers with Click Tracking and Location Concealment Using PHP or Perl?

PHP または Perl を使用してユーザーのブラウザに PDF ファイルを表示する

問題: ユーザーは PDF を表示する機能が必要ですクリックを追跡し、PDF の実際の場所を隠す追加機能を備えたブラウザ内でファイルを保存できます。

解決策:

PHP と Perl はどちらも、PDF ファイルを直接レンダリングするメソッドを提供します。ブラウザで。関係する基本的な手順は次のとおりです。

PHP:

<code class="php">header('Content-type: application/pdf');
readfile('the.pdf');</code>
ログイン後にコピー

Perl:

<code class="perl">open(PDF, "the.pdf") or die "could not open PDF [$!]";
binmode PDF;
my $output = do { local $/; <PDF> };
close (PDF);

print "Content-Type: application/pdf\n";
print "Content-Length: " .length($output) . "\n\n";
print $output</code>
ログイン後にコピー

その他の考慮事項:

  • ページ内に PDF を埋め込むには、Content-Disposition ヘッダーをインラインに設定します。 filename="the.pdf".
  • ユーザーが必要な PDF リーダー プラグイン (Adobe Reader など) をインストールしていることを確認してください。
  • 読み込み進行状況バーを無効にするには、Accept-Range を無効にします。バイトヘッダー。

コード例:

PHP (完全):

<code class="php">$file = './path/to/the.pdf';
$filename = 'Custom file name for the.pdf';

header('Content-type: application/pdf');
header('Content-Disposition: inline; filename="' . $filename . '"');
header('Content-Transfer-Encoding: binary');
header('Content-Length: ' . filesize($file));
header('Accept-Ranges: bytes');

readfile($file);</code>
ログイン後にコピー

Perl (完全):

<code class="perl">use strict;
use warnings;

my $file = 'the.pdf';
my $filename = 'Custom file name for the.pdf';

open(PDF, "<$file>") or die "Could not open PDF: $!";
binmode PDF;

my $size = -s PDF;

print "Content-type: application/pdf\n";
print "Content-Disposition: inline; filename=\"$filename\"\n";
print "Content-Transfer-Encoding: binary\n";
print "Content-Length: $size\n\n";

print while <PDF>;</code>
ログイン後にコピー

注: ブラウザの設定により、これらの手法がオーバーライドされ、PDF が強制的にダウンロードされるか、外部アプリケーションで開かれる場合があります。

以上がPHP または Perl を使用して、クリック追跡と位置隠蔽機能を備えた PDF をブラウザーに表示するにはどうすればよいですか?の詳細内容です。詳細については、PHP 中国語 Web サイトの他の関連記事を参照してください。

ソース:php
このウェブサイトの声明
この記事の内容はネチズンが自主的に寄稿したものであり、著作権は原著者に帰属します。このサイトは、それに相当する法的責任を負いません。盗作または侵害の疑いのあるコンテンツを見つけた場合は、admin@php.cn までご連絡ください。
著者別の最新記事
人気のチュートリアル
詳細>
最新のダウンロード
詳細>
ウェブエフェクト
公式サイト
サイト素材
フロントエンドテンプレート
私たちについて 免責事項 Sitemap
PHP中国語ウェブサイト:福祉オンライン PHP トレーニング,PHP 学習者の迅速な成長を支援します!