Re: [NTG-context] OT: Pdf info

2011-07-20 Thread Taco Hoekwater


On 07/20/11 13:21, Procházka Lukáš Ing. - Pontex s. r. o. wrote:
 Hello,
 
 this question in not straightly related to Context, but Context users
 may have solved it and Ctx may be used to solve it.
 
 I would need to get the following information from .pdf file(s):
 
 - number of pages,
 - common width and height of pages (provided that they are the same;
 otherwise the dimension can be e.g. zero).

There is the macro \getfiguredimensions which, amongst other things,
sets up \noffigurepages, \figurewidth, and \figureheight.

Here is an excerpt from a macro I have been using since 'forever':

\newcount\imgcount % to store the number of pages

\unexpanded\def\addimage#1{%
  \getfiguredimensions[#1.pdf]%
  \imgcount=\noffigurepages\relax
  \dorecurse
  {\the\imgcount}
  {\getfiguredimensions[#1.pdf][page=\recurselevel]%
   \ifdim\figurewidth\figureheight
  ...
   \fi }}

Best wishes,
Taco
___
If your question is of interest to others as well, please add an entry to the 
Wiki!

maillist : ntg-context@ntg.nl / http://www.ntg.nl/mailman/listinfo/ntg-context
webpage  : http://www.pragma-ade.nl / http://tex.aanhet.net
archive  : http://foundry.supelec.fr/projects/contextrev/
wiki : http://contextgarden.net
___


Re: [NTG-context] OT: Pdf info

2011-07-20 Thread luigi scarso
2011/7/20 Procházka Lukáš Ing. - Pontex s. r. o. l...@pontex.cz:
 Hello,

 this question in not straightly related to Context, but Context users may
 have solved it and Ctx may be used to solve it.

 I would need to get the following information from .pdf file(s):

 - number of pages,
 - common width and height of pages (provided that they are the same;
 otherwise the dimension can be e.g. zero).

 The final goal is to use Ctx as a .pdf joining engine - to provide this, I
 need to know whether the .pdf to be inserted is portrait or landscape
 oriented, what is its size (so if to be scaled or not) etc.

 So Lua inside Ctx may be used to get the required .pdf info, if necessary.

 If an external program was used, it should be non-interactive (command-line
 oriented), free and working under Windows.

 Does anyone have any experience with such a task?
You can use some macros (see Taco), and for external programs
google for  mupdf and  xpdf

Tthe lua pdf library with mkiv should be also useful, but I've still
to play with it.


-- 
luigi
___
If your question is of interest to others as well, please add an entry to the 
Wiki!

maillist : ntg-context@ntg.nl / http://www.ntg.nl/mailman/listinfo/ntg-context
webpage  : http://www.pragma-ade.nl / http://tex.aanhet.net
archive  : http://foundry.supelec.fr/projects/contextrev/
wiki : http://contextgarden.net
___

Re: [NTG-context] OT: Pdf info

2011-07-20 Thread Hartmut Henkel
 2011/7/20 Procházka Lukáš Ing. - Pontex s. r. o. l...@pontex.cz:
  Hello,
 
  this question in not straightly related to Context, but Context users
 may
  have solved it and Ctx may be used to solve it.
 
  I would need to get the following information from .pdf file(s):
 
  - number of pages,
  - common width and height of pages (provided that they are the same;
  otherwise the dimension can be e.g. zero).
 
  The final goal is to use Ctx as a .pdf joining engine - to provide this,
 I
  need to know whether the .pdf to be inserted is portrait or landscape
  oriented, what is its size (so if to be scaled or not) etc.
 
  So Lua inside Ctx may be used to get the required .pdf info, if
 necessary.
 
  If an external program was used, it should be non-interactive
 (command-line
  oriented), free and working under Windows.
 
  Does anyone have any experience with such a task?
 You can use some macros (see Taco), and for external programs
 google for  mupdf and  xpdf
 
 Tthe lua pdf library with mkiv should be also useful, but I've still
 to play with it.

luatex's epdf library (= poppler Lua bindings, maybe that's what Luigi meant) 
allows to extract all this info from a pdf file, with a bit of Lua programming.

Regards, Hartmut
-- 
Empfehlen Sie GMX DSL Ihren Freunden und Bekannten und wir
belohnen Sie mit bis zu 50,- Euro! https://freundschaftswerbung.gmx.de
___
If your question is of interest to others as well, please add an entry to the 
Wiki!

maillist : ntg-context@ntg.nl / http://www.ntg.nl/mailman/listinfo/ntg-context
webpage  : http://www.pragma-ade.nl / http://tex.aanhet.net
archive  : http://foundry.supelec.fr/projects/contextrev/
wiki : http://contextgarden.net
___

Re: [NTG-context] OT: Pdf info

2011-07-20 Thread luigi scarso
On Wed, Jul 20, 2011 at 2:02 PM, Hartmut Henkel hartmut_hen...@gmx.de wrote:
 luatex's epdf library (= poppler Lua bindings, maybe that's what Luigi meant) 
 allows to extract all this info from a pdf file, with a bit of Lua 
 programming.
Yes, I meant the epdf library.


-- 
luigi
___
If your question is of interest to others as well, please add an entry to the 
Wiki!

maillist : ntg-context@ntg.nl / http://www.ntg.nl/mailman/listinfo/ntg-context
webpage  : http://www.pragma-ade.nl / http://tex.aanhet.net
archive  : http://foundry.supelec.fr/projects/contextrev/
wiki : http://contextgarden.net
___


Re: [NTG-context] OT: Pdf info

2011-07-20 Thread Procházka Lukáš Ing . - Pontex s . r . o .

On Wed, 20 Jul 2011 14:02:00 +0200, Hartmut Henkel hartmut_hen...@gmx.de 
wrote:


The lua pdf library with mkiv should be also useful, but I've still
to play with it.


luatex's epdf library (= poppler Lua bindings, maybe that's what Luigi meant) 
allows to extract all this info from a pdf file, with a bit of Lua programming.

Regards, Hartmut


Hello,

would you provide a minimal example - if it is possible in the Ctx or Lua 
scope? Something like:


\startluacode
  local info = SOMETHING.getInfo(File.pdf)

  local n = info.numPages
  local w = info.width
  local h = info.height
\stopluacode


Best regards,

Lukas

___
If your question is of interest to others as well, please add an entry to the 
Wiki!

maillist : ntg-context@ntg.nl / http://www.ntg.nl/mailman/listinfo/ntg-context
webpage  : http://www.pragma-ade.nl / http://tex.aanhet.net
archive  : http://foundry.supelec.fr/projects/contextrev/
wiki : http://contextgarden.net
___


Re: [NTG-context] OT: Pdf info

2011-07-20 Thread Hans Hagen

On 20-7-2011 2:02, Hartmut Henkel wrote:

2011/7/20 Procházka Lukáš Ing. - Pontex s. r. o.l...@pontex.cz:

Hello,

this question in not straightly related to Context, but Context users

may

have solved it and Ctx may be used to solve it.

I would need to get the following information from .pdf file(s):

- number of pages,
- common width and height of pages (provided that they are the same;
otherwise the dimension can be e.g. zero).

The final goal is to use Ctx as a .pdf joining engine - to provide this,

I

need to know whether the .pdf to be inserted is portrait or landscape
oriented, what is its size (so if to be scaled or not) etc.

So Lua inside Ctx may be used to get the required .pdf info, if

necessary.


If an external program was used, it should be non-interactive

(command-line

oriented), free and working under Windows.

Does anyone have any experience with such a task?

You can use some macros (see Taco), and for external programs
google for  mupdf and  xpdf

Tthe lua pdf library with mkiv should be also useful, but I've still
to play with it.


luatex's epdf library (= poppler Lua bindings, maybe that's what Luigi meant) 
allows to extract all this info from a pdf file, with a bit of Lua programming.


indeed (although we still need to fill in some gaps)

anyhow:

local MyDocument = lpdf.epdf.load(sometext.pdf)

context.starttext()

local pages= MyDocument.pages
local dummy= MyDocument.pages[1] -- we need lua 5.2 in order to 
avoid this


local nofpages = #MyDocument.pages

context.starttabulate { |c|c|c| }

context.NC() context(page)
context.NC() context(width)
context.NC() context(height) context.NR()

for i=1, nofpages do
local page = pages[i]
local bbox = page.CropBox or page.MediaBox
context.NC() context(i)
context.NC() context(bbox[4]-bbox[2])
context.NC() context(bbox[3]-bbox[1]) context.NR()
end

context.stoptabulate()

context.stoptext()



-
  Hans Hagen | PRAGMA ADE
  Ridderstraat 27 | 8061 GH Hasselt | The Netherlands
tel: 038 477 53 69 | voip: 087 875 68 74 | www.pragma-ade.com
 | www.pragma-pod.nl
-
___
If your question is of interest to others as well, please add an entry to the 
Wiki!

maillist : ntg-context@ntg.nl / http://www.ntg.nl/mailman/listinfo/ntg-context
webpage  : http://www.pragma-ade.nl / http://tex.aanhet.net
archive  : http://foundry.supelec.fr/projects/contextrev/
wiki : http://contextgarden.net
___

Re: [NTG-context] OT: Pdf info (solved)

2011-07-20 Thread Procházka Lukáš Ing . - Pontex s . r . o .

Hello,

On Wed, 20 Jul 2011 13:29:35 +0200, luigi scarso luigi.sca...@gmail.com wrote:


You can use some macros (see Taco), and for external programs
google for  mupdf and  xpdf


I installed Xpdf for Windows - http://gnuwin32.sourceforge.net/packages/xpdf.htm - and 
pdfinfo.exe does the job:


C:\Programs.Con\Gnu4Win\XPdf\binpdfinfo 
c:\Lukas\Jobs\Drachov.PDPS\SO_126\Texts\TZ#.pdf
Creator:pdftk 1.41 - www.pdftk.com
Producer:   itext-paulo-155 (itextpdf.sf.net-lowagie.com)
CreationDate:   05/18/11 17:15:13
ModDate:05/18/11 17:15:13
Tagged: no
Pages:  8
Encrypted:  no
Page size:  595 x 842 pts (A4)
File size:  119898 bytes
Optimized:  no
PDF version:1.4


Thanks all for their help.

Best regards,

Lukas


--
Ing. Lukáš Procházka [mailto:l...@pontex.cz]
Pontex s. r. o.  [mailto:pon...@pontex.cz] [http://www.pontex.cz]
Bezová 1658
147 14 Praha 4

Tel: +420 244 062 238
Fax: +420 244 461 038

___
If your question is of interest to others as well, please add an entry to the 
Wiki!

maillist : ntg-context@ntg.nl / http://www.ntg.nl/mailman/listinfo/ntg-context
webpage  : http://www.pragma-ade.nl / http://tex.aanhet.net
archive  : http://foundry.supelec.fr/projects/contextrev/
wiki : http://contextgarden.net
___


Re: [NTG-context] OT: Pdf info

2011-07-20 Thread Procházka Lukáš Ing . - Pontex s . r . o .

local MyDocument = lpdf.epdf.load(sometext.pdf)

context.starttext()

local pages= MyDocument.pages
local dummy= MyDocument.pages[1] -- we need lua 5.2 in order to
avoid this

local nofpages = #MyDocument.pages

context.starttabulate { |c|c|c| }

context.NC() context(page)
context.NC() context(width)
context.NC() context(height) context.NR()

for i=1, nofpages do
 local page = pages[i]
 local bbox = page.CropBox or page.MediaBox
 context.NC() context(i)
 context.NC() context(bbox[4]-bbox[2])
 context.NC() context(bbox[3]-bbox[1]) context.NR()
end

context.stoptabulate()

context.stoptext()


This code works perfectly, thank you Hans!

Best regards,

Lukas

___
If your question is of interest to others as well, please add an entry to the 
Wiki!

maillist : ntg-context@ntg.nl / http://www.ntg.nl/mailman/listinfo/ntg-context
webpage  : http://www.pragma-ade.nl / http://tex.aanhet.net
archive  : http://foundry.supelec.fr/projects/contextrev/
wiki : http://contextgarden.net
___