alex_dudu
Messages postés1Date d'inscriptionlundi 21 février 2005StatutMembreDernière intervention12 mars 2008
-
12 mars 2008 à 18:34
cs_simomami
Messages postés1Date d'inscriptionjeudi 2 décembre 2004StatutMembreDernière intervention 7 juin 2009
-
7 juin 2009 à 22:42
Bonjour à tous,
nous vous postons ce message pour solliciter votre aide sur l'utilisation de la bibliothèque PDF Renderer.
Le code source suivant est censé nous permettre de convertir un fichier PDF en une série d'images au format .png. Le problème est que la conversion réalisée ici déforme partiellement certains documents (caractères qui se chevauchent ou images pixellisées).
// draw the first page to an image
int num = pdffile.getNumPages();
for(int i = 1 ; i <= num ; i++)
{
PDFPage page = pdffile.getPage(i);
//get the width and height for the doc at the default zoom
int width=(int)page.getBBox().getWidth();
System.out.println(width);
int height=(int)page.getBBox().getHeight();
System.out.println(height);
Rectangle rect = new Rectangle(0,0,width,height);
int rotation = page.getRotation();
Rectangle rect1=rect; if(rotation 90 || rotation 270)
rect1 = new Rectangle(0, 0, rect.height, rect.width);
//generate the image
BufferedImage img = (BufferedImage)page.getImage(
rect.width, rect.height, //width & height
rect1, // clip rect
null, // null for the ImageObserver
true, // fill background with white
true // block until drawing is done
);
ImageIO.write(img, "png", new File("C:/Documents and Settings/srun/Bureau/Nouveaudossier/pdf"+i+".png"));
System.out.println("Image "+ i+ " enregistrer");
cs_simomami
Messages postés1Date d'inscriptionjeudi 2 décembre 2004StatutMembreDernière intervention 7 juin 2009 7 juin 2009 à 22:42
je pense que le fait d'augmenter la résolution de l'image généré peut résoudre le probléme, par exemple le doubler,
remplacer :
BufferedImage img = (BufferedImage)page.getImage(
rect.width, rect.height, //width & height
rect1, // clip rect
null, // null for the ImageObserver
true, // fill background with white
true // block until drawing is done
);
par
BufferedImage img = (BufferedImage)page.getImage(
2*rect.width, 2*rect.height, //width & height
rect1, // clip rect
null, // null for the ImageObserver
true, // fill background with white
true // block until drawing is done
);