You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@poi.apache.org by vegaecm <an...@vegaecm.com> on 2012/12/27 13:07:21 UTC

How to change PNG DPI

Hi,

Our team use Apache POI to render PowerPoint documents (ppt and pptx) to
PNG.
Thank you for your efforts for this project, it is really great product!

Could you please give us a little advice (unless, of course, it is not
difficult for you).

"Shape" class contains
public static final int POINT_DPI = 72;

We would like to use another DPI value.
Are there any objections just to change this value (i.e. to 96 or to 150)
and rebuild project or would this approach be wrong and we need deep code
changes?

Thanks in advance.



--
View this message in context: http://apache-poi.1045710.n5.nabble.com/How-to-change-PNG-DPI-tp5711758.html
Sent from the POI - Dev mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@poi.apache.org
For additional commands, e-mail: dev-help@poi.apache.org


A hint for Graph support while cloning a sheet

Posted by Guillaume de GENTILE <gd...@finbox-solutions.com>.
Hi all,

While cloning a sheet (workbook.cloneSheet(indexSource)), the graphs 
from the source sheet are not duplicated in the target sheet and the 
resulting report is corrupted (error message while openning the Excel 
document).

I have amended the cloneSheet method to duplicate the graph from the 
source system (The amended code is in RED color).
However I am new with the pio API and don't really know how to handle 
objects (I don't get a clear picture of the code yet).
The target sheet contains a copy of the source graphs, however the 
graphs are still referencing the source sheet.
This code should be amended so the new graphs reference the new sheet.
It would be great to have this funtionality in the next release (if 
somebody knows how to do it...)

     /**
      * Create an XSSFSheet from an existing sheet in the XSSFWorkbook.
      *  The cloned sheet is a deep copy of the original.
      *
      * @return XSSFSheet representing the cloned sheet.
      * @throws IllegalArgumentException if the sheet index in invalid
      * @throws POIXMLException if there were errors when cloning
      */
     public XSSFSheet cloneSheet(int sheetNum) {
         validateSheetIndex(sheetNum);

         XSSFSheet srcSheet = sheets.get(sheetNum);
         String srcName = srcSheet.getSheetName();
         String clonedName = getUniqueSheetName(srcName);

         XSSFSheet clonedSheet = createSheet(clonedName);
         try {
             ByteArrayOutputStream out = new ByteArrayOutputStream();
             srcSheet.write(out);
             clonedSheet.read(new ByteArrayInputStream(out.toByteArray()));
         } catch (IOException e){
             throw new POIXMLException("Failed to clone sheet", e);
         }
         CTWorksheet ct = clonedSheet.getCTWorksheet();
         if(ct.isSetLegacyDrawing()) {
             logger.log(POILogger.WARN, "Cloning sheets with comments is 
not yet supported.");
             ct.unsetLegacyDrawing();
         }
         if (ct.isSetPageSetup()) {
             logger.log(POILogger.WARN, "Cloning sheets with page setup 
is not yet supported.");
             ct.unsetPageSetup();
         }

         clonedSheet.setSelected(false);

         // copy sheet's relations
         List<POIXMLDocumentPart> rels = srcSheet.getRelations();
         // if the sheet being cloned has a drawing then remember it and 
re-create tpoo
         XSSFDrawing dg = null;
         for(POIXMLDocumentPart r : rels) {
             // do not copy the drawing relationship, it will be re-created
             if(r instanceof XSSFDrawing) {
                 dg = (XSSFDrawing)r;
                 continue;
             }

             PackageRelationship rel = r.getPackageRelationship();
             clonedSheet.getPackagePart().addRelationship(
                     rel.getTargetURI(), rel.getTargetMode(), 
rel.getRelationshipType());
             clonedSheet.addRelation(rel.getId(), r);
         }

         // clone the sheet drawing alongs with its relationships
         if (dg != null) {
             if(ct.isSetDrawing()) {
                 // unset the existing reference to the drawing,
                 // so that subsequent call of 
clonedSheet.createDrawingPatriarch() will create a new one
                 ct.unsetDrawing();
             }
             XSSFDrawing clonedDg = clonedSheet.createDrawingPatriarch();
             // copy drawing contents
             clonedDg.getCTDrawing().set(dg.getCTDrawing());

             // Clone drawing relations
             List<POIXMLDocumentPart> srcRels = 
srcSheet.createDrawingPatriarch().getRelations();
             for (POIXMLDocumentPart rel : srcRels) {
                 if(rel instanceof XSSFChart) {
                     XSSFChart chart = (XSSFChart) rel;
                     try {

                         // create new chart from source Chart
                         int chartNumber = 
getPackagePart().getPackage().getPartsByContentType(XSSFRelation.CHART.getContentType()).size() 
+ 1;
                         XSSFChart c = (XSSFChart) 
clonedDg.createRelationship(XSSFRelation.CHART, 
XSSFFactory.getInstance(), chartNumber);
                         c.getCTChart().set(chart.getCTChart());
c.getCTChartSpace().set(chart.getCTChartSpace());

                         // the new chart is still referencing the 
source sheet!

                         PackageRelationship relation = 
c.getPackageRelationship();
clonedDg.getPackagePart().addRelationship(relation.getTargetURI(), 
relation.getTargetMode(),
                                 relation.getRelationshipType(), 
relation.getId());

                     } catch (Exception e) {
                         // TODO Auto-generated catch block
                         e.printStackTrace();
                     }
                 } else {
                     PackageRelationship relation = 
rel.getPackageRelationship();
                     clonedSheet
                             .createDrawingPatriarch()
                             .getPackagePart()
.addRelationship(relation.getTargetURI(), relation.getTargetMode(),
relation.getRelationshipType(), relation.getId());
                 }
             }
         }
         return clonedSheet;
     }


Thanks,
Guillaume

Re: How to change PNG DPI

Posted by Dave Fisher <da...@comcast.net>.
Give it a try. You will use more memory.

Regards,
Dave

On Dec 27, 2012, at 4:07 AM, vegaecm wrote:

> Hi,
> 
> Our team use Apache POI to render PowerPoint documents (ppt and pptx) to
> PNG.
> Thank you for your efforts for this project, it is really great product!
> 
> Could you please give us a little advice (unless, of course, it is not
> difficult for you).
> 
> "Shape" class contains
> public static final int POINT_DPI = 72;
> 
> We would like to use another DPI value.
> Are there any objections just to change this value (i.e. to 96 or to 150)
> and rebuild project or would this approach be wrong and we need deep code
> changes?
> 
> Thanks in advance.
> 
> 
> 
> --
> View this message in context: http://apache-poi.1045710.n5.nabble.com/How-to-change-PNG-DPI-tp5711758.html
> Sent from the POI - Dev mailing list archive at Nabble.com.
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: dev-unsubscribe@poi.apache.org
> For additional commands, e-mail: dev-help@poi.apache.org
> 


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@poi.apache.org
For additional commands, e-mail: dev-help@poi.apache.org