La conversion de PDF en tiff multipage (Groupe 4)

Je suis en train de convertir des Pdf en fichiers représenté par le org.apache.pdfbox.pdmodel.PDDocument classe et la icafe bibliothèque (https://github.com/dragon66/icafe/) à un tiff de plusieurs pages avec le groupe 4 de la compression et de 300 dpi. L'exemple de code qui fonctionne pour moi pour 288 ppp, mais, curieusement, PAS pour 300 dpi, de l'export tiff reste tout blanc. Personne n'a une idée de ce que la question est ici?

L'exemple de fichier pdf que j'utilise dans l'exemple se trouve ici: http://www.bergophil.ch/a.pdf

import java.awt.image.BufferedImage;
import java.io.FileOutputStream;
import java.io.IOException;
import org.apache.pdfbox.pdmodel.PDDocument;
import org.apache.pdfbox.pdmodel.PDPage;
import cafe.image.ImageColorType;
import cafe.image.ImageParam;
import cafe.image.options.TIFFOptions;
import cafe.image.tiff.TIFFTweaker;
import cafe.image.tiff.TiffFieldEnum.Compression;
import cafe.io.FileCacheRandomAccessOutputStream;
import cafe.io.RandomAccessOutputStream;
public class Pdf2TiffConverter {
public static void main(String[] args) {
String pdf = "a.pdf";
PDDocument pddoc = null;
try {
pddoc = PDDocument.load(pdf);
} catch (IOException e) {
}
try {
savePdfAsTiff(pddoc);
} catch (IOException e) {
}
}
private static void savePdfAsTiff(PDDocument pdf) throws IOException {
BufferedImage[] images = new BufferedImage[pdf.getNumberOfPages()];
for (int i = 0; i < images.length; i++) {
PDPage page = (PDPage) pdf.getDocumentCatalog().getAllPages()
.get(i);
BufferedImage image;
try {
//             image = page.convertToImage(BufferedImage.TYPE_INT_RGB, 288); //works
image = page.convertToImage(BufferedImage.TYPE_INT_RGB, 300); //does not work
images[i] = image;
} catch (IOException e) {
e.printStackTrace();
}
}
FileOutputStream fos = new FileOutputStream("a.tiff");
RandomAccessOutputStream rout = new FileCacheRandomAccessOutputStream(
fos);
ImageParam.ImageParamBuilder builder = ImageParam.getBuilder();
ImageParam[] param = new ImageParam[1];
TIFFOptions tiffOptions = new TIFFOptions();
tiffOptions.setTiffCompression(Compression.CCITTFAX4);
builder.imageOptions(tiffOptions);
builder.colorType(ImageColorType.BILEVEL);
param[0] = builder.build();
TIFFTweaker.writeMultipageTIFF(rout, param, images);
rout.close();
fos.close();
}
}

Ou est-il une autre bibliothèque pour écrire multi-page Tiff?

EDIT:

Grâce à dragon66 le bug dans icafe est maintenant résolu. Dans l'intervalle, j'ai expérimenté avec d'autres bibliothèques et aussi avec en invoquant ghostscript. Comme je pense que ghostscript est très fiable comme id est un outil largement utilisé, d'autre part, je dois compter que l'utilisateur de mon code a un ghostscript-installation, quelque chose comme ceci:

   /**
* Converts a given pdf as specified by its path to an tiff using group 4 compression
*
* @param pdfFilePath The absolute path of the pdf
* @param tiffFilePath The absolute path of the tiff to be created
* @param dpi The resolution of the tiff
* @throws MyException If the conversion fails
*/
private static void convertPdfToTiffGhostscript(String pdfFilePath, String tiffFilePath, int dpi) throws MyException {
//location of gswin64c.exe
String ghostscriptLoc = context.getGhostscriptLoc();
//enclose src and dest. with quotes to avoid problems if the paths contain whitespaces
pdfFilePath = "\"" + pdfFilePath + "\"";
tiffFilePath = "\"" + tiffFilePath + "\"";
logger.debug("invoking ghostscript to convert {} to {}", pdfFilePath, tiffFilePath);
String cmd = ghostscriptLoc + " -dQUIET -dBATCH -o " + tiffFilePath + " -r" + dpi + " -sDEVICE=tiffg4 " + pdfFilePath;
logger.debug("The following command will be invoked: {}", cmd);
int exitVal = 0;
try {
exitVal = Runtime.getRuntime().exec(cmd).waitFor();
} catch (Exception e) {
logger.error("error while converting to tiff using ghostscript", e);
throw new MyException(ErrorMessages.GHOSTSTSCRIPT_ERROR, e);
}
if (exitVal != 0) {
logger.error("error while converting to tiff using ghostscript, exitval is {}", exitVal);
throw new MyException(ErrorMessages.GHOSTSTSCRIPT_ERROR);
}
}

J'ai trouvé que le produit tif de ghostscript distingue fortement de la qualité de l' tiff produit par icafe (le groupe 4 tiff de ghostscript regarde en niveaux de gris)

Je vous recommande d'ouvrir un sujet ici: github.com/dragon66/icafe/issues/new
et où puis-je trouver la dernière version icafe.jar? Ou dois-je créer moi-même?
merci, ça fonctionne maintenant. J'ai également expérimenté avec ghostscript (à l'aide d'-sDEVICE=tiffg4) et je me demandais pourquoi le résultat est-il si différent (surtout pour les images, de texte, la différence n'est pas si frappante). Ghostscript produit des fichiers tiff qui ressemblent plus à des greylevel (bien qu'il soit d'aide inspiratoire avec pep), tandis que icafe produit plutôt "moche" images en noir et blanc
Remarque: ICAFE, vous permet désormais de définir ppp pour les deux directions verticale et horizontale
Merci Icafe est grande sur ce ...

OriginalL'auteur Raphael Roth | 2015-08-12