接続先
- ドライバの URI
ctip://cti.li/- REST API
https://cti.li/api/- MCP
https://cti.li/mcp(claude.ai や ChatGPT などの AI から使うとき。AIから使う)- ドライバ
- github.com/zamasoftnet で公開しています(Apache License 2.0)。
- ドキュメント
- ドライバと変換のすべての機能は、Copper PDF ドキュメントにあります。
ドライバを入れずに試すなら、フォームか JavaScript から REST API に POST します。例は HTML / JavaScript のタブにあります。
言語ごとの使い方
Java
インストール
現在のバージョンは 2.3.0 です。JitPack から取得します。
repositories {
maven { url 'https://jitpack.io' }
}
dependencies {
implementation 'com.github.zamasoftnet:cti.java:v2.3.0'
}
JAR を直接使う場合は、GitHub Releases からアーカイブをダウンロードし、cti-driver-min-2.3.0.jar をクラスパスに追加します。
ウェブページを変換する
import java.io.File;
import java.net.URI;
import jp.cssj.cti2.CTIDriverManager;
import jp.cssj.cti2.CTISession;
import jp.cssj.cti2.helpers.CTISessionHelper;
public class ServerResource {
private static final URI SERVER_URI = URI.create("ctip://cti.li/");
public static void main(String[] args) throws Exception {
try (CTISession session =
CTIDriverManager.getSession(SERVER_URI, "user", "kappa")) {
// test.pdfに結果を出力する
CTISessionHelper.setResultFile(session, new File("test.pdf"));
// 変換対象のサイトへのアクセスを許可する
session.property("input.include", "https://cti.li/**");
// ウェブページを変換
session.transcode(URI.create("https://cti.li/"));
}
}
}
ドキュメント
PHP
インストール
Composer でインストールします。
composer config repositories.zamasoftnet-cti-php vcs https://github.com/zamasoftnet/cti.php
composer require zamasoft/cti-php
ウェブページを変換する
<?php
require_once __DIR__ . '/vendor/autoload.php';
// セッションの開始
$session = cti_get_session('ctip://cti.li/',
array('user' => 'user', 'password' => 'kappa'));
// result.pdfに結果を出力する
$session->set_output_as_file('result.pdf');
// ウェブページを変換
$session->transcode('https://cti.li/');
// セッションの終了
$session->close();
ドキュメント
Perl
インストール
現在のバージョンは 2.1.4 です。
cpanm https://github.com/zamasoftnet/cti.perl/archive/refs/heads/main.tar.gz
ウェブページを変換する
use strict;
use warnings;
use CTI::DriverManager;
# 接続
my $session = CTI::DriverManager::get_session(
'ctip://cti.li/', user => 'user', password => 'kappa');
# result.pdfに結果を出力する
$session->set_output_as_file('result.pdf');
# ウェブページを変換
$session->transcode('https://cti.li/');
# 接続を閉じる
$session->close();
ドキュメント
Ruby
インストール
現在のバージョンは 2.2.0 です。Gemfile に次の行を書いて、bundle install を実行します。
gem 'copper-cti', git: 'https://github.com/zamasoftnet/cti.ruby.git'
ウェブページを変換する
require 'CTI'
include CTI
# セッションの開始
get_session('ctip://cti.li/',
'user' => 'user',
'password' => 'kappa'
) do |session|
# result.pdfに結果を出力する
session.set_output_as_file('result.pdf')
# ウェブページを変換
session.transcode_server('https://cti.li/')
end
include CTI を書かない場合は、CTI.get_session(...) で呼び出します。
ドキュメント
Python
インストール
現在のバージョンは 3.0.1 で、Python 3 用です。
pip install "git+https://github.com/zamasoftnet/cti.python.git#subdirectory=python3"
HTML を変換する
from cti import get_session
# セッションの開始
with get_session(
'ctip://cti.li/',
{'user': 'user', 'password': 'kappa'}
) as session:
# result.pdfに結果を出力する
session.set_output_as_file('result.pdf')
# 文書の送信
with session.transcode() as out:
out.write(b'<html><body><p>Hello Python</p></body></html>')
ドキュメント
Node.js
インストール
現在のバージョンは 1.1.0 です。Node.js 14 以降が必要です。
npm install https://github.com/zamasoftnet/cti.nodejs.git
TypeScript の型定義が入っています。JavaScript からは require('copper-cti') で読み込みます。
HTML を変換する
import { get_session } from 'copper-cti';
async function main() {
// セッションの開始
const session = get_session('ctip://cti.li/', {
user: 'user',
password: 'kappa'
});
try {
// result.pdfに結果を出力する
session.setOutputAsFile('result.pdf');
// 文書の送信
const writer = session.transcode('.');
writer.write('<html><body><h1>Hello, Copper PDF!</h1></body></html>');
writer.end();
await session.waitForCompletion();
} finally {
// セッションの終了
session.close();
}
}
main();
ドキュメント
.NET(C# / VB.NET)
インストール
現在のバージョンは 2.2.0 です。NuGet から取得します。
dotnet add package Zamasoft.CTI
ウェブページを変換する
C# の例です。
using System;
using Zamasoft.CTI;
namespace examples
{
class ServerResource
{
static void Main(string[] args)
{
using (Session session = DriverManager.getSession(
new Uri("ctip://cti.li/"), "user", "kappa"))
{
// test.pdfに結果を出力する
Utils.SetResultFile(session, "test.pdf");
// https://cti.li/以下にあるリソースへのアクセスを許可する
session.Property("input.include", "https://cti.li/**");
// ウェブページを変換
session.Transcode("https://cti.li/");
}
}
}
}
同じものを VB.NET で書くと次のとおりです。
Imports System
Imports Zamasoft.CTI
Module ServerResource
Sub Main()
Using session As Session = DriverManager.getSession( _
New Uri("ctip://cti.li/"), "user", "kappa")
' test.pdfに結果を出力する
Utils.SetResultFile(session, "test.pdf")
' https://cti.li/以下にあるリソースへのアクセスを許可する
session.Property("input.include", "https://cti.li/**")
' ウェブページを変換
session.Transcode("https://cti.li/")
End Using
End Sub
End Module
ドキュメント
HTML / JavaScript
ドライバは要りません。HTTP で REST API を直接呼び出します。
ブラウザで試す
次の URL をブラウザのアドレスバーに貼り付けて開きます。rest.main パラメーターの中身が PDF になります。
https://cti.li/api/transcode?rest.user=user&rest.password=kappa&rest.main=Hello+world%21
フォームから送る
同じことをフォームでも行えます。
<form action="https://cti.li/api/transcode" method="post">
<input type="hidden" name="rest.user" value="user"/>
<input type="hidden" name="rest.password" value="kappa"/>
<textarea name="rest.main">Hello world!</textarea><br/>
<button type="submit">変換</button>
</form>
認証
rest.user と rest.password を送らないと、3014 Authentication failure が返ります。代わりに HTTP の Authorization: Basic ヘッダーでも認証できます。URL はアクセスログに残るので、フォームやプログラムから呼び出すときはヘッダーを使ってください。