Return-Path: X-Original-To: apmail-pdfbox-dev-archive@www.apache.org Delivered-To: apmail-pdfbox-dev-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 2B0C99883 for ; Mon, 21 May 2012 04:59:42 +0000 (UTC) Received: (qmail 80299 invoked by uid 500); 21 May 2012 04:59:42 -0000 Delivered-To: apmail-pdfbox-dev-archive@pdfbox.apache.org Received: (qmail 80251 invoked by uid 500); 21 May 2012 04:59:41 -0000 Mailing-List: contact dev-help@pdfbox.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@pdfbox.apache.org Delivered-To: mailing list dev@pdfbox.apache.org Received: (qmail 80228 invoked by uid 99); 21 May 2012 04:59:41 -0000 Received: from issues-vm.apache.org (HELO issues-vm) (140.211.11.160) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 21 May 2012 04:59:41 +0000 Received: from isssues-vm.apache.org (localhost [127.0.0.1]) by issues-vm (Postfix) with ESMTP id E59E114280B for ; Mon, 21 May 2012 04:59:40 +0000 (UTC) Date: Mon, 21 May 2012 04:59:40 +0000 (UTC) From: =?utf-8?Q?Andreas_Lehmk=C3=BChler_=28JIRA=29?= To: dev@pdfbox.apache.org Message-ID: <529692246.2399.1337576380942.JavaMail.jiratomcat@issues-vm> In-Reply-To: <634444862.1255.1330486948883.JavaMail.tomcat@hel.zones.apache.org> Subject: [jira] [Closed] (PDFBOX-1240) Extract Images from PDF file using PDFBox in C# MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-JIRA-FingerPrint: 30527f35849b9dde25b450d4833f0394 [ https://issues.apache.org/jira/browse/PDFBOX-1240?page=3Dcom.atlassi= an.jira.plugin.system.issuetabpanels:all-tabpanel ] Andreas Lehmk=C3=BChler closed PDFBOX-1240. -------------------------------------- Resolution: Not A Problem Assignee: Andreas Lehmk=C3=BChler Thanks for coming back! Set to closed =20 > Extract Images from PDF file using PDFBox in C# > ----------------------------------------------- > > Key: PDFBOX-1240 > URL: https://issues.apache.org/jira/browse/PDFBOX-1240 > Project: PDFBox > Issue Type: New Feature > Components: Utilities > Affects Versions: 0.7.3 > Reporter: Pham Minh Cuong > Assignee: Andreas Lehmk=C3=BChler > Priority: Minor > Original Estimate: 168h > Remaining Estimate: 168h > > public class ExtractImage > { > private int imageCounter =3D 1; > private static string PASSWORD =3D "-password"; > private static string PREFIX =3D "-prefix"; > public ExtractImage() > { > } > public void extractImage(string []args) > { > if(args.Length<1||args.Length>4) > { > usage(); > } > else > { > string pdfFile =3D ""; > string password =3D ""; > string prefix =3D null; > for (int i =3D 0; i < args.Length; i++) > { > if(args[i]=3D=3DPASSWORD) > { > i++; > if (i >=3D args.Length) > { > usage(); > } > password =3D args[i]; > } > else if (args[i]=3D=3DPREFIX) > { > i++; > if(i>=3Dargs.Length) > { > usage(); > } > prefix =3D args[i]; > } > else > { > if(pdfFile=3D=3Dnull) > { > pdfFile =3D args[i]; > } > } > } > if(pdfFile=3D=3Dnull) > { > usage(); > } > else > { > if(prefix=3D=3Dnull && pdfFile.Length>4) > { > prefix =3D pdfFile.Substring(0, pdfFile.Length - = 4); > } > PDDocument document=3Dnull; > try > { > document =3D PDDocument.load(pdfFile); > if( document.isEncrypted() ) > { > =20 > StandardDecryptionMaterial spm =3D new Standa= rdDecryptionMaterial(password); > document.openProtection(spm); > AccessPermission ap =3D document.getCurrentAc= cessPermission(); > =20 > =20 > if( ! ap.canExtractContent() ) > { > Console.WriteLine("Error: You do not = have permission to extract images." ); > } > } > =20 > List pages =3D document.getDocumentCatalog().ge= tAllPages(); > java.util.Iterator iter =3D pages.iterator(); > while( iter.hasNext() ) > { > PDPage page =3D (PDPage)iter.next(); > PDResources resources =3D page.getResources()= ; > java.util.Map images =3D resources.getImage= s(); > if( images !=3D null ) > { > Iterator imageIter =3D images.keySet().= iterator(); > while( imageIter.hasNext() ) > { > string key =3D (String )imageIter.= next(); > PDXObjectImage image =3D (PDXObjectIm= age)images.get( key ); > string name =3D getUniqueFileName( = key, image.getSuffix() ); > Console.WriteLine( "Writing image:" += name ); > image.write2file( name ); > } > } > } > } > catch (Exception) > { > =20 > throw; > } > } > } > } > private string getUniqueFileName(string prefix, string suffix) > { > string uniqueName =3D null; > java.io.File f =3D null; > f =3D null; > while (f =3D=3D null || f.exists()) > { > uniqueName =3D prefix + "-" + imageCounter; > f =3Dnew File(uniqueName + "." + suffix); > imageCounter++; > } > return uniqueName; > } > private void usage() > { > Console.Error.WriteLine("Usage: java org.pdfbox.ExtractImages= [OPTIONS] \n" + > " -password Password to de= crypt document\n" + > " -prefix Image prefix= (default to pdf name)\n" + > " The PDF document to use\= n"); > Environment.Exit(1); > } > } > Reference: http://svn.apache.org/repos/asf/pdfbox/trunk/pdfbox/src/main/j= ava/org/apache/pdfbox/ExtractImages.java=20 > I tested but i have a problem.It ran if(args.Length<1||args.Length>4) an= d stopped in usage().It loop.Please help me.Many thanks. > { > usage(); > } -- This message is automatically generated by JIRA. If you think it was sent incorrectly, please contact your JIRA administrato= rs: https://issues.apache.org/jira/secure/ContactAdministrators!default.jsp= a For more information on JIRA, see: http://www.atlassian.com/software/jira