qpdf / qpdf

qpdf: A content-preserving PDF document transformer
https://qpdf.sourceforge.io/
Apache License 2.0
3.37k stars 270 forks source link

[Documentation / Extended Examples Collection] Providing small snippets & solutions #601

Open rubyFeedback opened 2 years ago

rubyFeedback commented 2 years ago

Heya Jay and others,

I recently had a problem with poppler and pdfinfo. As I had that problem with poppler, pdfinfo was not working (actually I think I had more than one problem, but the "net result" was that I could not remove individual pdf pages from larger .pdf books. I am reading a LOT of .pdf files on my computer these days,so chopping off pages is useful to me. Most people probably don't do that, but I need to digest the content, so this is a bit of a "bookmark-tagging" for me. Anyway....)

I looked into my own code and realised that I depended on pdfinfo. But that project was started many years ago, and since then I have transitioned more and more parts into qpdf.

So, I tried to use "qpdf --help" to see if I could find out how to quickly determine how many pages are in a .pdf file.

Turns out this is easily possible in qpdf!

Even I found it on first or second run of "qpdf --help" :-)

So for instance:

qpdf  foobar.pdf  --show-npages # -> outcome was 107 for that .pdf

But that got me thinking ... wouldn't it be neat if qpdf could have some page or document where short examples are shown? Really mostly just small-ish examples, with minimal explanation. Just for people to "get going" and to solve the most common tasks. This can be incomplete, the whole goal would be to provide a "first time starter" or "quick starter" into qpdf.

It can be a separate document, so it does not have to be on the main README, but ideally some .md markdown file that is mentioned from the main README so that people can find it. I write this issue request here because I tend to forget which issue requests I added, so in case others may find it useful I wanted to add it (I am awful at maintaining my own source code consistently ... :P )

At any rate, thank you for reading and potentially considering!

jberkenbilt commented 2 years ago

I just started populating a qpdf wiki. This sounds like a good idea for a wiki page. Keeping wiki pages up to date is particularly challenging, especially as the software ages, but I think this is a good idea. If you have some examples in mind, I can go ahead and add them. Right now, I'm just using the github wiki feature, but it's not that great about suggestions or allowing other people to be granted permission to the wiki without having write access, so I may consider alternatives. I figured something was better than nothing and there was no point in overdesigning before I had any idea whether anyone would ever use it.

brainwane commented 1 year ago

I have a specific request for a small snippet. I'm trying to switch from pdftk to qpdf. The specific problem I keep running into is page selection. I've read the relevant section of the documentation and the section on page ranges several times but none of the examples are as simple as my use case:

Select pages 4-8 from in.pdf to create out.pdf

and I keep running into error messages as I try different permutations of the syntax.

So this is an example of the level of recipe some folks might need help with! Here's a cookbook of recipes for ffmpeg that could serve as another inspiration.

Thanks!

concreteRick commented 1 year ago

I too found this a struggle :-(.

After trial and error, the following worked:

        qpdf  in.pdf --pages in.pdf 4-8 "--"  out.pdf

I don't know if that's the best or proper way to do this. The quotes around "--" seem to be required in the case of Windows PowerShell, which I'm using. The processing was super-fast.

With the above command, the entire set of Bookmarks and the entire PDF Structure tree in 'in.pdf' seem to be included in 'out.pdf'. Meaning both often point to nothing in 'out.pdf'.

        --flatten-annotations

may fix or half-fix that somehow. But I have not figured it out yet ...

-- @.***


Rick Davies, Technical Sales Manager Datazone Ltd, Tel: +353 64 66 289 64 Palm Gate, Greenane, Killarney, Fax: +353 64 66 289 65 Co. Kerry, Irelandwww.miramo.com


On 04/01/2023 23:04, Sumana Harihareswara wrote:

I have a specific request for a small snippet. I'm trying to switch from pdftk to qpdf https://www.harihareswara.net/posts/2022/pdftk-qpdf-and-dealing-with-password-protected-pdfs/. The specific problem I keep running into is page selection. I've read the relevant section of the documentation https://qpdf.readthedocs.io/en/stable/cli.html#page-selection and the section on page ranges https://qpdf.readthedocs.io/en/stable/cli.html#page-ranges several times but none of the examples are as simple as my use case:

Select pages 4-8 from |in.pdf| to create |out.pdf|

and I keep running into error messages as I try different permutations of the syntax.

So this is an example of the level of recipe some folks might need help with! Here's a cookbook of recipes for ffmpeg https://amiaopensource.github.io/ffmprovisr/ that could serve as another inspiration.

Thanks!

— Reply to this email directly, view it on GitHub https://github.com/qpdf/qpdf/issues/601#issuecomment-1371526536, or unsubscribe https://github.com/notifications/unsubscribe-auth/A47SB63SIFWSTZR266SGIKTWQX6XZANCNFSM5KYJ7TYQ. You are receiving this because you are subscribed to this thread.Message ID: @.***>

jberkenbilt commented 1 year ago

If someone would like to set up a snippets page or something, I am happy to contribute to it with questions. I think it's probably not something I'm likely to get around to anytime soon -- I don't really know what platform would be good for something like that.

Your command is correct. I don't have an explanation for the need for quotes around -- but I'm not a Windows user.

The issue with bookmarks is known, and I am about to start working on a long-standing enhancement to address it. --flatten-annotations will not have any impact on which bookmarks are present. At this time, all the bookmarks from the first file are present, and no other bookmarks are present.

In addition to the command you have, you could have given

I hope that helps. I know that people have trouble with --pages. I am hoping to provide much more flexibility on selecting pages, though it will probably require using a json file to specify.