Quantcast
Channel: Aspose.Pdf Product Family
Viewing all articles
Browse latest Browse all 3131

Pdf printing: Font quality not as expected

$
0
0
Dear Aspose Team,

we are currently in the evaluating the capabilities of Aspose.Pdf for Java compared to the .Net version.

So far, everything looks good.

But when it comes to printing out the PDF, we recognized differences in the quality of the font.

In .Net the font looks fine and as expected, while using the printing in Aspose.Words java, the font letters become pixelated.

Do you have any suggestions, how to improve on that?

Please find attached the pdf file used as well as both resulting Postscript files.

The coding used (similar to .Net):


@Test
    public void TestPdfToPsConversion(){
   
    AsposePdfConverter testAsposePdfConverter = new AsposePdfConverter();
   
    File pdfInput = new File("C:\\testDoc\\pdfPrintJava\\mixedOrientation.pdf");
   
   
    try {
   
     FileInputStream fis = new FileInputStream(pdfInput);
   
     byte[] fileBytes = IOUtils.toByteArray(fis);
     
     fis.close();
   
     byte[] converted = testAsposePdfConverter.convertToPdfPs(fileBytes);
     
     FileOutputStream fileOut = new FileOutputStream(new File("C:\\testDoc\\pdfPrintJava\\mixedOrientationTestOutput.ps"));
     
     fileOut.write(converted);
     
     fileOut.close();
    }
    catch(Exception e) {
    e.printStackTrace();
    }
    finally {
    }
   
    }

public byte[] convertToPdfPs(byte[] content) throws IOException {

        initializeLicense();
        byte[] result = null;
        URI printToFileURI = null;
        SimpleDateFormat relativeSubFolderPath = new SimpleDateFormat("yyyyMMdd");
        SimpleDateFormat id = new SimpleDateFormat("HHmmss");
        String filePath =
                String.format("C:\\testDoc\\pdfPrintJava\\%s.%s", "printPdfPsConversion", "ps");
        String strPrinterName = BdcProperties.PRINTER_NAME;

        InputStream input = new ByteArrayInputStream(content);
        Document pdf = new Document(input);

        RenderingOptions renderOpts = new RenderingOptions();
        renderOpts.setSystemFontsNativeRendering(true);

        PdfPrinterSettings printerSettings = new PdfPrinterSettings();
        printerSettings.setPrinterName(strPrinterName);
        printerSettings.setPrintToFile(true);
        printerSettings.setPrintFileName(filePath);

        PrintPageSettings pageSettings = new PrintPageSettings();
        pageSettings.setMargins(new PrinterMargins(0, 0, 0, 0));
        pageSettings.setPrinterSettings(printerSettings);
        pageSettings.setColor(true);
        pageSettings.setLandscape(false);

        PdfViewer viewer = new PdfViewer();
        viewer.bindPdf(pdf);
        viewer.setPrintPageDialog(false);
        // pageSettings.setPrinterSettings(printerSettings);
        viewer.setAutoResize(true);
        viewer.setAutoRotate(true);
        viewer.setRenderingOptions(renderOpts);

        // viewer.setResolution(600);

        viewer.printDocumentWithSettings(pageSettings, printerSettings);
        

        try {
            result = Files.readAllBytes(Paths.get(filePath));
        } catch (IOException e) {
            logger.error(" : " + e.getMessage(), e);
            throw new BdcException(MessageCodes.ConvertToPdfFormatFailed, StatusInfoSource.General, e);
        } catch (Exception e) {
            logger.error(" : " + e.getMessage(), e);
            throw new BdcException(MessageCodes.ConvertToPdfFormatFailed, StatusInfoSource.Converter, e);
        } finally {
            //Files.delete(Paths.get(filePath)); // change to delete directory also
            input.close();
            viewer.close();
        }

        return result;
    }


Thanks and kind regards
Wolfgang

Viewing all articles
Browse latest Browse all 3131

Trending Articles