Click here to Skip to main content
Click here to Skip to main content

Generate PDF Using C#

By , 1 Feb 2009
 
OpenOffice 2.4.1 was used during writing of article. At the end of the article there is link to the instructions that will make code work with OpenOffice 3.

Introduction

I must confess that I’m not a big fan of PDF. Still, it somehow manages to wiggle in almost every project I'm on – clients want to send out documents, Word is bounded to Windows, HTML is lame, PDF it is. Unfortunately, the situation with it and C# haven’t changed much in couple past years - if there were no new, fancy, priced components, I would conclude that it’s almost the same as it was in .NET 1.1 times – it is a pain to create PDFs.

For those of you who have access to components which can convert popular formats to PDF, this article is pretty much useless. But, for those who don’t want or simply can’t shell out over $1000 for a chance to convert other formats to PDF – I hope that this solution will prove as an attractive alternative.

Idea

During a talk with my friend Toni Ruža (who is primarily a Python developer) about a way to easily convert some WordML reports to PDF, he pointed me to the headless OpenOffice mode. It seems that it has been around for quite some time, but as it is mainly targeted at Java developers, it is no wonder that there were no big fuss about it in C# groups. Still, it promises much – you install OpenOffice, start it in Service mode, send commands over the API, and get to use any feature it provides. More than anything else, my interest was to load any supported format into OpenOffice and then export it as PDF.

Just to note, in this article, I'll talk about creating PDF from other documents, not from scratch. If you are looking for a way to do that, I'm encouraging you to first take a look at my Generating Word Reports / Documents article. Follow it, and you'll easily create WordML files (like the one used here) from a database or XML.

Solution architecture

I was saddened to find out that the headless mode of OpenOffice just minimizes GUI operations, not totally avoiding them. As someone who has a pretty nasty experience with Word.Application.Open() (using interactive applications such as Word by programmatically mimicking user actions), I started thinking on how to isolate OpenOffice and query it independently of the main application process, thus enabling loose coupling and a more stable environment. The result was a Windows Service which wraps the OpenOffice process, taking care of the security context and the usage, while providing the needed functionality over Remoting (am I a service-oriented freak or what? :)).

Here is a diagram presenting the classes used in the process:

Figure 1 – Class diagram

Figure 1 – Class diagram

ConversionToPDF is the main class when it comes to performing useful work. It employs various classes from the unoidl.com.sun namespace to communicate with OpenOffice, and mimics operations such as opening a file, exporting it as PDF, etc. It also uses the OfficeController class which is responsible for the lifecycle of OpenOffice’s process – it starts, monitors, and finally kills soffice.exe when not used, to preserve resources.

Receiver is the class that my Windows Service registers for usage over Remoting. It implements the IReceiver interface (needed functionality), and serves as the bridge between the main applications and OpenOffice.

Finally, I’ve created the GenericSender class for those not familiar with Remoting. It provides the Init method that accepts an address on which the Windows Service wrapper listens (by default, it is tcp://localhost:6543/OpenOfficeServiceReceiver) and initializes a proxy receiver (available as a property). From that point forwards, everything is simple as GenericSender.Receiver.ConvertToPDF(...).

How to start everything on my machine?

Let’s do this in a step-by-step fashion:

  1. Download OpenOffice from here, and perform the standard installation. I’ve developed and tested a solution using version 2.4 of OO. If you are setting up everything on an x64 machine, be sure to add the OO program directory (by default: c:\Program Files (x86)\OpenOffice.org 2.4\program) to the PATH environment variable as described in this forum post. If you change the environment variable, be sure to restart the machine in order to commit and reload the changes.
  2. Download the source code that accompanies this article, and Build Solution using the Release configuration in Visual Studio 2008. When the build is complete, check OpenOfficeService/bin/Release and run svc_inst.bat. After that, you should see the OpenOffice Wrapper Service in the list of services when you go to Control Panel -> Administrative Tools -> Services. Right click on it, select Properties, go to the Log on tab, and check Allow service to interact with desktop.
  3. Before you can start the service, you need to tweak the license agreement. Because the wrapper service will run under the LocalSystem account, you need to somehow tell OpenOffice that the LocalSystem user “accepted” the terms of use. To prevent the license agreement dialog from popping up and blocking everything, you need to modify the file at %OOInstallPath%\share\registry\data\org\openoffice\Setup.xcu by finding this part:
  4. <prop oor:name="ooSetupInstCompleted">
      <value>false</value>
    </prop>
    <prop oor:name="ooSetupShowIntro">
      <value>true</value>
    </prop>

    and replacing it with (note that LicenseAcceptDate must be later than the OpenOffice installation time):

    <prop oor:name="ooSetupInstCompleted" oor:type="xs:boolean">
     <value>true</value>
    </prop>
    <prop oor:name="LicenseAcceptDate" oor:type="xs:string">
     <value>2008-07-22T14:00:00</value>
    </prop>
    <prop oor:name="FirstStartWizardCompleted" oor:type="xs:boolean">
     <value>true</value>
    </prop>

    This step is taken from here, and I would like to thank Mirko Nasato for his great guide.

    Be sure to start any OpenOffice application (Start -> Programs -> OpenOffice.org -> OpenOffice.org Writer, for example), and validate that it loads without any glitches in order to be sure that OO is properly installed and setup.

  5. Verify the service configuration (next chapter), start the OpenOffice Wrapper Service, and use it to convert a document. If you have downloaded the source code, you can right click on Default.aspx (Test Applications -> PDFWeb project) in Solution Explorer and choose View in Browser... Here is a code excerpt that uses the GenericSender from OpenOfficeService.Objects.dll to perform the conversion:
  6. protected void GiveMePDFButton_Click(object sender, EventArgs e)
    {
        // Initialize Receiver in GenericSender
        OpenOfficeService.Objects.GenericSender.Init(
            "tcp://localhost:6543/OpenOfficeServiceReceiver");
    
        // Translate path and load up file in byte array, convert it
        string source = Server.MapPath("~/SomeWordML.xml");
        byte[] wordML = File.ReadAllBytes(source);
    
        byte[] result = 
          OpenOfficeService.Objects.GenericSender.Receiver.ConvertToPDF(wordML);
    
        // Write response to client
        Response.AddHeader("content-type", "application/pdf");
        Response.AddHeader("Content-Disposition", 
                           "attachment; filename=result.pdf");
    
        Response.BinaryWrite(result);
    }

    Figure 2 – Testing page

    Figure 2 – Testing page

Believe it or not, that’s it! You now have a functioning PDF converter which can be queried from C#, by Remoting.

During the wrapper implementation, I thought about multi-threading and (hopefully) made calling the ConvertToPDF thread safe. Conversion requests are queued and processed one by one, so the Open Office Wrapper Service can be used by more than one application and, why not, from multiple machines too (the generic sender for the application running on other machines should then be initialized with tcp://%machineHostingService%:6543/OpenOfficeServiceReceiver).

Configuration

Currently, there are the following settings for the Open Office Wrapper Service:

  • Port – It’s the port on which the service will listen for requests. By default, it is 6543.
  • ProcessName – The name of the OpenOffice process (used when searching the process list to see if OO is alive). When you start OpenOffice in headless mode, it is soffice.bin (instead of soffice.exe).
  • PathToOpenOffice – Self-explanatory, eh? If you have installed OpenOffice on a path other than the default, you should change this setting (the default path is c:\Program Files\OpenOffice.org 2.4\program\soffice.exe; on x64 machines, add (x86) after Program Files).
  • SecondsIdleAllowed – When a conversion request is submitted, OpenOfficeController checks if OO is running in the background, and if not, starts soffice.exe in headless mode. By default, if no new request is made in 60 seconds, the OpenOffice process will be killed.
  • CheckIntervalInSeconds – The interval in which the service evaluates OpenOffice usage (bound to the previous setting). By default, it is 30 seconds.
  • RequestTimeoutInSeconds – The time in which a response is expected from OpenOffice. If the item stays in the queue for too long or OpenOffice gets too big a file for processing, a Timeout Exception will be thrown. The default wait is 30 seconds.

Running in-process?

I would like to mention once again that the Windows Service I wrote is only there to provide a security context and serve as a bridge to OpenOfficeWrapper.dll that implements the main stuff when it comes to communicating with OpenOffice. If you wish, you can directly reference OpenOfficeWrapper.dll and perform PDF conversions in-process, but you must be sure that your application will be run with sufficient security privileges! In my testing, the conversion was successful only if I run the application under an account that belonged to the Administrator group.

Also, you could run into trouble when trying to run OpenOfficeWrapper on x64 versions of Windows. I’ve had tons of trouble trying to get my Web Application to convert PDF by using the OpenOfficeWrapper in process on a Windows 2003 x64 machine. So, if you really do not need to have everything in your application’s process, leave the code that wraps OpenOffice separated, and use it through a Windows Service.

Words of warnings and words of thanks

To me, the documentation of OpenOffice is terrible. OK, I could be another C# "quasi-developer" who finds it easier to look at examples than to crawl through bunch of Wiki pages, diagrams, and forum posts just to get a couple lines of code that opens a document. But, for me - after an absolute champion of useless information, unrelated links, and broken searches in the MSDN - the OO developer portal is one more example of how you do not want your documentation to be organized. From what I’ve seen, OpenOffice is a great product considering the cost ($0), and it is a shame that I can’t say the same for its documentation.

On the other hand, posts of server users on the OOoForum are really helpful; I would specifically like to thank LarsB, tcedi, and DannyB. Most of the conversion code in ConvertToPDF.cs is taken from LarsB’s Commandline PDF convertor; so, thank you man – I hope you’ll continue to post useful snippets.

Conclusion

With this article, I aimed at a simple goal – to provide an easy-to-follow, free, and versatile solution for converting documents to PDF by using C#. I am aware that there are technically more robust solutions, but I do not know any of them that’s free. If you know – please post it in the comments section along with an impression of this article.

Enjoy! ;)

References

History

  • January 8th, 2009 - Added references.
  • July 22nd, 2008 - Initial version of the article.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

About the Author

Predrag Tomasevic
Software Developer Atama Group
United States United States
http://www.linkedin.com/in/ptomasevic

Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board.
Search this forum  
    Spacing  Noise  Layout  Per page   
GeneralMy vote of 5memberNuanda0330-May-13 4:43 
Only needed a few minor tweaks to convert this project into a full PDF conversion service. Thank you for this great project!
Questioncan not stat OOSService ,and have an errormemberyinjiuwen22-Apr-13 22:26 
“/”应用程序中的服务器错误。
 
找不到指定的模块。 (异常来自 HRESULT:0x8007007E)
 
说明: 执行当前 Web 请求期间,出现未处理的异常。请检查堆栈跟踪信息,以了解有关该错误以及代码中导致错误的出处的详细信息。
 
异常详细信息: System.IO.FileNotFoundException: 找不到指定的模块。 (异常来自 HRESULT:0x8007007E)
 
源错误:
 

行 21: byte[] wordML = File.ReadAllBytes(source);
行 22:
行 23: byte[] result = OpenOfficeService.Objects.GenericSender.Receiver.ConvertToPDF(wordML);
行 24:
行 25: // Write response to client
 
源文件: C:\Users\Administrator\Downloads\article_src\Solution\PDFWeb\Default.aspx.cs 行: 23
QuestionMethod not found: 'unoidl.com.sun.star.uno.XComponentContext uno.util.Bootstrap.bootstrap()'."}membergeneral_aelius21-Jun-12 2:58 
Hello I'm using OpenOffice 3.4.0, and I'm getting the following error :
 
Method not found: 'unoidl.com.sun.star.uno.XComponentContext uno.util.Bootstrap.bootstrap()'."}
 

Server stack trace:
at OpenOfficeWrapper.ConversionToPDF.Generate(String sourcePath, String destinationPath)
at OpenOfficeWrapper.ConversionToPDF.Generate(String sourcePath) in E:\Projecten\Demos\PDFGeneration\OpenOfficeWrapper\ConversionToPDF.cs:line 60
at OpenOfficeService.Receiver.ConvertToPDF(String source) in E:\Projecten\Demos\PDFGeneration\OpenOfficeService\Receiver.cs:line 52
at System.Runtime.Remoting.Messaging.StackBuilderSink._PrivateProcessMessage(IntPtr md, Object[] args, Object server, Int32 methodPtr, Boolean fExecuteInContext, Object[]& outArgs)
at System.Runtime.Remoting.Messaging.StackBuilderSink.PrivateProcessMessage(RuntimeMethodHandle md, Object[] args, Object server, Int32 methodPtr, Boolean fExecuteInContext, Object[]& outArgs)
at System.Runtime.Remoting.Messaging.StackBuilderSink.SyncProcessMessage(IMessage msg, Int32 methodPtr, Boolean fExecuteInContext)
 
Exception rethrown at [0]:
at System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage reqMsg, IMessage retMsg)
at System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& msgData, Int32 type)
at OpenOfficeService.Objects.IReceiver.ConvertToPDF(String source)
at PDFWeb._Default.ExcelToPDFButton_Click(Object sender, EventArgs e) in E:\Projecten\Demos\PDFGeneration\PDFWeb\Default.aspx.cs:line 40
at System.Web.UI.WebControls.Button.OnClick(EventArgs e)
at System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument)
at System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument)
at System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument)
at System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData)
at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
 
Can someone help me with this?
AnswerRe: Method not found: 'unoidl.com.sun.star.uno.XComponentContext uno.util.Bootstrap.bootstrap()'."}memberMember 955983130-Jan-13 16:39 
Pls refer to Comments and Discussions of below URL
,What Predrag Tomasevic said at 30 Jan '09 - 1:11
Generate PDF Using C#[^]
QuestionOther uses as a servicememberzaf16-May-12 20:51 
I would like to use OO as a server side spreadsheet engine to create functionality similar to Excel Services provided by Sharepoint. Any idea where I can get documentation and samples of how calls are made. I have searched a lot but it seems all the examples are about converting to PDF.
QuestionWindows Servicememberjedchan19-Mar-12 4:07 
I can't find file %OOInstallPath%\share\registry\data\org\openoffice\Setup.xcu in openoffice 3.3
can you help me?
thanks
GeneralMy vote of 2memberalireza azarang20-Sep-11 23:14 
needs an installation application
Generali´m missing something?memberWilmer Cárdenas9-Jun-11 11:23 
Hi, great work! but when i tried it throws an error:
Can´t find file: "C:\Windows\system32\config\systemprofile\AppData\Local\gnr-destination-1839750680-634432289671224350.pdf" with both buttons ("Give me pdf from wordML" and "Give me pdf from excel" )
 
in the lines:
byte[] result = OpenOfficeService.Objects.GenericSender.Receiver.ConvertToPDF(wordML);
or
byte[] result = OpenOfficeService.Objects.GenericSender.Receiver.ConvertToPDF(source);
 
respectively.
I´m working on win 7 x64 visual studio 2010 and Open Office 3.1, and i´ve followed the instructions in the post for setting environment variables, and etc...from goa_kiwi´s post...did i miss something?
GeneralRe: i´m missing something?membergeneral_aelius21-Jun-12 5:35 
I've got also the same issue on another installation of mine..did you manage to solve it?
GeneralMy vote of 1membergowthammanju10-May-11 21:02 
i can not find the solution for this problem can u guide me
GeneralSecuring the PDFmembermarc lang6-Jan-11 1:39 
Hi,
 
I have got the conversion working fine now in 2.4.1.
 
I now want to manipulate the PDF to amend the permissions.
 
I have used this page as a reference:
 
http://wiki.services.openoffice.org/wiki/API/Tutorials/PDF_export#Security
 
And my code in saveDocument now looks like:
 
 
// Exporting to PDF consists of giving the proper
            // filter name in the property "FilterName"
            // With only this, the WHOLE document will be exported
            // using the existing PDF export settings
            // (the one used the last time, or the default if the first time)
            unoidl.com.sun.star.beans.PropertyValue[] aMediaDescriptor = new unoidl.com.sun.star.beans.PropertyValue[2];
 
            aMediaDescriptor[0] = new unoidl.com.sun.star.beans.PropertyValue();
            aMediaDescriptor[0].Name = "FilterName";
            aMediaDescriptor[0].Value = new uno.Any("writer_pdf_Export");
 
            // By adding the "FilterData" we can control what is exported and how
            // For example, we will export ONLY the current selection
            // it's a collection of 5 properties
            unoidl.com.sun.star.beans.PropertyValue[] aFilterData 
                = new unoidl.com.sun.star.beans.PropertyValue[5];
 

            aFilterData[0] = new unoidl.com.sun.star.beans.PropertyValue();
            aFilterData[0].Name = "Printing";
            //* 0 = The document cannot be printed.
            //* 1 = The document can be printed at low resolution only.
            //* 2 = The document can be printed at maximum resolution. 
            if (permitPrinting)
            { aFilterData[0].Value = new uno.Any(2); }
            else
            { aFilterData[0].Value = new uno.Any(0); }
            
 
            aFilterData[1] = new unoidl.com.sun.star.beans.PropertyValue();
            aFilterData[1].Name = "Changes";
            //* 0 = The document cannot be changed.
            //* 1 = Inserting deleting and rotating pages is allowed.
            //* 2 = Filling of form field is allowed.
            //* 3 = Both filling of form field and commenting is allowed.
            //* 4 = All the changes of the previous selections are permitted, with the only exclusion of page extraction (copy).  
            if (permitChanges)
            { aFilterData[1].Value = new uno.Any(4); }
            else
            { aFilterData[1].Value = new uno.Any(0); }
 

 
            aFilterData[2] = new unoidl.com.sun.star.beans.PropertyValue();
            aFilterData[2].Name = "EnableCopyingOfContent";
            if (permitCopyingOfContent)
            { aFilterData[2].Value = new uno.Any(true); }
            else
            { aFilterData[2].Value = new uno.Any(false); }
 

            aFilterData[3] = new unoidl.com.sun.star.beans.PropertyValue();
            aFilterData[3].Name = "RestrictPermissions";
            aFilterData[3].Value = new uno.Any(true);
 

            aFilterData[4] = new unoidl.com.sun.star.beans.PropertyValue();
            aFilterData[4].Name = "PermissionPassword";
            aFilterData[4].Value = new uno.Any("password");
 

            // Apply filter settings to the media (document)
            aMediaDescriptor[1] = new unoidl.com.sun.star.beans.PropertyValue();
            aMediaDescriptor[1].Name = "FilterData";
            aMediaDescriptor[1].Value = new uno.Any(typeof(unoidl.com.sun.star.beans.PropertyValue[]), aFilterData);
 
            //RestrictPermissions

 
            if (isDebugEnabled) { log.DebugFormat("Attempting to store to URL {0}", fileName); }
 
            ((XStorable)xComponent).storeToURL(fileName, aMediaDescriptor);
 
 

The document does come out with "SECURE" in the Window title when opened, so something has happened, but all the permissions such as Allow Printing still seem to be set as "Allowed"
 
Has anyone had any luck with this?
GeneralRe: Securing the PDFmembermarc lang6-Jan-11 1:55 
Spent an hour on this, then as soon as I posted I realised what it was.
 
The values being passed in above (permitChanges etc) were incorrect.
 
The code above works perfectly, so anyone wanting to implement security - there it is!
GeneralFiles being lockedmembermarc lang23-Dec-10 4:18 
Hi,
 
I have this working - kinda!
Using OO 3.2, followed the steps in other thread and have it generating a PDF.
 
However. in the "finally" block after it has read the bytes from the PDF and returns them, my client is getting the error:
 
The process cannot access the file 'C:\Documents and Settings\Default User\Local Settings\Application Data\gnr-source-541841103-634287140951073780.xml' because it is being used by another process.
 
So looks as though the XML file is locked?
 
Has anyone else experienced this?
 
Bit of a shame, looks like it's going to leave the temp files on the server.
 
I may try roll back to OO 2.4 to see if it helps
GeneralRe: Files being lockedmembermarc lang23-Dec-10 5:36 
Ahhh!
 
Rolled back to 2.4, implemented log4net
 
now getting:
 
RROR 2010-12-23 16:32:49,580 ConversionToPDF Generate - Exception caught: unoidl.com.sun.star.uno.RuntimeException: [map_to_uno():[]com.sun.star.beans.PropertyValue] conversion failed
[map_to_uno():unoidl.com.sun.star.beans.PropertyValue.Value [map_to_uno():any] could not convert type!
 
Server stack trace:
 

Exception rethrown at [0]:
at System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage reqMsg, IMessage retMsg)
at System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& msgData, Int32 type)
at unoidl.com.sun.star.frame.XStorable.storeToURL(String sURL, PropertyValue[] lArguments)
at OpenOfficeWrapper.ConversionToPDF.saveDocument(XComponent xComponent, String fileName)
 

Looks like it's the line storeToURL
 
propertyValue[0] = new unoidl.com.sun.star.beans.PropertyValue();
propertyValue[0].Name = "FilterName";
propertyValue[0].Value = new uno.Any("writer_pdf_Export");
 
if (isDebugEnabled) { log.DebugFormat("Attempting to store to URL {0}", fileName); }
 
((XStorable)xComponent).storeToURL(fileName, propertyValue);
 

Is it not recognising the "writer_pdf_Export"?
GeneralWindows Servicemembertiutababo29-Dec-09 22:46 
Is there a way to get this to run with as localsystem instead of admin groups?
Generalproblemmembersuppergosc7-Jun-09 4:41 
i, I've tried to run this code and I god exception:
 
No connection could be made because the target machine actively refused it 127.0.0.1:6542
 
in line:
 
[Default.aspx.cs - line: 22] byte[] result = OpenOfficeService.Objects.GenericSender.Receiver.ConvertToPDF(wordML);
 
any ideas what can be wrong?
GeneralRe: problemmemberWilmer Cárdenas9-Jun-11 11:01 
did you check if the service is properly installed and started?, when the connection is refussed it´s due there's nothing listening in that port
GeneralTimeout for LoadingmemberMember 438015726-Apr-09 9:15 
Great code, thanks for the contribution.   I made a small modification to support an application I developed that performs batch processing.   After 20 seconds of trying to load a file I have the system stop.   In my case, when trying to load a file that was password protected the system would hang indefinitely.   Additional recommendations would be to set the time out as a function of the input file size.
 
//Load the sourcefile
                        XComponent xComponent = aLoader.loadComponentFromURL(sourcePath, "_blank", 0,
                           new unoidl.com.sun.star.beans.PropertyValue[0]);
 
                        //Wait for loading
                        int sleepCount = 0;
                        while (xComponent == null)
                        {
                              System.Threading.Thread.Sleep(1000);
                              sleepCount++;
 
                              if (sleepCount > 20)
                              {
                                   
                                    return "";
                              }
                        }
GeneralDocument is no good in OOmembermrdajma6662-Mar-09 6:12 
I created XML document (WordML) and when opened in OpenOffice, there are no pictures and formatting of text is quite different.
Is there any way for the document to looks the same in MS Office and Open Office ?
GeneralAnother easy solution to create PDF from C#memberbazooka7628-Feb-09 7:24 
This was a good article.. If you are looking to create PDF with data in XML another easy and free option is to use NFOP. Check this article out for a clear step by step instruction to generate PDF from C#
 
http://www.codelathe.com/blog/index.php/2009/02/28/generate-pdf-from-cnet/
GeneralPerformancemembermjmim2-Feb-09 5:51 
Great idea! how is it performance wise?
Approximately how much time does it take for an average web page (in seconds)?
GeneralRe: PerformancememberPredrag Tomasevic2-Feb-09 15:56 
This solution definitely isn't for hi-load scenarios... but you can expect about 1 conversion per 3 seconds (on average 1 page A4 document).
GeneralAlternative solutionmemberzlezj1-Feb-09 21:09 
When creating reports from third party applications, an alternative solution could be printing the document using PDF Creator[^]
GeneralRe: Alternative solutionmemberPredrag Tomasevic2-Feb-09 16:04 
The problem with PDF Creator (and all other free PDF printers) is that something needs to trigger them (Word, OpenOffice, some other program), unless developer wishes to send direct print commands (and most of the developers don't want to do that).
 
So, for conversion from other document types PDF Creator is pretty much useless. But, if someone wants to go with PDF Creator using C# for whatever reason, take a look at this link -> http://angrez.blogspot.com/2007/06/create-pdf-in-net-using-pdfcreator.html[^]
QuestionWill this support Unicode characters?memberDINTO22-Jan-09 2:33 
I need help in generating PDF with Unicode characters, like I want to make PDFs in different languages like Russian, Japanese, Arabic, german etc. Is it possible with this component?
 
D
AnswerRe: Will this support Unicode characters?memberPredrag Tomasevic29-Jan-09 19:15 
I don't see why it wouldn't work. Download source, run it and try processing your documents...
AnswerRe: Will this support Unicode characters?memberDev. Heba11-Feb-09 9:06 
I also need a way to support Arabic text Frown | :(
I tried to search and I found solutions but none was ideal to solve the problem!
AnswerRe: Will this support Unicode characters?memberDev. Heba20-Feb-09 12:08 
Sleepy | :zzz:
GeneralNo need for $1000 worth librariesmemberSasa Popovic19-Jan-09 10:51 
Nice article but in my oppinion too much workarounds when there is a free and open source library for elegant PDF generation. You can check it here: http://itextsharp.sourceforge.net/[^].
 
I used it on commercial products with heavy load and a lot of PDF generation. Works like a charm and you don't need to install anything on production server in order for it to generate PDF files.
 

GeneralRe: No need for $1000 worth librariesmemberPredrag Tomasevic29-Jan-09 18:02 
http://www.codeproject.com/KB/files/generatepdf.aspx?fid=1517061&df=90&mpp=50&noise=3&sort=Position&view=Quick&select=2650633#xx2650633xx[^]
GeneralRe: No need for $1000 worth librariesmemberSasa Popovic29-Jan-09 22:00 
I'm sorry, I didn't saw the other comment about iTextSharp.
 
You have a point about it being a matter of taste Smile | :)
 

GeneralI need help, please. [modified]memberducero19-Jan-09 3:56 
Hello, first sorry for my English. I am Spanih.
 
I am trying to use the code of this article, into web app (ASP.NET) with .net framework 2.0 into VS2005, and OO 3.0, but not work. I run my app into VS2005 own web server. When i run app, an error was occurred in this line:
 
Dim Resul As Byte() = OpenOfficeService.Objects.GenericSender.Receiver.ConvertToPDF(PDF)
 
that say: Method not found. 'unoidl.com.sun.star.uno.XComponentContext uno.util.Bootstrap.bootstrap()'
 
Thanks a lot.
 
modified on Monday, January 19, 2009 10:06 AM

GeneralRe: I need help, please.memberPredrag Tomasevic19-Jan-09 7:28 
The problem is that you are using OpenOffice 3.0 - code is made for OpenOffice 2.4.1
 
I've found OpenOffice 2.4.2 on this address -> http://download.openoffice.org/2.4.2/index.html[^]. Until I port code for OO 3.0 can you try to use that version?
GeneralRe: I need help, please.memberPredrag Tomasevic29-Jan-09 19:12 
http://www.codeproject.com/KB/files/generatepdf.aspx?fid=1517061&select=2903150&fr=1#xx2903150xx[^]
QuestionHow to avoid Random string on the top of PDFs generatedmemberVijay Pandey15-Jan-09 22:14 
Hi,
 
Thank you for posting some good article on open office. When I convert an HTML file to PDF, PDF file always contains a string  . Can we avoid this string.
 
Thank You
AnswerRe: How to avoid Random string on the top of PDFs generatedmemberPredrag Tomasevic29-Jan-09 19:16 
I can't reproduce your problem (and I never got  when converting my files). If you can, send me a link to your HTML and I'll try to help you.
AnswerRe: How to avoid Random string on the top of PDFs generatedmembermindking6-May-09 22:18 
I need help with this as well , is there a way to remove the characters
AnswerRe: How to avoid Random string on the top of PDFs generatedmemberMarek.T18-Jan-10 7:33 
What you are seeing is the byte order mark. There is a bug in the code that binds it to a particular Encoding.Default for the environment it is running in. I have not looked at the code though, so I have no idea where the bug may be. For details, see e.g. here: http://stackoverflow.com/questions/288111/remove-byte-order-mark-from-a-file-readallbytes-byte[^]
GeneralOpenOffice 3memberagentone7-Jan-09 3:55 
Can you maybe explain detailed (step-by-step) how you have solve it and run it with OpenOffice 3? I really have try it now many hours and it will not work.
GeneralRe: OpenOffice 3membergoa_kiwi7-Jan-09 9:40 
Hi. Refer to reply below by clicking here [^]
GeneralRe: OpenOffice 3memberPredrag Tomasevic29-Jan-09 19:13 
http://www.codeproject.com/KB/files/generatepdf.aspx?fid=1517061&select=2903150&fr=1#xx2903150xx[^]
QuestionCan the code be used with the dot net 2.0membersharma.monal29-Dec-08 2:22 
As I dont have visual studio 2008 I want to ask if the code and the dll can be used with the framework 2.0 or framework 1.1.
Thanks
AnswerRe: Can the code be used with the dot net 2.0memberPredrag Tomasevic29-Dec-08 6:49 
Code doesn't contain any .NET 3.5 specifics... (there are only couple of using System.Linq statements that you need to delete).
 
You can download source and use some kind of downgrading utility (like this one http://mises.com/blogs/misestech/VisualStudioProjectDowngrade.zip[^]) to convert project to VS 2005.
 
P.
GeneralOpen Office 3membergoa_kiwi20-Nov-08 11:33 
Hi, I have a .Net windows service that uses OO. It took me a while to get this going under Server 2003, but after coming across your awesome article I finally got it going by setting the PATH environment variable amd setting the OO license agreement to accepted (Setup.xcu).
 
However, we have recently upgraded to OO3 and now its not working!
 
One thing I have noticed is that the OO dlls have now moved and are now under C:\Program Files (x86)\OpenOffice.org 3\URE\bin and C:\Program Files (x86)\OpenOffice.org 3\Basis\program. I have added both these to the path environment variable but still no luck.
 
I have noted the license agreement files (Setup.xcu) has also changed location, but I have updated this to auto-accept license, but no luck there either.
 
Any ideas?
GeneralRe: Open Office 3membergoa_kiwi26-Nov-08 9:32 
I finally got this going Big Grin | :-D . In order to use Open Office 3 from a windows service you need to add some additional environment settings as detailed here: http://blog.nkadesign.com/2008/net-working-with-openoffice-3/
 
Basically the below (using standard installation paths):
- Append to PATH variable C:\Program Files\OpenOffice.org 3\URE\bin.
- Create a UNO_PATH variable with C:\Program Files\OpenOffice.org 3\program.
 
Also to now accept the license agreements for all users, etc, what I do is first open up Open Office with an existing user, accept the license agreement, and I then copy that users Open Office profile (from documents and settings) to the Defualt user profile.
GeneralRe: Open Office 3memberagentone7-Jan-09 3:55 
Can you maybe explain detailed (step-by-step) how you have solve it and run it with OpenOffice 3? I really have try it now many hours and it will not work.
GeneralRe: Open Office 3membergoa_kiwi7-Jan-09 9:33 
Remember my suggested fix was for a Windows Server 2003 (x64) machine, and was also for my own code... I have not tested it with the code supplied in this article (although it shouldn't make a difference).
 
I have just noticed my original answer had slightly incorrect paths (missing "x86" extension). Also on my last install I still hit an issue and had to perform what I detail in step 6 below. But I have now got this going on 3 seperate Server 2003 machines, and so it should work for you.

 
Here are the instructions step by step. Note I am assuming standard installation paths:
 
1) Change/Add the following environmental varibles (Available in the Advanced tab, under My Computer properties).
- Append to PATH variable "C:\Program Files (x86)\OpenOffice.org 3\URE\bin" (and also remove any Open Office paths you might have added previously)
- Create a UNO_PATH variable with "C:\Program Files (x86)\OpenOffice.org 3\program"
 
2) Accept Open Office license agreements for all users. I do this by first opening up Open Office manually with an existing user and accepting license aggreements, etc. I then copy that users Open Office profile (C:\Documents and Settings\[Username]\Application Data\OpenOffice.org) to the Default user profile (C:\Documents and Settings\Default User\Application Data\).
 
3) Restart machine for settings to take affect
 
4) Install Service. Ensure it is set to run under the 'Local System Account' with the 'Allow service to interact with desktop' right set
 
5) Start Service
 
6) If you are still having issues converting docs, try the following:
- stop the service
- set the service to run under the administrator account
- start it
- try to convert a document (it should work)
- stop the service again
- set service to run under the 'Local System Account' again with the 'Allow service to interact with desktop' right set
- start the service
GeneralRe: Open Office 3memberagentone7-Jan-09 22:33 
Thank you for you fast reply. I still have same problems with this script.. I get each time the error (ASP.NET site) method not found: unoidl.com.sun.star.uno.XComponentContext uno.util.Bootstrap.bootstrap().
Maybe you can give me your eMail adress?
GeneralRe: Open Office 3membergoa_kiwi8-Jan-09 9:37 
Hmmm... like I said above I am using my own pdf conversion code (using Open Office). Given you are having an issue with the code in this article, maybe the articles author (Predrag Tomasevic) would be better based to give you further suggestions.
GeneralRe: Open Office 3memberagentone8-Jan-09 23:51 
Maybe there is a way that you give me your solution?

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Permalink | Advertise | Privacy | Mobile
Web03 | 2.6.130617.1 | Last Updated 2 Feb 2009
Article Copyright 2008 by Predrag Tomasevic
Everything else Copyright © CodeProject, 1999-2013
Terms of Use
Layout: fixed | fluid