saving a pdf file


Syncfusion 4.4.

I have a pdfDocument and I want to save it as a pdf file. Here are my two questions:

1. Can I get the sample code to save the pdfDocument as a pdf file, and provide dialog for user to choose the path and name.

2. When I use the following code to save the file:
pdfDocument.Save("report.pdf");
System.Diagnostics.Process.Start("report.pdf");

The report file is saved and opened, but the file has to be closed if I want to regenerate the report, otherwise the program will crash.

Thanks a lot for helping me out.

Jane



1 Reply

MW Melba Winshia Syncfusion Team August 9, 2007 02:16 PM UTC

Hi Jane,

Thank you for your interest in Essential PDF.

Issue 1: (provide dialog for user to choose the path)
--------

You can use SaveFileDialog class to provide dialog for user to choose the path and name.

[C#]


SaveFileDialog saveFileDialog = new SaveFileDialog();
saveFileDialog.Filter = "Files(*.pdf)|*.pdf";
saveFileDialog.AddExtension = true;
saveFileDialog.DefaultExt = ".pdf";

if (saveFileDialog.ShowDialog() == DialogResult.OK && saveFileDialog.CheckPathExists)
{
//Save the PDF Document to disk.
pdfDoc.Save(saveFileDialog.FileName);
pdfDoc.Close();

//Message box confirmation to view the created PDF document.
if (MessageBox.Show("Do you want to view the PDF file?", "PDF File Created",
MessageBoxButtons.YesNo, MessageBoxIcon.Information)
== DialogResult.Yes)
{
Process proc = new Process();
proc.StartInfo.FileName = saveFileDialog.FileName;
proc.Start();
}
}

Please refer the (modified - if one is provided earlier) sample in the below link which illustrates the above.



http://websamples.syncfusion.com/samples/XlsIO.Windows/67104/main.htm


Please try running the above sample and let me know if this helps.

Issue 2: (the file has to be closed)
--------

You can close the document by using close method of PDFDocument.

[C#]

//Save
pdfDocument.Save("report.pdf");

//Close the document
pdfDoc.Close();

//Open
System.Diagnostics.Process.Start("report.pdf");

Please let me know if you have any other questions.

Thanks,
Melba

Loader.
Up arrow icon