Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

How to print horizonal by using a java script ?

New Here ,
Feb 15, 2021 Feb 15, 2021

Hello together,

I need to print my PDF Document via JavaScript. 

These are my printParams which I use and which works very well:

              pp.interactive = pp.constants.interactionLevel.silent;
              pp.firstPage = 0;
              pp.lastPage = 0;
              pp.pageHandling = pp.constants.handling.fit;
              pp.nUpAutoRotate = true;

Is there any possible Java Code which makes it possible to rotate my print page from vertical to horizonal? 

I tried everything could you please help me?

Best regards

TOPICS
Acrobat SDK and JavaScript
1.4K
Translate
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

Community Expert , Feb 23, 2021 Feb 23, 2021

OK, pretty much everything there is wrong.

Use this code:

 

this.setPageRotations(0,0,90);

this.print({
	bUI:true,
	nStart:0,
	nEnd:0,
	bShrinkToFit:true
});
Translate
LEGEND ,
Feb 17, 2021 Feb 17, 2021

See the setPageRotations parameter explained below:

 

nRotate (optional) The amount of rotation that should be applied to the target pages. Can be 0, 90, 180, or 270. The default is 0. Example Rotate pages 0 through 10 of the current document.

 

this.setPageRotations(0, 10, 90); 

 

You can read more about it in the Adobe Acrobat SDK JavaScript API JavaScript for Acrobat API Reference, setPageTabOrder, page 342

Translate
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 ,
Feb 23, 2021 Feb 23, 2021

Hello,

thanks for yout idea. I tried your code and different variations of it but it doesnt work. I will show you what I have done. I run the following script:

this.print({
bUI:true,
nStart:0,
nEnd:0,
bShrinkToFit:true
setPageRotations:(0,10,90)
})

but the print option(look at my screenshot) does not switch to horizontal (yellow marked area). I need to turn ON the yellow marked option by javascript.

Thankyou and Best regards

Translate
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
Community Expert ,
Feb 23, 2021 Feb 23, 2021

setPageRotations has nothing to do with the print command. It's its own command to rotate the pages.

You should use the code provided by ls_rbls, before calling the print command (and after, if you want to rotate the pages back to their original views).

Translate
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 ,
Feb 23, 2021 Feb 23, 2021

Okay thanks, I tried to do it befor printing, but it also doesnt work.

Thats my code:

//___________________________________first run
this.setPageRotations(0, 10, 90); 

TypeError: Ungültiger Argumenttyp.
Doc.setPageRotations:1:Console undefined:Exec
 ===> Parameter nEnd.
undefined

//__________________________________second run

nStart:0;
nEnd:0;
setPageRotations:(0,10,90);

 

Translate
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
Community Expert ,
Feb 23, 2021 Feb 23, 2021

How many pages are there in your file?

Translate
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 ,
Feb 23, 2021 Feb 23, 2021

9 Pages , I tried also (0,9,90).

Translate
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
Community Expert ,
Feb 23, 2021 Feb 23, 2021

Page numbers in JS are zero-based, so use 8, not 9.

Translate
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 ,
Feb 23, 2021 Feb 23, 2021

Yes in JS it is zero based, right. I also tried to use 8 not 9.

But same it does not work.

Its very frustrating because its an easy requirement in my opinion. :(((

Translate
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
Community Expert ,
Feb 23, 2021 Feb 23, 2021

Post your exact code and the error message you're getting.

Translate
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 ,
Feb 23, 2021 Feb 23, 2021

In the picture bellow you can see

-my test page

-exact code

-message after executing the code (yellow marked) no error

Thanks!!

Translate
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
Community Expert ,
Feb 23, 2021 Feb 23, 2021

OK, pretty much everything there is wrong.

Use this code:

 

this.setPageRotations(0,0,90);

this.print({
	bUI:true,
	nStart:0,
	nEnd:0,
	bShrinkToFit:true
});
Translate
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
Community Expert ,
Feb 23, 2021 Feb 23, 2021
LATEST

And if you want it to work with a file of any length, use this:

 

 

this.setPageRotations(0,this.numPages-1,90);

this.print({
	bUI:true,
	nStart:0,
	nEnd:this.numPages-1,
	bShrinkToFit:true
});

 

Translate
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