calculate all pagesizes in one job

Post Reply
w3gmbh
Newbie
Posts: 12
Joined: Mon Dec 16, 2013 4:14 pm

calculate all pagesizes in one job

Post by w3gmbh »

Hi,

I, trying to calculate all pagesizes of either
* a single multipage PDF
* a single onepage PDF
* a folder containing one or both of the above

then writing a log-file of all pages in ONE csv (using the job-folder name or in case of a single pdf just the nameproper of that pdf)

with only one single pdf it works using scripter, but only first page calculated:

Code: Select all

function jobArrived( s : Switch, job : Job )
{
	
	var outPath = s.getPropertyValue("LogPath")+"/";
	var jobName = job.getNameProper();
	
	if(job.isType("pdf")) {		

		//Get NumberOfPages
		pdfPages = job.getVariableAsNumber("[Stats.NumberOfPages]");
		s.log(2, 'Pages: '+pdfPages);
		
		//Get size of the pdf in mm
		pdfWidth = job.getVariableAsNumber("[Stats.PageWidth]") * 0.352778;
		pdfHeight = job.getVariableAsNumber("[Stats.PageHeight]") * 0.352778;
		pdfSqm = pdfWidth * pdfHeight / 1000000;
		s.log (2, 'Width: ' + pdfWidth);
		s.log (2, 'Height: ' + pdfHeight);
	}
	
	var f = new File(outPath+jobName+".csv");
	
	if (!f.exists && outPath != "") {
		s.log(2,"Neues Logfile wird angelegt: "+f.fullName);
		f.open(File.Append);
		f.writeLine("Name;Seite;Breite;Höhe;qm");
		f.close();
		}
	//Append to existing Logfile
	if (f.exists) {
		f.open(File.Append);
		f.writeLine(jobName+";1;"+pdfWidth+";"+pdfHeight+";"+pdfSqm);
		f.close();
		s.log(2,"Log-File: "+ f.fullName + " ergänzt");
	}
	else {
		s.log(2,"Datei existiert nicht: "+f.fullName);
	}


	job.sendToSingle(job.getPath()); // send to null
        return;
}
Im not sure how to proceed. Using dismantler or ungroup in advance, then split pdf to retain the original filename (for writing a csv)???
Writing the original filename in hierarchie? or in private data?

Example:

incoming Folder with 2 PDF files:
Foldername: MyJob
1. File: Multipage.pdf
2. File: Single Page.pdf

Output should then be MyJob.csv with following content (like in the code from above):

Name;Page;Width;Heigth;sqm
Multipage.pdf;1;210;297;0.0623
Multipage.pdf;2;297;420;0.12474
Single Page.pdf;1;2000;1800;3.6

thx in advance for any help

Ralf.
w3gmbh
Newbie
Posts: 12
Joined: Mon Dec 16, 2013 4:14 pm

Re: calculate all pagesizes in one job

Post by w3gmbh »

solved by myself using dismantler and hierarchy.
tdeschampsBluewest
Member
Posts: 37
Joined: Tue Jun 01, 2021 11:57 am

Re: calculate all pagesizes in one job

Post by tdeschampsBluewest »

Hi,
Is there a reason behind the legacy usage?
Dismantler

The documentation of scripting 2023 fall give a pretty nice example to loop trough PDF pages : https://www.enfocus.com/manuals/Develop ... thods.html


It will look like something :

Code: Select all

declare namespace types {
    type page = {
        index:number,
        width: number,
        height:number
    }
}
// Script that checks if all pages have identical page boxes
async function jobArrived(s: Switch, flowElement: FlowElement, job: Job) {
    const jobPath = await job.get(AccessLevel.ReadOnly);

    let pdfDoc: PdfDocument;
    try {

        // Open PDF file
        pdfDoc = PdfDocument.open(jobPath);
        const numPages: number = pdfDoc.getNumberOfPages();
        const pdfDimensions:types.page[] = []

        // Go over all the pages
        for (let i = 0; i < numPages; i++) {
            const index = i+1
            const pdfPage = pdfDoc.getPage(index);
            pdfDimensions.push({
                index: index,
                width: pdfPage.getTrimBoxHeight(false),
                height:pdfPage.getTrimBoxWidth(false)
            })
        }

    // Close the PDF document
        pdfDoc.close();
        pdfDoc = null;


    // Do something with the array with something like https://www.npmjs.com/package/csvtojson

    } catch (err) {
        job.fail("PDF error: %1", [err]);
        if (pdfDoc) {
            pdfDoc.close();
        }
    }
You could also check the app CSV creator to build CSV on the fly : https://www.enfocus.com/en/appstore/product/csvcreator
Post Reply