Re: PDF to Image Converter
HI
http://www.foolabs.com/xpdf/ try this, u just have to port that in ur application. it will give u image also
Re: PDF to Image Converter
I might be missing the obvious, but nothing in your code seems to set "scaledsimage", which will remain a null pixmap and produce nothing out at line 19.
1 Attachment(s)
Re: PDF to Image Converter
Thank you ChrisW67 and vishwajeet.dusane
I have been using ..GraphicsViewEdit example to get the PDF Opject Loaded then Save any page I want to a PNG file.
http://www.qt-apps.org/content/show....?content=80234
I have been using some code and Classes to my project.
I have been messing with code.. this why it was not in my last code
Code:
pdfFile = LoadPDF( fixurl.absoluteFilePath() ,page,large);
QImage tImage
= pdfFile.
toImage();
tImage.save("tfile.png","PNG",100);
The tool I'm working on is some sort of mass PDF Converter to Images.
Attachment 4368
I have been trying to make it some sample .. to convert the loaded PDF file into the
the Function LoadPDF Returns QPixmap for the selected Page .. but it has no setScaledSize .. and when you save. no file at all shows up.
Best Regards :)
Re: PDF to Image Converter
LoadPDF() is possibly not returning what you think. Have you tried looking at pdfFile.isNull() and/or pdfFile.size() to see if a meaningful pixmap is actually being returned?
Alternatively, conversion to QImage is failing: use QImage::isNull() to check.
Or, the save is failing but you are ignoring the return code.
Re: PDF to Image Converter
Hi ChrisW67
Thanks for your help..
the implementation Code for the Function LoadPDF
Code:
{
const QString pdfFile
= PathConvert
(fn
);
const QString tmpFile = PathConvert
(QDir::homePath()+"/sctodaytmps.png");
const QString qttmpFile
= QDir::homePath()+"/sctodaytmps.png";
tmp.setNum(Page);
int ret = -1;
tmp.setNum(Page);
args.append("-sDEVICE=png16m");
args.append("-r72");
args.append("-dGraphicsAlphaBits=4");
args.append("-o");
args.append(tmpFile);
args.append("-dFirstPage="+tmp);
args.append("-dLastPage="+tmp);
args.append(pdfFile);
ret = callGS(args);
////////qDebug() << "### ret " << ret;
if (ret == 0)
{
QPixmap penna
= tmpimage.
scaledToWidth(w
);
tmpimage.detach();
QFile lastaction
(qttmpFile
);
lastaction.remove();
p.begin(&penna);
p.setBrush(Qt::NoBrush);
p.
setPen(QPen(QBrush(Qt
::black),
2,Qt
::SolidLine));
p.drawRect(0, 0, penna.width(), penna.height());
p.end();
return penna;
}
return pm;
}
I have tested the way you suggested with this code
Code:
pdfFile = LoadPDF( fixurl.absoluteFilePath() ,page,large);
if (pdfFile.isNull())
QMessageBox::warning(0,
"pdfFile.isNull() = True ",
"pdfFile.isNull() = True");
QImage tImage
= pdfFile.
toImage();
if (tImage.isNull())
QMessageBox::warning(0,
"tImage.isNull() = True ",
"tImage.isNull() = True");
I'm getting both of the messages .. that mean it's not loading and converting to QPixmap
I think I will miss with the function more tomorrow..
Best Regards :)
Re: PDF to Image Converter
Hi Rajab,
i'm interested in a function that converts PDF in a QImage, how can i implement it? is ur code available on sourceforge or somewhere?? tnx for ur help
Re: PDF to Image Converter
The approach above uses Ghostscript to convert the PDF to PNG. It simply builds a command line and runs gs (using QProcess I assume) to do the conversion. The resulting PNG file is then loaded into a QPixmap/QImage.
Re: PDF to Image Converter
Hi, thanks for sharing converting PDF to PNG. I just wonder whether it works for other raster images, especially for PDF to TIFF conversion, single-page or multi-page. Is that OK?
Re: PDF to Image Converter
Quote:
Originally Posted by
mindylynn0
Hi, mindylynn0.
Have you ever found your way out?
Re: PDF to Image Converter
Considering she made only one post to this forum, and that one nearly two years ago, it is very unlikely you will get an answer to your question from her. Why bring back a dead thread? Check the date of the last post before you respond to something.
Re: PDF to Image Converter
To save PDF to images for easily sharing, viewing and others, PDFelement is what you need. It converts PDF pages into images like JPG, JPEG, PNG, BMP, TIFF, etc. What's more, the images in PDF file can be exported to your computer.
youtube.com/watch?v=F67uHRaNvJc
Re: PDF to Image Converter
Maybe you can explain why you think posting a link to a video about a commercial product is relevant in a forum dedicated to writing software using Qt? And why we shouldn't just consider your post to be spam?
Re: PDF to Image Converter
Quote:
Originally Posted by
marsiliano
Hi Rajab,
i'm interested in a function that converts PDF in a QImage, how can i implement it? is ur code available on sourceforge or somewhere?? tnx for ur help
story saver instagram
Hello! Unfortunately, my code isn't on SourceForge. However, I can guide you in implementing a function to convert PDF to QImage. Feel free to share more details about your project!
Re: PDF to Image Converter
Quote:
Feel free to share more details about your project!
Do you realize you are replying to a 14 year old post?
In case anyone wanders into this post, the QPdf module contains the functionality needed to open a PDF document, navigate through it page by page, and render individual pages to a QImage using QPdfDocument. If you want to save the image to a file, QImage::save() will do that. If you want to display the page image on-screen, then QPainter::drawImage() will do that for you.
There is no need for any external (non-Qt) code to accomplish this.