sumatrapdfreader / sumatrapdf

SumatraPDF reader
http://www.sumatrapdfreader.org
GNU General Public License v3.0
13.63k stars 1.73k forks source link

Export one or more slides pages as PDF/JPG/GIF #687

Open Shohreh opened 7 years ago

Shohreh commented 7 years ago

I sometimes need to export one or more slides from a PDF file, either as a PDF file of its own, JPGs, or as a GIF file (convenient for Twitter).

Currently, it seems like SumatraPDF doesn't support this, so I must open a PDF in eg. LibreOffice just to export slides.

SumatraPeter commented 5 years ago

@kjk: Looks like a duplicate of #367 by the same user.

GitHubRulesOK commented 5 years ago

Since the OP request is image biased I am confining my answer to Image formats (No text based output or extraction)

Make sure you click "Fit a Single Page" icon (next to zoom out) or use the keys CTRL + 6 NOT continuous page modes, otherwise you are likely to only get the first page (page 1)

For the first request of PDF you can simply print to PDF. Just that current page, using file print options. There ARE limitations as the PDF will be printed as an image, so will not have selectable text. (I did say that here we are not attempting to preserve text). Due to the nature of upscaling the PDF file will be larger than expected and will lose definition since it is dithered. The only way round all these issues is to use Version 3.0 and NOT print as image.

For broader range of images Double click the page of a comic or image of interest (it may be only part of the page like the example below) image

Now to see the context menu either right click or press [≣] that is the context menu key to the right of the space bar

Note:- If you have NOT selected an image in a PDF you will not see the second entry "Copy Image" however if you are in a comic book it will be visible without selection (it is a context menu)

Generally you need to choose between the three options and you need to be aware there are differences for each type of file, however you need to factor ZOOM into the decision.

In a PDF file or similar if you want the whole page first zoom to the level you need, so if you want the page half size then first zoom to 50% then "Select All" will capture the whole page (even if you can't see it)

If you want part of a page at double size, first zoom to the level you need e.g. 200% move to one corner of the part you want. Then hold the CTRL key down and start left click dragging towards the opposite corner (even if it is out of view) you can release CTRL as soon as the selection colour (usually yellow) appears but once you release the left mouse button that completes the selection. A right click then offers copy selection, so in this case do NOT select all.

The other option when available of "Copy Image" is unaffected by zoom, that is it will be a 100% copy of the original as seen which could have been any format when embedded but will be converted to pixels in the clipboard.

Now with those clipboard images you can most easily open ms paint via shortcut or Cortana box (or any other preferred image app) and then paste and save as PNG GIF or JPG

Personally I prefer WordPad and save as RTF or Paint and save as PNG

GitHubRulesOK commented 4 years ago

For an alternative method of externalizing a full single pages content see the wider discussion in #542

GitHubRulesOK commented 3 years ago

I have published my SumatraPDF Addin script that exports different file whole page types as fixed quality PNG (rather than as inferior lossy JPG) but once extracted, either as a single page or a range of pages, they can easily be converted by any other imaging tool. For more details see https://forum.sumatrapdfreader.org/t/export-save-page-s-as-jpg-png-picture-s-image-s/1030/11

GitHubRulesOK commented 1 year ago

There are 2 simple ways to export pages, this was so fast on a slow machine I thought it had not run image

So above example is based on mutool convert (this old 32bit can only use 1.20 but 1.23 is available)

ExternalViewers [
    [
        CommandLine = C:\Users\old user\Downloads\Apps\PDF\mupdf\1.20.0\mutool.exe convert -F png -o """%d\Page-.png""" "%1" %p
        Name = Convert Page &To PNG
        Filter = *.pdf
    ]
]

So it is a one file type pony in my case I set that to PNG at default resolution

but you can use any command file combinations you need for example this was an older one I wrote but can be updated and adapted easily.
image

https://github.com/GitHubRulesOK/MyNotes/raw/master/AppNotes/SumatraPDF/Addins/ExportPng/ExportPng.cmd

Altometer1 commented 9 months ago

Hello, friends, your respect is needed! Can you give me some tips on how to efficiently convert PDF files to JPG format?

GitHubRulesOK commented 9 months ago

@Altometer1

PDF to JPG is not ideal unless they are already jpg inside the PDF such as embedded photographs.

IMHO The better Quality output from PDF is PNG and many people say PNG files are bigger than JPG which does not have to be true as PNG has many more options to retain Quality at smaller sizes. If slower decompression is acceptable higher compressions such as WebP may be an alternative.

So first off is WHY JPG ? as it is less efficient for downstream uses.

user1823 commented 7 months ago

I have published my SumatraPDF Addin script that exports different file whole page types as fixed quality PNG

@GitHubRulesOK, this script doesn't seem to work if the filename or the folder name contains a space. Can you suggest and/or push a fix?

GitHubRulesOK commented 7 months ago

Long time ago so would probably do different now if it is a variable without "quoted spaces" it should be easy to find which one and adjust but it works as it is for most common portable cases. so not one I keep maintaining.

Newer up-to-date apps like pdftopng or pdfimages/pdftopbm -png ? should be easy to wrap but I have to compile some of those for run on my system current OS Win32. MuTool is the most compatible but again Artifex dropped Win32 some time ago (after 1.20) and my compiles may not pass virus total as personal unsigned.

user1823 commented 7 months ago

if it is a variable without "quoted spaces" it should be easy to find which one and adjust

If a quick review of the code allows you to find where the quote should be added, it would be great. Otherwise, I will try to find it out myself (it will be difficult though because I don't understand the syntax well)

GitHubRulesOK commented 7 months ago

Hmm there were changes in the way SumatraPDF parses commands more recently, so may depend on your version

The external call should be passing as finally "%1" thus quoted but unknown if that is the cause so will test with recent pre-release first point I see is the filter internally says it is all files (.) but should perhaps be restricted to *.PDF like the MuTool version shown above.

GitHubRulesOK commented 7 months ago

@user1823 Ok updated methods same link new file for your testing (simplified as expects to be in the same folder as MuTool) https://github.com/GitHubRulesOK/MyNotes/raw/master/AppNotes/SumatraPDF/Addins/ExportPng/ExportPng.cmd

Add the latest file in setting something like this where """ improves path /filenames with spaces

ExternalViewers [
    [
        CommandLine = c:\windows\system32\cmd.exe /c " """C:\Some one\Downloaded\Apps\SumatraPDF\Plus\ExportPng.cmd""" """%1""" page=%p "
        Name = Save current page &Graphics to PNG 
        Filter = *.*
    ]
]
user1823 commented 7 months ago

Thanks, this version works after applying a small patch that I have sent as a PR (https://github.com/GitHubRulesOK/MyNotes/pull/1).