Return-Path: X-Original-To: apmail-pdfbox-users-archive@www.apache.org Delivered-To: apmail-pdfbox-users-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 3CE0B185A0 for ; Wed, 11 Nov 2015 05:38:04 +0000 (UTC) Received: (qmail 49594 invoked by uid 500); 11 Nov 2015 05:38:03 -0000 Delivered-To: apmail-pdfbox-users-archive@pdfbox.apache.org Received: (qmail 49572 invoked by uid 500); 11 Nov 2015 05:38:03 -0000 Mailing-List: contact users-help@pdfbox.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: users@pdfbox.apache.org Delivered-To: mailing list users@pdfbox.apache.org Received: (qmail 49555 invoked by uid 99); 11 Nov 2015 05:38:03 -0000 Received: from Unknown (HELO spamd4-us-west.apache.org) (209.188.14.142) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 11 Nov 2015 05:38:03 +0000 Received: from localhost (localhost [127.0.0.1]) by spamd4-us-west.apache.org (ASF Mail Server at spamd4-us-west.apache.org) with ESMTP id 10B33C0FBE for ; Wed, 11 Nov 2015 05:38:03 +0000 (UTC) X-Virus-Scanned: Debian amavisd-new at spamd4-us-west.apache.org X-Spam-Flag: NO X-Spam-Score: 2.879 X-Spam-Level: ** X-Spam-Status: No, score=2.879 tagged_above=-999 required=6.31 tests=[DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, HTML_MESSAGE=3, RCVD_IN_MSPIKE_H3=-0.01, RCVD_IN_MSPIKE_WL=-0.01, SPF_PASS=-0.001] autolearn=disabled Authentication-Results: spamd4-us-west.apache.org (amavisd-new); dkim=pass (2048-bit key) header.d=gmail.com Received: from mx1-eu-west.apache.org ([10.40.0.8]) by localhost (spamd4-us-west.apache.org [10.40.0.11]) (amavisd-new, port 10024) with ESMTP id fkdLKzwXnOc0 for ; Wed, 11 Nov 2015 05:38:01 +0000 (UTC) Received: from mail-oi0-f41.google.com (mail-oi0-f41.google.com [209.85.218.41]) by mx1-eu-west.apache.org (ASF Mail Server at mx1-eu-west.apache.org) with ESMTPS id C69A120D14 for ; Wed, 11 Nov 2015 05:38:00 +0000 (UTC) Received: by oiad129 with SMTP id d129so10891688oia.0 for ; Tue, 10 Nov 2015 21:37:59 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:reply-to:in-reply-to:references:date:message-id :subject:from:to:content-type; bh=kDuNeY/B8IcwDRJDgN0LW+wGkyKyCax9iuP0uypPAsY=; b=WSTg5EbofGo9o5oZQB1TZtrax+kWouP81NFBo6Tio/KvrXuhfBCx6miHdA92WxL6+a Pia8Y3SdYfm+Z0EqhFLrqlcuN50cAO3y8G7FdHD5tZAi2OCm0KHPW5tzOPyHXOfF79ZX i/vyOMQXpREd0s8ldh6pYwDn64uwacCrCpRZKafz5S588PczpJe2ff6N81VLD8jhY8xW QYh790wRaIwfzKVxH9R3fgWs63/AQR8IAf3BQBqUYUaNlQ5S2aBLDDgOk8B+VvyJsOFg Y1GCxDSpuDgCPEccEwbouH7tNxY9J0MhVuPYlRU7R6xgQnUwPzxb0N0vf3zw1MIZzfHR xhpw== MIME-Version: 1.0 X-Received: by 10.202.98.2 with SMTP id w2mr3434192oib.106.1447220279663; Tue, 10 Nov 2015 21:37:59 -0800 (PST) Received: by 10.202.180.84 with HTTP; Tue, 10 Nov 2015 21:37:59 -0800 (PST) Reply-To: nasir.rasul@gmail.com In-Reply-To: References: Date: Tue, 10 Nov 2015 21:37:59 -0800 Message-ID: Subject: Re: Trying to get rotate to work From: Nasir Rasul To: users@pdfbox.apache.org Content-Type: multipart/alternative; boundary=001a113d3988ae612905243d3a17 --001a113d3988ae612905243d3a17 Content-Type: text/plain; charset=UTF-8 Hi Ronald, You are declaring >private static final String pdfFile = null; Subsequently, >File f = new File(pdfFile); In between you need to initialize pdfFile with a value. At this point, pdfFile is null. It has never been assigned a value Cheers Nasir - Nasir On Tue, Nov 10, 2015 at 6:27 PM, Ronald DERAMUS wrote: > Hi all, > I'm new to this list and to java. I was wondering if anyone has a good > working example of the rotate page feature? I haven't found a good example > and I am trying to rotate a whole pdf page and save it.. I have the > following code but it doesn't seem to work... I'm having a hard time > getting rid of the NullPointer error. > > Here is my code: > > //import java.awt.List; > import java.util.List; > import java.io.File; > import java.io.FileInputStream; > import java.io.IOException; > > import org.apache.pdfbox.cos.COSDocument; > import org.apache.pdfbox.exceptions.COSVisitorException; > import org.apache.pdfbox.pdfparser.PDFParser; > import org.apache.pdfbox.pdmodel.PDDocument; > import org.apache.pdfbox.pdmodel.PDPage; > > > public class PdfRotator { > > > private static final String pdfFile = null; > > public static void main(String[] args) throws IOException { > > PDDocument document = PDDocument.load("PDFrotatorTEST.pdf"); > > > > //public static void main(String[] args) throws Exception { > > List pages = (List) document.getDocumentCatalog().getAllPages(); > > for (int i = 0; i < pages.size(); i++) { > PDPage page = (PDPage) ((java.util.List) pages).get(i);// PDPage > page = (PDPage) pages.get(i); > if ((i + 1) % 2 == 0) { > page.setRotation(0); > } > } > > File f = new File(pdfFile);// File f = new File(pdfFile); > String newFile = f.getParent() + File.separator + "out.pdf"; > try { > document.save(newFile); > } catch (COSVisitorException e) { > // TODO Auto-generated catch block > e.printStackTrace(); > } > document.close(); > } > } > > Errors: > Exception in thread "main" java.lang.NullPointerException > at java.io.File.(Unknown Source) > at PdfRotator.main(PdfRotator.java:36) > --001a113d3988ae612905243d3a17--