繁体   English   中英

PDF盒PNG图片不支持

[英]PDF box PNG image not supporting

我正在使用PDF框创建PDF,我正在尝试将图像打印为pdf,它可以使用除PNG以外的所有格式。 Mycode如下:

String image = "c:/image.png";                  
                                   PDXObjectImage ximage = null;
                  if( image.toLowerCase().endsWith( ".jpg" ) )
                  {
                      ximage = new PDJpeg(doc, new FileInputStream( image ) );
                  }
                  else if (image.toLowerCase().endsWith(".tif") || image.toLowerCase().endsWith(".tiff"))
                 {
                      ximage = new PDCcitt(doc, new RandomAccessFile(new File(image),"r"));
                 }
                 else
                  {
                      BufferedImage awtImage = ImageIO.read( new File( image ) );
                      ximage = new PDPixelMap(doc, awtImage);
                      throw new IOException( "Image type not supported:" + image );
                  }

                 PDPageContentStream contentStream = new PDPageContentStream(doc, page);
                  contentStream.drawImage( ximage, 20, 20 );

每当我给png图片时,它都会转到:

else
                      {
                          BufferedImage awtImage = ImageIO.read( new File( image ) );
                          ximage = new PDPixelMap(doc, awtImage);
                          //throw new IOException( "Image type not supported:" + image );
                      }

并显示图像流IO异常无法读取图像文件。 我还需要对此进行什么更改以接受png图像? 请帮忙...

String image = "c:/"+rst.getString(8);                  
                                               PDXObjectImage ximage = null;
                                if( image.toLowerCase().endsWith( ".jpg" ) )
                                {
                                    ximage = new PDJpeg(doc, new FileInputStream( image ) );
                                }
                                else if (image.toLowerCase().endsWith(".tif") || image.toLowerCase().endsWith(".tiff"))
                               {
                                    ximage = new PDCcitt(doc, new RandomAccessFile(new File(image),"r"));
                               }
                               else
                                {
                                    BufferedImage awtImage = ImageIO.read( new File( image ) );
                                    ximage = new PDPixelMap(doc, awtImage);

                                }


                               contentStream.drawXObject(ximage, 20, pageYaxis-120, 80, 80);
                                                pageYaxis = pageYaxis-56;

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM