You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@pdfbox.apache.org by Werner Nell <We...@web.de> on 2009/10/22 15:27:42 UTC

text not printed

Hi.
I have the problem that the text in my pdf-file wil not be printed at all. The PDF is shown and printed correctly with Acrobat Reader.
What I do is:

        PDDocument document = null;

        try {
            URL pdfFile = new URL(pdfURLStr);
            write_message("Printing URL: " + pdfURLStr);
            document = PDDocument.load(pdfFile);
            List pages = document.getDocumentCatalog().getAllPages();

            // load fonts here iterate over pages 
            if (pages.isEmpty()) {
                write_message("Pages list is empty");
            } else {
                write_message("Pages list is NOT empty");
                Iterator it = pages.iterator();

                while (it.hasNext()) {
                  PDPage currentPage = (PDPage) it.next();
                   Map map = currentPage.findResources().getFonts();
                   
                   write_message("Map is: "+map.toString());                   
                   Set mySet = map.keySet();
                   
                   Iterator setInt = mySet.iterator();
                   
                    while (setInt.hasNext()) {
                        
                        String val = (String)setInt.next();
                        
                        PDType1Font pdt = (PDType1Font)map.get(val);
                        write_message("'"+val+" "+pdt.getFontDescriptor().getFontName()+"'");
                        
                        PDFont currFont = this.loadFontByName(document,pdt.getFontDescriptor().getFontName(),val);
                        //        PDTrueTypeFont.loadTTF(document, extFSFonts.getProperty(fontName) );
                        
                        if(currFont != null)
                        {
                          currentPage.findResources().getFonts().put(val,currFont);
                        }
                    }
                }
             }
 
            AccessPermission currentPermissions = document.getCurrentAccessPermission();

            if (!currentPermissions.canPrint()) {
                write_message("Permission denied to print document.");
            }

            PrintService currentPrintService = PrinterJob.getPrinterJob().getPrintService();
            PrinterJob printJob = PrinterJob.getPrinterJob();
            printJob.setPrintService(currentPrintService);
            printJob.setPageable(document);

            write_message("Printing PDDocument");
            printJob.print();
            
            // Close document
             document.close();
            
        } catch (Exception ex) {
            write_message(ex.getMessage());
}

Any suggestions?

______________________________________________________
GRATIS für alle WEB.DE-Nutzer: Die maxdome Movie-FLAT!
Jetzt freischalten unter http://movieflat.web.de


Re: text not printed

Posted by Andreas Lehmkühler <an...@lehmi.de>.
Hi,

Werner Nell schrieb:
> Hi.
> I have the problem that the text in my pdf-file wil not be printed at all. The PDF is shown and printed correctly with Acrobat Reader.
> What I do is:
> 
>         PDDocument document = null;
> 
>         try {
>             URL pdfFile = new URL(pdfURLStr);
>             write_message("Printing URL: " + pdfURLStr);
>             document = PDDocument.load(pdfFile);
>             List pages = document.getDocumentCatalog().getAllPages();
> 
>             // load fonts here iterate over pages 
>             if (pages.isEmpty()) {
>                 write_message("Pages list is empty");
>             } else {
>                 write_message("Pages list is NOT empty");
>                 Iterator it = pages.iterator();
> 
>                 while (it.hasNext()) {
>                   PDPage currentPage = (PDPage) it.next();
>                    Map map = currentPage.findResources().getFonts();
>                    
>                    write_message("Map is: "+map.toString());                   
>                    Set mySet = map.keySet();
>                    
>                    Iterator setInt = mySet.iterator();
>                    
>                     while (setInt.hasNext()) {
>                         
>                         String val = (String)setInt.next();
>                         
>                         PDType1Font pdt = (PDType1Font)map.get(val);
>                         write_message("'"+val+" "+pdt.getFontDescriptor().getFontName()+"'");
>                         
>                         PDFont currFont = this.loadFontByName(document,pdt.getFontDescriptor().getFontName(),val);
>                         //        PDTrueTypeFont.loadTTF(document, extFSFonts.getProperty(fontName) );
>                         
>                         if(currFont != null)
>                         {
>                           currentPage.findResources().getFonts().put(val,currFont);
>                         }
>                     }
>                 }
>              }
Why are you doing all that font-loading stuff? PDFBox should find all
included fonts on its own, if the font type is supported. If the fonts
aren't included PDFBox tries to determine if they are installed
somewhere on your system. What fonts are used within your document,
truetype, truetype as embedded subtype, Type1 ...? I guess it uses some
unsupported fonts. Have a look at the docs properties e.g. using the
Acrobat Reader. If you want to check if a pdf will be printed with
pdfbox, just try to open it with the PDFReader that comes with pdfbox.
If the pdf is shown correctly the printing should work too.

>             AccessPermission currentPermissions = document.getCurrentAccessPermission();
> 
>             if (!currentPermissions.canPrint()) {
>                 write_message("Permission denied to print document.");
>             }
> 
>             PrintService currentPrintService = PrinterJob.getPrinterJob().getPrintService();
>             PrinterJob printJob = PrinterJob.getPrinterJob();
>             printJob.setPrintService(currentPrintService);
>             printJob.setPageable(document);
> 
>             write_message("Printing PDDocument");
>             printJob.print();
>             
>             // Close document
>              document.close();
This should do the printing trick.

BR
Andreas Lehmkühler