Welcome Dialog

Welcome to the Community!

We have a brand new look! Take a tour with us and explore the latest updates on Adobe Support Community.


[Javascript] Export page to PDF = "Data is out of range." Error 30481.

New Here ,
Aug 14, 2021 Aug 14, 2021

Copy link to clipboard

Copied

Hello to all,

Being a complete beginner in Javascript, I don't understand how to solve my problem and call you specialists.
I want to export the active page in PDF 150 dpi RGB without bleed.
I found a script in an old Adobe doc and I systematically get an error message 30481 "Data out of range" when I run it.

Thank you very much to those who can help me!
(This is my very first post, I hope to get it right. 😊)

with(app.pdfExportPreferences){

//Basic PDF output options.
	pageRange = app.activeDocument.layoutWindows[0].activePage.name  
	acrobatCompatibility = AcrobatCompatibility.acrobat6; 
	exportGuidesAndGrids = false; 
	exportLayers = false; 
	exportNonPrintingObjects = false; 
	exportReaderSpreads = false; 
	generateThumbnails = false; 
	try{ 
		ignoreSpreadOverrides = false; 
	} 
	catch(e){} 
	includeBookmarks = false; 
	includeHyperlinks = true; 
	includeICCProfiles = false; 
	includeSlugWithPDF = false; 
	includeStructure = false; 
	interactiveElementsOption = InteractiveElementsOptions.doNotInclude; 
	//Setting subsetFontsBelow to zero disallows font subsetting; 
	//set subsetFontsBelow to some other value to use font subsetting. 
	subsetFontsBelow = 100; 

	//Bitmap compression/sampling/quality options.
	colorBitmapCompression = BitmapCompression.jpeg; 
	colorBitmapQuality = CompressionQuality.maximum; 
  	thresholdToCompressColor = 150;
	colorBitmapSampling = Sampling.BICUBIC_DOWNSAMPLE;
	colorBitmapSamplingDPI = 150  
	//thresholdToCompressColor is not needed in this example. 
	//colorBitmapSamplingDPI is not needed when colorBitmapSampling is set to none.
	grayscaleBitmapCompression = BitmapCompression.jpeg; 
	grayscaleBitmapQuality = CompressionQuality.maximum; 
	thresholdToCompressGray = 150;
	grayscaleBitmapSampling = Sampling.BICUBIC_DOWNSAMPLE;
	grayscaleBitmapSamplingDPI = 150;  
	//thresholdToCompressGray is not needed in this example. 
	//grayscaleBitmapSamplingDPI is not needed when grayscaleBitmapSampling 
	//is set to none.
	monochromeBitmapCompression = MonoBitmapCompression.CCIT4; 
	thresholdToCompressMonochrome = 600;
	monochromeBitmapSampling = Sampling.BICUBIC_DOWNSAMPLE;
	monochromeBitmapSamplingDPI = 300  
	//thresholdToCompressMonochrome is not needed in this example. 
	//monochromeBitmapSamplingDPI is not needed when 
	//monochromeBitmapSampling is set to none.
	 
	//Other compression options.
	compressionType = PDFCompressionType.compressNone; 
	compressTextAndLineArt = true; 
	cropImagesToFrames = true; 
	optimizePDF = true; 

	//Printers marks and prepress options.
	//Get the bleed amounts from the document's bleed.
    bleedBottom = 0;  
    bleedTop = 0;  
    bleedInside = 0;  
    bleedOutside = 0;  
	//If any bleed area is greater than zero, then export the bleed marks. 
	if(bleedBottom == 0 && bleedTop == 0 && bleedInside == 0 && bleedOutside == 0){
		bleedMarks = false; 
		} 
		else{
			bleedMarks = false; 
		} 
		colorBars = false; 
		colorTileSize = 128; 
		grayTileSize = 128; 
		cropMarks = false; 
		omitBitmaps = false; 
		omitEPS = false; 
		omitPDF = false; 
		pageInformationMarks = false; 
		pageMarksOffset = 0; 
		pdfColorSpace = PDFColorSpace.RGB; 
		//Default mark type.
		pdfMarkType = 1147563124;
		printerMarkWeight = PDFMarkWeight.p125pt; 
		registrationMarks = false; 
		try{ 
			simulateOverprint = false; 
		} 
		catch(e){} 
		useDocumentBleedWithPDF = false; 
		//Set viewPDF to true to open the PDF in Acrobat or Adobe Reader. 
		viewPDF = false;
	} 
	//Now export the document. You'll have to fill in your own file path.
	var parentfolder = app.activeDocument.fullName.parent;
	var basename = app.activeDocument.name.replace(/\.indd$/, "");
app.activeDocument.exportFile(ExportFormat.pdfType, new File(parentfolder + "/" + basename + ".pdf"), false);

 

TOPICS
Import and export, Scripting

Views

35

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Adobe Community Professional , Aug 16, 2021 Aug 16, 2021
Hi cn73827803, there are conditions where pageRange will fail in your code. E.g. if your active page is a master page. Perhaps also if you have alternate layouts in your document and the pure name of a page is not enough to denote a page. If there are other issues with your code, I don't know. Did not test. Will it work if you exchange this line of code: pageRange = app.activeDocument.layoutWindows[0].activePage.name with: pageRange = "+"+(app.activeDocument.layoutWindows[0].activePage.documen...

Likes

Translate

Translate
Adobe Community Professional ,
Aug 16, 2021 Aug 16, 2021

Copy link to clipboard

Copied

Hi cn73827803,

there are conditions where pageRange will fail in your code.

E.g. if your active page is a master page. Perhaps also if you have alternate layouts in your document and the pure name of a page is not enough to denote a page. If there are other issues with your code, I don't know. Did not test.

 

Will it work if you exchange this line of code:

pageRange = app.activeDocument.layoutWindows[0].activePage.name

with:

pageRange = "+"+(app.activeDocument.layoutWindows[0].activePage.documentOffset + 1);

which assigns an "absolute page number" to property pageRange. Which is always unique for your document regardless if there are alternate layouts or section suffixes etc.pp.

 

Run both lines of code, not the whole code, on your open document to test and alert( pageRange ) in a second line.

 

Regards,
Uwe Laubender

( ACP )

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Aug 16, 2021 Aug 16, 2021

Copy link to clipboard

Copied

Hello Laubender and BarlaeDC,
So I don't really know why but when I copy the code of this post and paste it to retry, the error doesn't occur anymore! Was it a character encoding problem?

So with

pageRange = app.activeDocument.layoutWindows[0].activePage.name

it works and I tested with the line

pageRange = "+"+(app.activeDocument.layoutWindows[0].activePage.documentOffset + 1);

it works too! (test on page 2, result: +2)
Anyway thanks a lot Laubender, you taught me the syntax for the absolute position of a page 😊

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Aug 16, 2021 Aug 16, 2021

Copy link to clipboard

Copied

LATEST

And thank you BarlaeDC also for taking the time to look into my problem 😊

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe Community Professional ,
Aug 16, 2021 Aug 16, 2021

Copy link to clipboard

Copied

Hi,

 

Running on the latest InDesign, it works as expected for me. are you able to provide the document that you are working with?

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines