Hi @alexey.noskov
Just to clarify:
My input type will be DOC/DOCX. Here are the questions:
If I convert to PDF, below are the two ways to set zoom factor and rotate factor:
//Option 1:
//Use pdf to set rotate and zoom -resultant type will be PDF
com.aspose.words.Document document = wordDocument.getDocument();
com.aspose.words.Document doc1 = document.extractPages(pageNum - 1, 1);
doc1.save("C:/temp/save.pdf", SaveFormat.PDF);
com.aspose.pdf.Document pdfDocument = new com.aspose.pdf.Document("C:/temp/save.pdf");
GoToAction action = new GoToAction(new XYZExplicitDestination(1, 0, 0, .5));
pdfDocument.setOpenAction(action);
pdfDocument.save("C:/temp/zoomed.pdf", com.aspose.pdf.SaveFormat.Pdf);
//Option 2:
//Use ImageSaveOptions to set zoom , rotate yet to figure out : resultant mime type will be pdf
com.aspose.words.Document documentImage = wordDocument.getDocument();
com.aspose.words.Document documentImage1 = documentImage.extractPages(pageNum - 1, 1);
com.aspose.words.PdfSaveOptions pdfSaveOptions = new com.aspose.words.PdfSaveOptions();
pdfSaveOptions.setZoomBehavior(PdfZoomBehavior.ZOOM_FACTOR);
pdfSaveOptions.setZoomFactor(25);
documentImage1.save("C:/temp/zoomword.pdf", pdfSaveOptions);
- If I want the type of the output to be PNG , the only way to set zoom and rotate is as below:
com.aspose.words.Document pngDocument = wordDocument.getDocument();
com.aspose.words.Document pngDocument1 = pngDocument.extractPages(pageNum - 1, 1);
// Calculate the number of rows and columns that we will fill with thumbnails.
final int thumbColumns = 2;
int thumbRows = pngDocument.getPageCount() / thumbColumns;
int remainder = pngDocument.getPageCount() % thumbColumns;
if (remainder > 0) thumbRows++;
// Scale the thumbnails relative to the size of the first page.
float scale = 1.0f;
Dimension thumbSize = pngDocument.getPageInfo(0).getSizeInPixels(scale, 96);
// Calculate the size of the image that will contain all the thumbnails.
int imgWidth = (int)(thumbSize.getWidth() * thumbColumns);
int imgHeight = (int)(thumbSize.getHeight() * thumbRows);
BufferedImage img = new BufferedImage(700, 700, BufferedImage.TYPE_INT_ARGB);
Graphics2D gr = img.createGraphics();
gr.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
gr.setColor(Color.white);
// Fill the background, which is transparent by default, in white.
// gr.fillRect(0, 0, imgWidth, imgHeight);
// for (int pageIndex = 0; pageIndex < document.getPageCount(); pageIndex++) {
int rowIdx = pageNum / thumbColumns;
int columnIdx = pageNum % thumbColumns;
// Specify where we want the thumbnail to appear.
float thumbLeft = (float)(columnIdx * thumbSize.getWidth());
float thumbTop = (float)(rowIdx * thumbSize.getHeight());
Point.Float size = pngDocument.renderToScale(pageNum - 1, gr, (float)ConvertUtil.inchToPoint(3), (float)ConvertUtil.inchToPoint(3), scale);
gr.setColor(Color.black);
// Render a page as a thumbnail, and then frame it in a rectangle of the same size.
gr.drawRect(0, 0, (int)ConvertUtil.inchToPoint(3), (int)ConvertUtil.inchToPoint(3));
// }
// ImageIO.write(img, "PNG", new File("C:/temp/Rendering.Thumbnails.png"));
ImageIO.write(img, "PNG", os);
If I want DOC to PNG conversion and then set zoom , I need to use renderToScale or renderToSize API of Aspose.Words. Can you please confirm if my understanding is correct ?
Also, what is the difference between using GoToAction(from aspose.pdf) to set zoom and PdfSaveOptions(aspose.words) to set zoom ?