Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

画像を添付している時にPDFが生成できない。 #1

Open
ohura-debian opened this issue Mar 8, 2024 · 2 comments
Open

Comments

@ohura-debian
Copy link

バージョン3.6.5を使っています。
{{ref_image}}を使って画像を表示させているページでPDFを生成させようとすると、ブラウザの画面に以下のエラーが出てPDFが生成されません。

Software Error:

unknown image file type: 76%5F%2D%5FCIMG1597%2Ejpg at lib/PDFJ.pm line 1704.

画像が添付されていないページでは特に問題はないようです。

サーバーはDebian GNU/Linuxで、Perlのバージョンは5.38.2です。

@kugijp
Copy link
Member

kugijp commented Mar 9, 2024

PDFJの新しい仕様に対応できていなかったようです。
取り急ぎ、修正箇所をお知らせします。

3.6.4まではJPEGのみ対応でしたが、
3.6.5から下記パッチ適用にて JPEGとPNG画像に対応可能です。

--- plugin/pdf/PDFParser.pm~	2018-01-15 19:19:46.000000000 +0900
+++ plugin/pdf/PDFParser.pm	2024-03-10 02:24:19.000000000 +0900
@@ -455,13 +455,13 @@
 	my $page = shift;
 	my $file = shift;
 	
 	$self->end_text;
 	$self->end_verbatim;
 	
-	unless($file =~ /\.jpe?g$/i){
+	unless($file =~ /\.(jpe?g|png)$/i){
 		return;
 	}
 	
 	my $filename = $self->{wiki}->config('attach_dir')."/".&Util::url_encode($page).".".&Util::url_encode($file);
 	my $info   = image_info($filename);
 	my $width  = $info->{width};
@@ -469,11 +469,15 @@
 	
 	if($width > $self->{width}){
 		$width  = $self->{width};
 		$height = $height * ($width / $info->{width})
 	}
 	
-	my $imgobj = $self->{doc}->new_image($filename,$info->{width},$info->{height},$width,$height,0,$info->{'color_type'});
+	my $type = 'jpg';
+	if ($file =~ /\.png$/i) {
+		$type = 'png';
+	}
+	my $imgobj = $self->{doc}->new_image($filename,$info->{width},$info->{height},$width,$height,0,$info->{'color_type'}, $type);
 	push @{$self->{paras}},$imgobj;
 }
 
 1;

@ohura-debian
Copy link
Author

手元の環境で、jpg、pngを表示している時にもPDFを生成できることを確認しました。
ありがとうございます。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants