bhagawatshinde 11 Posting Whiz

Hi guys i have generated PDF file from docx(.rtf also) You need to install bullzip printer and word.
Prerequsities - you have to add reference Bullzip.PdfWriter.
here is code snippest

internal static byte[] PrintToPdf(string appFolder, string tempDocxFileName)
        {
            try
            {
                string tempFolder = appFolder + @"\temp";
                string tempDocxFilePath = tempFolder + @"\" + tempDocxFileName;
                PdfSettings pdfSettings = new PdfSettings();
                pdfSettings.PrinterName = System.Configuration.ConfigurationManager.AppSettings["Bullzip PDF Printer"];
                string settingsFile = pdfSettings.GetSettingsFilePath(PdfSettingsFileType.Settings);
                pdfSettings.LoadSettings(appFolder + @"\App_Data\printerSettings.ini");
                pdfSettings.SetValue("Output", tempFolder + @"\<docname>.pdf");
                pdfSettings.WriteSettings(settingsFile);
                PdfUtil.PrintFile(tempDocxFilePath, pdfSettings.PrinterName);
                string tempPdfFilePath = tempFolder + @"\Microsoft Word - " + tempDocxFileName + ".pdf";
                bool fileCreated = false;
                while (!fileCreated)
                {
                    fileCreated = PdfUtil.WaitForFile(tempPdfFilePath, 1000);
                }
                byte[] pdfBytes = File.ReadAllBytes(tempPdfFilePath);
                File.Delete(tempDocxFilePath);
                File.Delete(tempPdfFilePath);
                return pdfBytes;                                               
            }
            catch (Exception ex)
            {
                return null;
            }
        }

        private void button6_Click(object sender, EventArgs e)
        {
            PrintToPdf("F:\\Bhagawat.s\\TestB", "1020000101777777180712.rtf");
        }

Dani AI

Generated

Good, practical start from — printing DOCX/RTF to PDF via Bullzip and Word is a workable approach for desktop utilities and single-user tools. A few reliability and safety tips will make this robust in more demanding environments.

Don’t rely on an infinite wait for the output file. Poll with a sensible timeout, and consider checking that the file size is stable for a short interval before treating the PDF as complete. Use a unique temp path per conversion (temporary folder or a GUID-based filename) to avoid collisions when conversions run concurrently. Always clean up temp files in a finally block and surface any exceptions instead of swallowing them so failures are diagnosable.

Be cautious about running Word automation from server processes. Automating Office on server-side apps is fragile and unsupported in many hosting scenarios: Word can hang, require an interactive desktop session, or run into permission issues. If the converter must run from a web server or handle many requests, prefer server-safe alternatives (commercial libraries like Aspose.Words or GemBox.Document, headless LibreOffice/soffice conversion, or a cloud document-conversion API) for reliability and scale.

If you stay with Bullzip+Word, make the output deterministic: configure the printer’s programmatic settings so the PDF filename is predictable rather than inferring Word’s generated name. Ensure the account running the process has printer and filesystem permissions, run COM operations on an STA thread and release COM objects promptly, and add logging around each step (settings write, print call, file-detection, cleanup). Quick checklist: confirm printer+Word are installed where the code runs, use Path.Combine/secure temp names, add timeout and stable-size checks, log full exceptions, and evaluate a server-friendly converter if this will be used in production.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.