Uploaded image for project: 'PDFBox'
  1. PDFBox
  2. PDFBOX-5140

Can't change PDF including some Chinese font to JPG correctly

    XMLWordPrintableJSON

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Major
    • Resolution: Duplicate
    • Affects Version/s: 2.0.22
    • Fix Version/s: None
    • Component/s: Rendering
    • Labels:
      None
    • Environment:
      Windows 10

      Description

      I tried to change PDF file including Chinese font to JPG file.
      Source code is as below.

      	private List<String> convertPdf2Jpg(File pdfFile) {
      
      		List<String> jpgList = new ArrayList<String>();
      
      		try {
      			PDDocument document = PDDocument.load(pdfFile);
      			PDFRenderer pdfRenderer = new PDFRenderer(document);
      			for (int i = 0; i < document.getNumberOfPages(); i++) {
      				BufferedImage image = null;
      				try{
      					image = pdfRenderer.renderImageWithDPI(i, 300 ,ImageType.RGB);
      					String jpgName = pdfFile.getPath().split(".pdf")[0] + "_" + String.format("%03d", i+1) +  ".jpg";
      					ImageIOUtil.writeImage(image, jpgName, 300);
      					jpgList.add(jpgName);
      				}
      				catch(Exception e) {
      					document.close();
      					LOG.error(pdfFile + "(" + i + " page) " + " can't convert pdf to jpg file (convertPdf2Jpg())." + e.toString());
      					throwPdfBoxException("convertPdf2Jpg():" +  pdfFile + "(" + i + " page) " + " can't convert pdf to jpg file." + e.toString());
      				}
      			}
      			document.close();
      		}
      		catch(Exception e){
      			LOG.error(pdfFile + "Can't load PDF file (convertPdf2Jpg()).");
      		}
      		return jpgList;
      	}
      

      I attached example of PDF and JPG. Chinese characters are broken.
      It seems that it depends on font.
      If you need more information, please let me know.

      Thanks

      //Okada

        Attachments

        1. TC_PMingLiU.pdf
          837 kB
          Shigeru Okada
        2. TC_PMingLiU_001.jpg
          382 kB
          Shigeru Okada
        3. TC_MingLiu.pdf
          807 kB
          Shigeru Okada
        4. TC_MingLiu_001.jpg
          382 kB
          Shigeru Okada
        5. TC_DFKaiShuSB.pdf
          838 kB
          Shigeru Okada
        6. TC_DFKaiShuSB_001.jpg
          382 kB
          Shigeru Okada

          Issue Links

            Activity

              People

              • Assignee:
                Unassigned
                Reporter:
                Shigeru_Okada Shigeru Okada
              • Votes:
                0 Vote for this issue
                Watchers:
                2 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: