<< Click to Display Table of Contents >> Navigation: Example Projects > .NET C# Example: PDFViewNET |
The component has been dropped on the from. It is initialized like this:
public Form1()
{
InitializeComponent();
pdfViewer1.ViewerStart("xxx", "yyy", 0);
pdfViewer1.ViewOptions = eViewOptions.wpExpandAllBookmarks |
eViewOptions.wpExpandAllBookmarks |
eViewOptions.wpSelectPage |
eViewOptions.wpShowPageSelection;
pdfViewer1.ViewControls =
eViewControls.wpHorzScrollBar |
eViewControls.wpNavigationPanel |
eViewControls.wpPropertyPanel |
eViewControls.wpVertScrollBar |
eViewControls.wpViewPanel;
pdfViewer1.Command(commands.COMPDF_SetDocumentProperties, "Eigenschaften");
}
Load and append PDF files:
private void loadToolStripMenuItem1_Click(object sender, EventArgs e)
{
if (openFileDialog1.ShowDialog() == DialogResult.OK)
{
pdfViewer1.LoadFromFile(openFileDialog1.FileName);
}
}
private void appendToolStripMenuItem_Click(object sender, EventArgs e)
{
if (openFileDialog1.ShowDialog() == DialogResult.OK)
{
pdfViewer1.AppendFromFile(openFileDialog1.FileName);
}
}
Show the print dialog:
private void Print_Click(object sender, EventArgs e)
{
pdfViewer1.Command(commands.COMPDF_PrintDialog);
}
Implement the find method. It will locate next location unless the string was changed:
static string LastFind;
private void FindBtn_Click(object sender, EventArgs e)
{
int p = pdfViewer1.FindText(FindTextEdit.Text, true, LastFind == FindTextEdit.Text, true, true);
if (p < 0) MessageBox.Show("Text not found.");
LastFind = FindTextEdit.Text;
}
Implement saving to a new PDF file (requires Demo or PLUS license)
private void pDFToolStripMenuItem_Click(object sender, EventArgs e)
{
saveFileDialog1.Filter = "PDF Files|*.PDF";
if (saveFileDialog1.ShowDialog() == DialogResult.OK)
{
if (!pdfViewer1.Plus.SaveToFile(saveFileDialog1.FileName))
MessageBox.Show("Saving the file was not successful!");
}
}
Create a bitmap from the current page. Possible formats are BMP, PNG and JPEG. It simply uses the caption of the sender menu item.
private void jPEGToolStripMenuItem_Click(object sender, EventArgs e)
{
saveFileDialog1.Filter = ((ToolStripMenuItem)sender).Text + " Files|*." + ((ToolStripMenuItem)sender).Text;
if (saveFileDialog1.ShowDialog ()== DialogResult.OK)
{
if (!pdfViewer1.WriteBitmap(pdfViewer1.Page-1, BitmapFormat.Automatic, saveFileDialog1.FileName))
MessageBox.Show("Saving the file was not successful!");
}
}
Rotate the selected pages
private void RotateBtn_Click(object sender, EventArgs e)
{
pdfViewer1.Command(commands.COMPDF_RotatePage, "selected", -90);
}
Switch between select and pan mouse mode
private void SelectBtn_Click(object sender, EventArgs e)
{
SelectBtn.Checked = !SelectBtn.Checked;
if (SelectBtn.Checked)
pdfViewer1.Command(commands.COMPDF_SelectMode, 1);
else pdfViewer1.Command(commands.COMPDF_SelectMode, 0);
}