Version: ImageMagick-6.9.2-0
We have deveopers who is using a linux server on amazon AWS.
We want to convert PDF to .jpg for presentation.
It works fine for most PDF´s, but when we upload a PDF with multiple pages, the conversion breaks.
The settings I have for the "convert" part are:
$max_width = '842';
$max_height = '595';
//$attachments_array = array();
//exec("convert -density 300 -trim ".$attachment_path." -quality 30 ".$pdfImgPath);
//exec("convert -version -density -1 ".$attachment_path." -quality 100 ".$pdfImgPath);
//exec("convert -density 1080 -set units PixelsPerInch -density 1080 -quality 300 -background white -flatten -resize {$max_width}x{$max_height} ".$attachment_path." ".$pdfImgPath);
exec("convert -density 1080 -set units PixelsPerInch -density 152 -quality 100 -background white -flatten -resize {$max_width}x{$max_height} ".$attachment_path." ".$pdfImgPath);
// iterate over pages of the pdf file
The pdf itself is created in PPT, and in landscape mode, and I guess the resolution for A4 landscape is 842x595 using 72 dpi.
I have tried to increase quality to 100, to make the image crisp.
and the second density to 152.
When uploading a PDF from 23Kb to 8Mb it all works fine.
but when a small PDF is creted with multiple "pages" the upload breaks.
PDF to -jpg convertion , the image breaks for multiple PDF
-
- Posts: 12159
- Joined: 2010-01-23T23:01:33-07:00
- Authentication code: 1151
- Location: England, UK
Re: PDF to -jpg convertion , the image breaks for multiple PDF
Define "breaks". What happens? Do you get any images? Any error messages? Does your computer catch fire?rezapilot wrote:... but when we upload a PDF with multiple pages, the conversion breaks.
Your commands have bad syntax, for example:
Code: Select all
convert -density 1080 -set units PixelsPerInch -density 152 -quality 100 -background white -flatten -resize {$max_width}x{$max_height} ".$attachment_path." ".$pdfImgPath
How large are your PDF pages (in pixels) and how many pages? Do you have enough memory?
snibgo's IM pages: im.snibgo.com
Re: PDF to -jpg convertion , the image breaks for multiple PDF
breaks: in the backend I can see the image like this: http://www.underconsideration.com/brand ... d_base.png
the file size, themself are not the issue since I have managed to upload files up to 18Mb.
The "break" issue occurs when the PDF file has more than 1 page.
the file size, themself are not the issue since I have managed to upload files up to 18Mb.
The "break" issue occurs when the PDF file has more than 1 page.
-
- Posts: 12159
- Joined: 2010-01-23T23:01:33-07:00
- Authentication code: 1151
- Location: England, UK
Re: PDF to -jpg convertion , the image breaks for multiple PDF
So, you get an image. What is wrong with it?
I asked "How large are your PDF pages (in pixels) and how many pages?" Not megabytes, but pixels and pages.
I suggest you narrow down the problem, to get a failure with one PDF file and one command without any variables. Tell us what that command is, put the PDF somewhere like dropbox.com and paste the URL here.
I asked "How large are your PDF pages (in pixels) and how many pages?" Not megabytes, but pixels and pages.
I suggest you narrow down the problem, to get a failure with one PDF file and one command without any variables. Tell us what that command is, put the PDF somewhere like dropbox.com and paste the URL here.
snibgo's IM pages: im.snibgo.com
Re: PDF to -jpg convertion , the image breaks for multiple PDF
"So, you get an image. What is wrong with it?"
But I cannot use the converted image in my portal since it does not convert properly.
the pixle size for 1 page PDF is 960x718 when using 72 DPI. 1
the issue/error with the broken image occurs ONLY when the PDF has more than 1 page.
here is the link to the heavy PDF: https://www.dropbox.com/s/w91znlnctv59k ... 2.pdf?dl=0
and the PDF w 2 pages: https://www.dropbox.com/s/juaq8qz9cwijz ... e.pdf?dl=0
But I cannot use the converted image in my portal since it does not convert properly.
the pixle size for 1 page PDF is 960x718 when using 72 DPI. 1
the issue/error with the broken image occurs ONLY when the PDF has more than 1 page.
here is the link to the heavy PDF: https://www.dropbox.com/s/w91znlnctv59k ... 2.pdf?dl=0
and the PDF w 2 pages: https://www.dropbox.com/s/juaq8qz9cwijz ... e.pdf?dl=0
-
- Posts: 12159
- Joined: 2010-01-23T23:01:33-07:00
- Authentication code: 1151
- Location: England, UK
Re: PDF to -jpg convertion , the image breaks for multiple PDF
What command fails with one of those PDF files?
snibgo's IM pages: im.snibgo.com
Re: PDF to -jpg convertion , the image breaks for multiple PDF
@snibgo, I appreciate your help alot, but the situation is that the developers that we work with have "left".
Background:
The platform is based on wordpress, the idea is that "admin", uploads a PDF, and using imagemagick, we convert it to a jpg, for the final client to view, using lightbox popup.
While uploading PDF´s that are only 1 page, everything works fine, the image gets uploaded and the final client can see it in the lightbox.
But when admin uploads a PDF that has more than 1 page, thats when in wp-admin the image breaks, as I tried to discribe it last time.
And final client is not able to see or use the jpg image in lightbox, since it does not convert to jpg.
They have created the function of converting multiple PDF´s as custom work, and the script that I can find in the php file is as below.
This should be the one that converts and puts the PDF in page 1-infinite.
When it comes to your points that the code has bad syntex, I would really be glad if you could tell me besides the order, what specific code I can insert.
the command that I use now is: (the same as before)
The page is still in "testmode" ie, I can do changes on the php file and then try it out.
Background:
The platform is based on wordpress, the idea is that "admin", uploads a PDF, and using imagemagick, we convert it to a jpg, for the final client to view, using lightbox popup.
While uploading PDF´s that are only 1 page, everything works fine, the image gets uploaded and the final client can see it in the lightbox.
But when admin uploads a PDF that has more than 1 page, thats when in wp-admin the image breaks, as I tried to discribe it last time.
And final client is not able to see or use the jpg image in lightbox, since it does not convert to jpg.
They have created the function of converting multiple PDF´s as custom work, and the script that I can find in the php file is as below.
This should be the one that converts and puts the PDF in page 1-infinite.
Code: Select all
// iterate over pages of the pdf file
$pno = 0;
for($p = 1; $p <= $pages; $p++){
$im->setIteratorIndex( $p - 1 );
//$im->setResolution(240, 350);
$im->setImageFormat('jpg');
$filename_neu = $filename_wo_extension .'_'. $p .'.jpg';
$attachment_title_final = $attachment_title."-".$pno;
$attachment_title_final = str_replace(" ", "-", $attachment_title_final);
if($pages > 1):
$pdfImgPath = $upload_dir['basedir'].'/pdf_images/'.$attachment_title_final.'.jpg';
$pdfImgUrl = $upload_dir['baseurl'].'/pdf_images/'.$attachment_title_final.'.jpg';
endif;
$arrData = array(
'attachment_id' => $post_ID,
'img_path' => $pdfImgPath,
'img_url' => $pdfImgUrl
);
//pr($arrData);
//die();
$isInsert = $wpdb->insert($strTbl , $arrData);
$pno++;
}
endif;
return $post_ID;
}
add_filter('add_attachment', 'insert_luminance_datas', 10, 2);
//get pdf name by id
the command that I use now is: (the same as before)
Code: Select all
convert -density 1080 -set units PixelsPerInch -density 152 -quality 100 -background white -flatten -resize {$max_width}x{$max_height} ".$attachment_path." ".$pdfImgPath
-
- Posts: 12159
- Joined: 2010-01-23T23:01:33-07:00
- Authentication code: 1151
- Location: England, UK
Re: PDF to -jpg convertion , the image breaks for multiple PDF
Sorry, I can't debug your code.
snibgo's IM pages: im.snibgo.com