Return-Path: X-Original-To: apmail-incubator-ooo-dev-archive@minotaur.apache.org Delivered-To: apmail-incubator-ooo-dev-archive@minotaur.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 35EA4C1EA for ; Thu, 31 May 2012 07:53:00 +0000 (UTC) Received: (qmail 68181 invoked by uid 500); 31 May 2012 07:52:59 -0000 Delivered-To: apmail-incubator-ooo-dev-archive@incubator.apache.org Received: (qmail 67975 invoked by uid 500); 31 May 2012 07:52:59 -0000 Mailing-List: contact ooo-dev-help@incubator.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: ooo-dev@incubator.apache.org Delivered-To: mailing list ooo-dev@incubator.apache.org Received: (qmail 67938 invoked by uid 99); 31 May 2012 07:52:58 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 31 May 2012 07:52:58 +0000 X-ASF-Spam-Status: No, hits=-0.0 required=5.0 tests=SPF_PASS X-Spam-Check-By: apache.org Received-SPF: pass (athena.apache.org: local policy) Received: from [82.146.102.94] (HELO pmgroup.be) (82.146.102.94) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 31 May 2012 07:52:51 +0000 Received: from [192.168.0.37] ([192.168.0.37]) by mail.pmgroup.be (PMGroup Mailserver) with ASMTP id PMF40428 for ; Thu, 31 May 2012 09:52:28 +0200 Message-ID: <4FC722C6.2000301@pmgroup.be> Date: Thu, 31 May 2012 09:50:30 +0200 From: Fernand Vanrie User-Agent: Mozilla/5.0 (Windows NT 5.1; rv:12.0) Gecko/20120428 Thunderbird/12.0.1 MIME-Version: 1.0 To: ooo-dev@incubator.apache.org Subject: Re: [Rendering] Trying to render text page to a bitmap References: <4FA29AC8.7090502@pmgroup.be> <20120530164933.GA22946@localhost> In-Reply-To: <20120530164933.GA22946@localhost> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Virus-Checked: Checked by ClamAV on apache.org Ariel , Very instructive, copied to my learning stuff, thansk i pointed Eric to a other technic, opening the doc in "preview" mode in a frame based on a new created window in a filepicker dialog. Principle parts of the code Sub PreviewWindowLoadOOFile(sUrl as String) oPreviewWindow = InstallNewPreviewWindow(oFPickerDialog.Window, 0) oFrame = createUnoService("com.sun.star.frame.Frame") oFrame.initialize(oPreviewWindow) Dim aProps(0) As New com.sun.star.beans.PropertyValue aProps(0).Name = "Preview" aProps(0).Value = true oPreviewDoc = oFrame.loadComponentFromURL(sUrl, "", 0, aProps()) end sub function InstallNewPreviewWindow(oWin as Object, lWinAttrs as Long) as Object ' Create a window descriptor and set up its properties Dim aDescriptor As New com.sun.star.awt.WindowDescriptor aDescriptor.Type = com.sun.star.awt.WindowClass.SIMPLE aDescriptor.Parent = oWin aDescriptor.Bounds = oWin.Windows(lLastWindowAtStart).PosSize aDescriptor.WindowAttributes = com.sun.star.awt.WindowAttribute.SHOW or lWinAttrs oToolkit = createUnoService("com.sun.star.awt.Toolkit") InstallNewPreviewWindow = oToolkit.createWindow(aDescriptor) end function Greetz Fernand > REM ***** BASIC ***** > > Option Explicit > > Sub Main > GlobalScope.BasicLibraries.loadLibrary("Tools") > Dim oDoc as Object > oDoc = ThisComponent > > > If HasUnoInterfaces(oDoc, "com.sun.star.view.XRenderable") Then > Dim sBaseURL as String > sBaseURL = DirectoryNameOutOfPath(oDoc.getURL(), "/") > > Dim oSFA as Object > oSFA = CreateUnoService("com.sun.star.ucb.SimpleFileAccess") > Dim oGraphicProvider as Object > oGraphicProvider = CreateUnoService("com.sun.star.graphic.GraphicProvider") > > Dim oController as Object > Dim oUnitConverter as Object > oController = oDoc.getCurrentController() > oUnitConverter = oController.getFrame().getComponentWindow() > > Dim oSelection as Object > ' it could be the whole document > oSelection = oDoc > > ' or the selection > 'Dim oTextCursor as Object > 'oTextCursor = oDoc.getText().createTextCursorByRange(oDoc.getText().getStart()) > 'oTextCursor.goToRange(oDoc.getText().getEnd(), True) > 'oController.select(oTextCursor) > 'oSelection = oController.getSelection() > > Dim oDevice as Object > Dim aRenderOptions(5) as New com.sun.star.beans.PropertyValue > aRenderOptions(0).Name = "RenderDevice" > aRenderOptions(0).Value = oDevice > aRenderOptions(1).Name = "ExportNotesPages" > aRenderOptions(1).Value = False > aRenderOptions(2).Name = "IsFirstPage" > aRenderOptions(2).Value = True > aRenderOptions(3).Name = "IsLastPage" > aRenderOptions(3).Value = False > aRenderOptions(4).Name = "IsSkipEmptyPages" > aRenderOptions(4).Value = True > aRenderOptions(5).Name = "PageRange" > aRenderOptions(5).Value = "" > > > Dim nPageCount as Integer > nPageCount = oDoc.getRendererCount( oSelection, aRenderOptions ) > If nPageCount> 0 Then > Dim oToolkit as Object > oToolkit = CreateUnoService("com.sun.star.awt.Toolkit") > > Dim oRenderer as Object > Dim oPageSize as Object > Dim i% > Dim sURL$ > > While nPageCount> 0 > nPageCount = nPageCount - 1 > oRenderer = oDoc.getRenderer(nPageCount, oSelection, aRenderOptions) > For i = 0 To UBound(oRenderer) > If oRenderer(i).Name = "PageSize" Then > oPageSize = oRenderer(i).Value > Exit For > End If > Next > > Dim oDeviceSize as Object > oDeviceSize = oUnitConverter.convertSizeToPixel(oPageSize, com.sun.star.util.MeasureUnit.MM_100TH) > oDevice = oToolkit.createScreenCompatibleDevice( oDeviceSize.Width, oDeviceSize.Height) > aRenderOptions(0).Value = oDevice > oDoc.render( nPageCount, oSelection, aRenderOptions) > > Dim oBitmap as Object > oBitmap = oDevice.createBitmap( 0, 0, oDevice.Info.Width,oDevice.Info.Height) > > sURL = sBaseURL + "/" + CStr(nPageCount) + ".png" > If oSFA.exists(sURL) Then oSFA.kill(sURL) > StoreBitmapToURL(oGraphicProvider, oBitmap, sURL) > Wend > End If > End If > End Sub > > Sub StoreBitmapToURL(oGraphicProvider, oBitmap, sURL) > Dim oMediaProperties(0) as New com.sun.star.beans.PropertyValue > oMediaProperties(0).Name = "Bitmap" > oMediaProperties(0).Value = oBitmap > > Dim oGraphic as Object > oGraphic = oGraphicProvider.queryGraphic(oMediaProperties) > > If NOT IsNull(oGraphic) Then > Dim oMediaPropertiesOut(2) as New com.sun.star.beans.PropertyValue > oMediaPropertiesOut(0).Name = "URL" > oMediaPropertiesOut(0).Value = sURL > oMediaPropertiesOut(1).Name = "MimeType" > oMediaPropertiesOut(1).Value = "image/png" > > oGraphicProvider.storeGraphic(oGraphic, oMediaPropertiesOut) > End If > End Sub