Magick++ and PDF
Magick++ and PDF
In program I need read PDF files and them convert it to BLOB.
The default density 72dpi very small for me. I need 300-600dpi.
In the program I use Magick++ class.
Please give me example of setting pdf density before reading file into memory.
The default density 72dpi very small for me. I need 300-600dpi.
In the program I use Magick++ class.
Please give me example of setting pdf density before reading file into memory.
Re: Magick++ and PDF
Please give me example of setting pdf density before reading file into memory.
Code: Select all
try
{
Image image;
image.density("100");
image.read("logo.pdf");
image.write("logo.miff");
}
catch (Magick::WarningCoder &e)
{
cout << "Warning " << e.what() << endl;
}
Re: Magick++ and PDF
This is situation when pdf file consist of one page. What about multipage pdf?
Re: Magick++ and PDF
Magick++ will process multiple PDF's. If you want to access individual pages use STL.
Re: Magick++ and PDF
I try such code
...
image.read(&fname[1]); //I wont read second page of pdf file "fname"
...
It compile fine, but when I run program with filename "file_venugopal.pdf" I recive error "ImageMagick: unable to open image `ile_venugopal.pdf': No such file or directory @ blob.c/OpenBlob/2411"
Where is my mistake?
...
image.read(&fname[1]); //I wont read second page of pdf file "fname"
...
It compile fine, but when I run program with filename "file_venugopal.pdf" I recive error "ImageMagick: unable to open image `ile_venugopal.pdf': No such file or directory @ blob.c/OpenBlob/2411"
Where is my mistake?
-
- Posts: 1015
- Joined: 2005-03-21T21:16:57-07:00
Re: Magick++ and PDF
&fname[1] is the address of the second character of the string in fname. So, since fname is "file_venugopal.pdf", &fname[1] will pass the string "ile_venugopal.pdf" to image.read.
What you need is to put "[1]" as part of the file name so that fname is "file_venugopal.pdf[1]"
Pete
What you need is to put "[1]" as part of the file name so that fname is "file_venugopal.pdf[1]"
Pete
Sorry, my ISP shutdown all personal webspace so my MagickWand Examples in C is offline.
See my message in this topic for a link to a zip of all the files.
See my message in this topic for a link to a zip of all the files.
Re: Magick++ and PDF
I try
with result:
...
Now we form file name
"file_venugopal.pdf[1]"ImageMagick: unable to open image `"file_venugopal.pdf[1]"': No such file or directory @ blob.c/OpenBlob/2411
...
Code: Select all
try {
Image image;
image.density("300");
int i=1;
char* temp;
sprintf(temp, "\"%s[%d]\"",fname, i );
cout << "Now we form file name"<<"\n";
cout << temp;
image.read(temp);
// Write to BLOB in BMP format
image.write(&blob, "DIB");
} catch(Exception &error_) {
cerr << error_.what() << "\n";
return NULL;
}
...
Now we form file name
"file_venugopal.pdf[1]"ImageMagick: unable to open image `"file_venugopal.pdf[1]"': No such file or directory @ blob.c/OpenBlob/2411
...
Re: Magick++ and PDF
Don't use the double quotes. Double quotes are useful for command shells, not for the API.
Re: Magick++ and PDF
Thank you, it's work.
Small question: How to identify number of page in multipage pdf without readImages() function?
Small question: How to identify number of page in multipage pdf without readImages() function?
Re: Magick++ and PDF
Use ping() to just return metadata associated with an image including the page count. To make it efficient, set the density / resolution to something small like 10 (e.g. image.density(10)).
Re: Magick++ and PDF
I read ping() documentation and no found where it is number of page image atribute:
Ping is similar to read except only enough of the image is read to determine the image columns, rows, and filesize. The columns , rows , and fileSize attributes are valid after invoking ping. The image data is not valid after calling ping.
Re: Magick++ and PDF
Is it "analog" of ping() function for STL?
How to change image density to 300dpi before reading image into STL list?
How to change image density to 300dpi before reading image into STL list?
Re: Magick++ and PDF
I know this is a dead thread but I'm stuck in the same pickle. I'm reading in a PDF with multiple pages. Each page needs to be read in at a DPI of 300x300. Seeing as I cannot pass options into Magick::readImages() my only option as far as I am aware is preallocating a STL container of Magick::Image and looping through setting calling density() on each of them before passing the container to Magick::readImages(). The issue is that ping()ing a Magick::Image doesn't allow it to return the number of pages. The only way I see to retrieve the number of pages in a PDF document is to call Magick::readImages() and call size() on the STL container. I'd rather not have to read the PDFs in twice, one to preallocate the Magick::Images and set the density, then again to read in the PDF again with the desired density.
Re: Magick++ and PDF
I will see if I can add something that will allow you to specify the density before the next release.
Edit: With the next release of ImageMagick (6.8.9-7) you will be able to do this:
Edit: With the next release of ImageMagick (6.8.9-7) you will be able to do this:
Code: Select all
ReadOptions options;
options.density(Geometry(300, 300));
std::list<Image> images;
readImages(&images, "C:\\test.pdf", options);
size_t i;
std::list<Image>::iterator image;
for (image = images.begin(), i = 0; image != images.end(); image++, i++)
image->write("C:\\test." + std::to_string(i) + ".png");