How i can take a pdf page as image in wxDc?

Talk here about issues with one of the components hosted at wxCode, or suggest features for it.
dkaip
Super wx Problem Solver
Super wx Problem Solver
Posts: 333
Joined: Wed Jan 20, 2010 1:15 pm

How i can take a pdf page as image in wxDc?

Post by dkaip »

Hello.
I must take a pdf page as image in wxDc.
There is some example to see?
Thanks
Jim.
User avatar
eranon
Can't get richer than this
Can't get richer than this
Posts: 867
Joined: Sun May 13, 2012 11:42 pm
Location: France
Contact:

Re: How i can take a pdf page as image in wxDc?

Post by eranon »

Basically, you have to display your PDF in a control, then capture the rendered result. So, it means 3 steps: read, render, capture. I never dealed with PDF against wxWidgets, but typing "wxpdf" in Google returns some results...
[Ind. dev. - wxWidgets 3.0/3.1 under "Win 7 64-bit, TDM64-GCC" + "OS X 10.9, LLVM Clang"]
dkaip
Super wx Problem Solver
Super wx Problem Solver
Posts: 333
Joined: Wed Jan 20, 2010 1:15 pm

Re: How i can take a pdf page as image in wxDc?

Post by dkaip »

But how to pdf page to ctrl, or image?
Using wxPdfDoc i do not want to use other library, so i am looking for some example.
For example i found for Magick ... But already use wxPdfDoc...

Code: Select all

#include <Magick++.h>
using namespace Magick;
....
vector<Image> imageList;
readImages( &imageList, "my.pdf" );

for (int i = 0; i < imageList.size(); i++) {
   stringstream fileName;
   fileName << "my" << i << ".tiff";
   imageList[i].write(fileName.str());
}
User avatar
eranon
Can't get richer than this
Can't get richer than this
Posts: 867
Joined: Sun May 13, 2012 11:42 pm
Location: France
Contact:

Re: How i can take a pdf page as image in wxDc?

Post by eranon »

dkaip wrote:But how to pdf page to ctrl, or image?
This is the research you have to do about the point one in your roadmap. There's nothing premade, ready-to-use in wxWidgets itself. You need a class to read, parse, then render the PDF. There're a lot of PDF specs and even if a page can be already an image, most will be not... Then you have to render it to have something to capture (towards an image).
dkaip wrote:Using wxPdfDoc i do not want to use other library, so i am looking for some example. For example i found for Magick ... But already use wxPdfDoc...
You say you want to stick with wxPdfDoc and you show a Magick example: it's contradictory! However, the example you shows seems (I don't know Magick) to extract the existing images from a PDF, then save them in files... It's far from what you want to achieve since you want to capture a rendered page including text, images, specific layout.
[Ind. dev. - wxWidgets 3.0/3.1 under "Win 7 64-bit, TDM64-GCC" + "OS X 10.9, LLVM Clang"]
dkaip
Super wx Problem Solver
Super wx Problem Solver
Posts: 333
Joined: Wed Jan 20, 2010 1:15 pm

Re: How i can take a pdf page as image in wxDc?

Post by dkaip »

From where i must looking to find code?
Evince? Some lib like PoDoFo?
utelle
Moderator
Moderator
Posts: 1125
Joined: Tue Jul 05, 2005 10:00 pm
Location: Cologne, Germany
Contact:

Re: How i can take a pdf page as image in wxDc?

Post by utelle »

dkaip wrote:From where i must looking to find code?
Evince? Some lib like PoDoFo?
First, you have to specify exactly what you want to accomplish. In your previous posts you described that you want/need to display a page from a PDF document on screen, and you stated that you are using wxPdfDocument and want to stay with it.

What you did not tell yet is whether the PDF page you need to display on screen is part of a foreign PDF document or whether it is part of a PDF document you created with your own application. In the latter case you could use the wxPdfDC class and the wxWidgets printing framework, which would allow you to display a preview of your document on screen. In the former case you would need a way to render the PDF page in question. The problem is that wxPdfDocument is a library for creating PDF documents, not for rendering them. The same is true for PoDoFo.

One approach to render a PDF page could be to use a tool like imagemagick to convert a PDF page to a image graphic format like JPEG or PNG and to display the image on screen.

Another approach could be to render a PDF page using PDFium, for which a wxWidgets wrapper, wxPDFView, exists. Not a trivial approach, I'd like to add.

Regards,

Ulrich
dkaip
Super wx Problem Solver
Super wx Problem Solver
Posts: 333
Joined: Wed Jan 20, 2010 1:15 pm

Re: How i can take a pdf page as image in wxDc?

Post by dkaip »

Sorry, the PDF page i need to display on screen is part of a foreign PDF document, and this pdf insert in mine wxPdfDocument. But i need to put some things on some pages, so i must can ability to see pages.
Thank you very much, i will try wxPDFView.
User avatar
eranon
Can't get richer than this
Can't get richer than this
Posts: 867
Joined: Sun May 13, 2012 11:42 pm
Location: France
Contact:

Re: How i can take a pdf page as image in wxDc?

Post by eranon »

As utelle stated, your approach is a little blur and it becomes more and more opaque at every message. Until now, you wanted to convert a PDF page to an image and in your last message you introduce the fact that you want to insert a PDF into a PDF you created and that you need to edit this foreign PDF too... It's a lot of different things! Maybe you should draw a global flowchart... There's no magic button that will give you the overall design of you app. It's up to you to sort the tasks and ask when you have a precise question; and eventually with some code showing you really started to try something by yourself.
[Ind. dev. - wxWidgets 3.0/3.1 under "Win 7 64-bit, TDM64-GCC" + "OS X 10.9, LLVM Clang"]
dkaip
Super wx Problem Solver
Super wx Problem Solver
Posts: 333
Joined: Wed Jan 20, 2010 1:15 pm

Re: How i can take a pdf page as image in wxDc?

Post by dkaip »

It is simple. I have an external pdf file. Creating a wxPDFDocument file, insert all pages in that.
But i must add some text and images at certain pages on that, depends of the page image that i must see first.
That is all. Very clear. To see a page in a wxDC is the hole problem.
So i must do all that have told me.
Thank's
Jim.
Some questions for utelle. First thanks for answer about all that.
There are 2 projects and i have download first as you say. I think that second project is for Foxit Reader as well.
Now i am trying to run the simple at /wxPDFView/samples/simple/Simple.h. So i am add all files .h and .cpp from 'stc' and 'include' and 'private' dirs, for running without make a lib.
Downloading PDFium, i don’t know what files i must add to project to run ok.
Thank's again.
Jim.
utelle
Moderator
Moderator
Posts: 1125
Joined: Tue Jul 05, 2005 10:00 pm
Location: Cologne, Germany
Contact:

Re: How i can take a pdf page as image in wxDc?

Post by utelle »

dkaip wrote:Some questions for utelle. First thanks for answer about all that.
There are 2 projects and i have download first as you say. I think that second project is for Foxit Reader as well.
Now i am trying to run the simple at /wxPDFView/samples/simple/Simple.h. So i am add all files .h and .cpp from 'stc' and 'include' and 'private' dirs, for running without make a lib.
Downloading PDFium, i don’t know what files i must add to project to run ok.
As far as I can tell you will need wxPDFView and probably PDFium at Google (since it seems that PDFium at github wasn't updated for quite a while). Building PDFium is not trivial - you should follow the instructions given on its website.

Regards,

Ulrich
dkaip
Super wx Problem Solver
Super wx Problem Solver
Posts: 333
Joined: Wed Jan 20, 2010 1:15 pm

Re: How i can take a pdf page as image in wxDc?

Post by dkaip »

I have done those things to build pdfium
download depot_tools
----------------
git clone https://chromium.googlesource.com/chrom ... _tools.git
export PATH=$PATH:/home/a/depot_tools

ninja
--------
sudo apt-get install ninja

pdfium
----------
mkdir repo
cd repo
gclient config --unmanaged https://pdfium.googlesource.com/pdfium.git
gclient sync
cd pdfium

mkdir build-gtk
cd build-gtk
gedit args.gn
--------------------------------
# Build arguments go here.
# See "gn args <out_dir> --list" for available build arguments.
is_debug = true # Enable debugging features.
pdf_is_standalone = true # Set for a non-embedded build.
---------------------------------
cd ..
gn gen build-gtk
But with
ninja -C build-gtk

or

Code: Select all

ninja -C build-gtk pdfium_all
i have no results, only "now monitoring process activity", so i cant make the static lib for wxPDFView.

Any advice welcome.
Thank's
Jim
utelle
Moderator
Moderator
Posts: 1125
Joined: Tue Jul 05, 2005 10:00 pm
Location: Cologne, Germany
Contact:

Re: How i can take a pdf page as image in wxDc?

Post by utelle »

Unfortunately, I have no experience in building PDFium under Linux. Maybe you could try to contact the developer of wxPDFView directly and ask him.

Sorry that I don't have a better answer for you.

Regards,

Ulrich
User avatar
eranon
Can't get richer than this
Can't get richer than this
Posts: 867
Joined: Sun May 13, 2012 11:42 pm
Location: France
Contact:

Re: How i can take a pdf page as image in wxDc?

Post by eranon »

The pdfium forum is there: https://groups.google.com/forum/#!forum/pdfium.
This post is called "Entire page as an image in pdfium": https://groups.google.com/forum/#!topic ... KAe-NroS-w
[Ind. dev. - wxWidgets 3.0/3.1 under "Win 7 64-bit, TDM64-GCC" + "OS X 10.9, LLVM Clang"]
dkaip
Super wx Problem Solver
Super wx Problem Solver
Posts: 333
Joined: Wed Jan 20, 2010 1:15 pm

Re: How i can take a pdf page as image in wxDc?

Post by dkaip »

Hello.
Thank's for answer.
I just made libs, so i am upload how.
Download depot-tools
Set PATH
export PATH=$PATH:/home/a/depot_tools
Do those.. sorry my english... i know well ansient Greek
mkdir repo
cd repo
gclient config --unmanaged https://pdfium.googlesource.com/pdfium.git
gclient sync
cd pdfium
Next install ninja ... NOT THIS ... sudo apt-get install ninja, NO
from https://ninja-build.org/ the instructions ...
git clone git://github.com/ninja-build/ninja.git && cd ninja
git checkout release
cat README
build ninja
./configure.py --bootstrap
the ninja executable file is done, so we copy that to /home/a/repo/pdfium directory.

Next we must place arguments ... so.. in our 'out/debug' directory.
gn args out/debug
out/debug/args.gn file generate and with...
gedit out/debug/args.gn
we add what we want ...
# Build arguments go here.
# See "gn args <out_dir> --list" for available build arguments.

pdf_is_standalone = true # Set for a non-embedded build.
is_component_build = false # Disable component build (must be false)

clang_use_chrome_plugins = false # Currently must be false.
We save and then we must generate ninja files with ..
gn gen out/debug
Now we are ready to compile pdfium lib.
sudo ./ninja -C out/debug pdfium_all
and then after some time we take .. exe files ...
/home/a/repo/pdfium/out/debug/genmacro
/home/a/repo/pdfium/out/debug/genmodule
/home/a/repo/pdfium/out/debug/genperf
/home/a/repo/pdfium/out/debug/genstring
/home/a/repo/pdfium/out/debug/genversion
/home/a/repo/pdfium/out/debug/icudtl.dat
/home/a/repo/pdfium/out/debug/mksnapshot
/home/a/repo/pdfium/out/debug/natives_blob.bin
/home/a/repo/pdfium/out/debug/pdfium_diff
/home/a/repo/pdfium/out/debug/pdfium_embeddertests
/home/a/repo/pdfium/out/debug/pdfium_test
/home/a/repo/pdfium/out/debug/pdfium_unittests
/home/a/repo/pdfium/out/debug/re2c
/home/a/repo/pdfium/out/debug/snapshot_blob.bin
/home/a/repo/pdfium/out/debug/v8_build_config.json
/home/a/repo/pdfium/out/debug/yasm
and the lib files ...
/home/a/repo/pdfium/out/debug/obj/libfdrm.a
/home/a/repo/pdfium/out/debug/obj/libformfiller.a
/home/a/repo/pdfium/out/debug/obj/libfpdfapi.a
/home/a/repo/pdfium/out/debug/obj/libfpdfdoc.a
/home/a/repo/pdfium/out/debug/obj/libfpdftext.a
/home/a/repo/pdfium/out/debug/obj/libfxcodec.a
/home/a/repo/pdfium/out/debug/obj/libfxcrt.a
/home/a/repo/pdfium/out/debug/obj/libfxge.a
/home/a/repo/pdfium/out/debug/obj/libfxjs.a
/home/a/repo/pdfium/out/debug/obj/libimage_diff.a
/home/a/repo/pdfium/out/debug/obj/libpdfium.a
/home/a/repo/pdfium/out/debug/obj/libpwl.a
/home/a/repo/pdfium/out/debug/obj/libtest_support.a
Running for example
out/debug/pdfium_test --png /home/a/mozilla.pdf
we see all mozilla.pdf pages as png images.

It take me a hole day to make all these ...
Today i must connect with wxPDFView...
Thank's all.
Jim
Last edited by dkaip on Tue Dec 19, 2017 4:30 pm, edited 1 time in total.
User avatar
eranon
Can't get richer than this
Can't get richer than this
Posts: 867
Joined: Sun May 13, 2012 11:42 pm
Location: France
Contact:

Re: How i can take a pdf page as image in wxDc?

Post by eranon »

Nice to post this guide ;) Well, *not sure*, but don't forget to take a look at the second link I pushed to you in my previous post: if pdfium allows to catch any PDF page as an image, your job is done and you don't need to render it in a control with wxPDFView (unless you need it for another part of your app, of course)...
[Ind. dev. - wxWidgets 3.0/3.1 under "Win 7 64-bit, TDM64-GCC" + "OS X 10.9, LLVM Clang"]
Post Reply