IMPORTANT ANNOUNCEMENT

These forums were permanently set to read-only mode on July 20, 2022. From that day onwards, no new posting or comment is allowed on the site, but the historical content remains intact and searchable.

A new location for posting questions about PlanetPress Suite is now available:

OL Learn - PlanetPress Classic (opens in new tab)

Topic Options
#38286 - 01/17/12 02:15 PM Alambic help
ricks Offline
OL Guru

Registered: 04/17/10
Posts: 101
Loc: Seattle
I'm trying to use vbscript and the AlambicEdit resource to find out the size of the page. I have some code that works at finding rotated (landscape) pages, and flipping them around. That is below. Can anyone clarify how to use the HRESULT IPage::MediaSize ( IPdfRect ** retVal ) command or something else to determine the size of the page? I will save the output of that command in a text file during processing so that I know which PDF files can can print on letter vs. legal stock. Thanks for any ideas or code examples.

MyPDF.Open Watch.GetJobFileName, False
dim pgs : pgs = MyPDF.Pages.Count
For x = 1 to pgs

iRot = MyPDF.Pages.Item(x-1).Orientation

if (iRot = 90) then
nRot = 0
MyPDF.Pages.Item(x-1).Orientation = nRot

MyPDF.Save(true)
end if

Next

Top
#38287 - 01/17/12 03:39 PM Re: Alambic help [Re: ricks]
Benoit Potvin
Unregistered


Hi,

Here is a VB script I have written 3 weeks ago to print a letter-sized multipage PDF in 2-up fashion over a 11x17 landscape page, with telescoping.

Look at how pdfRect is instanciated for an example use of the IPDFrect structure.

Code:
dim MyPDF, NewPDF, NewPDF_PageCount, pdfRect, i

'MyPDF is the PDF with documents we want to impose 2-up with telescoping on 11x17 paper.
'MyPDF is the current Job
Set MyPDF = Watch.GetPDFEditObject
MyPDF.Open Watch.GetJobFileName(), false

'NewPDF is the pdf on which MyPDF is to be imposed 2-up
Set NewPDF = Watch.GetPDFEditObject
NewPDF.Create Watch.GetJobFileName()

'NewPDF_PageCount is the theoretical page count of NewPDF
NewPDF_PageCount = round(MyPDF.Pages.Count/2)
if(NewPDF_PageCount < MyPDF.Pages.Count/2) Then
   NewPDF_PageCount = NewPDF_PageCount + 1
End if

'pdfRect is used in the creation of the destination pages, which is 11x17, landscape
set pdfRect = CreateObject("AlambicEdit.PdfRect")
pdfRect.left = 0
pdfRect.top = 792
pdfRect.right = 1224
pdfRect.bottom = 0

For i = 0 to (NewPDF_PageCount-1)
 'add the the 11x17 landscape page
  NewPDF.Pages.Insert i, pdfRect
  'merge it with 2 pages from MyPDF
  NewPDF.Pages.Item(i).Merge2 MyPDF.Pages.Item(i), 0.0, 0.0, 0.0, 1.0
  if ((i + NewPDF_PageCount) < MyPDF.Pages.Count) then
      NewPDF.Pages.Item(i).Merge2 MyPDF.Pages.Item(i+NewPDF_PageCount), 612.0, 0.0, 0.0, 1.0
  end if
Next

MyPDF.Close
NewPDF.Save False




Hope this helps!


Ben

Top
#38301 - 01/18/12 01:01 PM Re: Alambic help [Re: ]
ricks Offline
OL Guru

Registered: 04/17/10
Posts: 101
Loc: Seattle
Ben, Thank you for your code example. I'm sorry though I'm still confused.

I see how pdfRect is instanciated and your code works fine with my pdf's in testing, but I don't want to create a new page.

I want to get the size of existing pages within the PDF file I'm looking at. I'm trying to use these commands:

HRESULT MediaSize (IPdfRect **retVal)
HRESULT Size (IPdfRect **retVal)

which seem to tell me they can be used to determine the size of the PDF but how to use this to get there is not clear for my brain.

I did this:
set pdfRect = CreateObject("AlambicEdit.PdfRect")

Then in the loop I do all of the following attempts and they all fail? What do I need to do to determine the page size (mediasize) and crop size (size)?

pdfMB = MyPDF.Pages.Item(x-1).MediaSize(pdfRect)
pdfMB = MyPDF.Pages.Item(x-1).MediaSize
pdfMB = MyPDF.Pages.Item(x-1).MediaSize, 0, 0, 0, 0

Top
#38304 - 01/18/12 02:50 PM Re: Alambic help [Re: ricks]
Yannick Fortin Offline
OL Expert

Registered: 08/25/00
Posts: 354
Loc: Objectif Lune Montréal
The API documentation is generated from the original C++ source code and therefore canoot be used 100% as-is in script. To get the page size in VBScript, you would write

set pdfRect = CreateObject("AlambicEdit.PdfRect")
pdfRect = MyPDF.Pages.Item(x-1).MediaSize

The "**retVal" in the method definition indicates that this parameter is the actual the return value for the function. The HRESULT return value is just COM housekeeping and is not used in script.
_________________________
Yannick Fortin, Team OL

Top
#38307 - 01/18/12 10:02 PM Re: Alambic help [Re: Yannick Fortin]
ricks Offline
OL Guru

Registered: 04/17/10
Posts: 101
Loc: Seattle
So here is my code at the start of looping through all the pages in a given PDF file:

set pdfRect = CreateObject("AlambicEdit.PdfRect")
For x = 1 to pgs
iRot = MyPDF.Pages.Item(x-1).Orientation
pdfRect = MyPDF.Pages.Item(x-1).MediaSize

And I get this in the log files:

ERROR: W3602 : Error 0 on line 54, column 3: Microsoft VBScript runtime error: Object doesn't support this property or method: 'pdfRect'
ERROR: W3603 : Error running script.
ERROR: Run Script: W1603 : Plugin failed - 18:57:33

Top
#38308 - 01/18/12 11:37 PM Re: Alambic help [Re: ricks]
Yannick Fortin Offline
OL Expert

Registered: 08/25/00
Posts: 354
Loc: Objectif Lune Montréal
The pdfRect variable is an object, so you need to make the assignment using the set operator.

set pdfRect = MyPDF.Pages.Item(x-1).MediaSize
_________________________
Yannick Fortin, Team OL

Top
#38317 - 01/19/12 06:51 PM Re: Alambic help [Re: Yannick Fortin]
ricks Offline
OL Guru

Registered: 04/17/10
Posts: 101
Loc: Seattle
Thanks to all. I got this working. It finally dawned on me that I needed to capture the size using some code like below:


outFile.WriteLine(Cstr(pdfRect.top))

The info is right there.

Top