Hello, you can try below code:
private void BtnSave_Click(object sender, EventArgs e)
{
if (this.pdfDocumentViewer1.PageCount > 0)
{
SaveFileDialog dialog = new SaveFileDialog();
dialog.Filter = "PDF document (*.pdf)|*.pdf";
DialogResult result = dialog.ShowDialog();
string fileName = dialog.FileName;
if (result == DialogResult.OK)
{
pdfDocumentViewer1.SaveToFile(fileName);
MessageBox.Show("You have saved this PdfDocuemnt as:\n" + fileName, "Spire.PdfViewer Demo", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
}
}
private void BtnSaveStream_Click(object sender, EventArgs e)
{
if (this.pdfDocumentViewer1.PageCount > 0)
{
SaveFileDialog dialog = new SaveFileDialog();
dialog.Filter = "PDF document (*.pdf)|*.pdf";
DialogResult result = dialog.ShowDialog();
string fileName = dialog.FileName;
if (result == DialogResult.OK)
{
MemoryStream stream = new MemoryStream();
pdfDocumentViewer1.SaveToFile(stream);
byte[] fileBytes = stream.ToArray();
FileStream fileStream = new FileStream(fileName, FileMode.Create, FileAccess.ReadWrite);
fileStream.Write(fileBytes, 0, fileBytes.Length);
fileStream.Flush();
fileStream.Close();
stream.Close();
MessageBox.Show("You have first saved this PDF docuemnt as memory stream,\nthen write the memory stream in a file :\n" + fileName, "Spire.PdfViewer Demo", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
}
}
}