Dim caption As String = "Example: NewOCG"
Dim gdpicturePDF As GdPicturePDF = New GdPicturePDF()
If (gdpicturePDF.NewPDF() = GdPictureStatus.OK) AndAlso
(gdpicturePDF.NewPage(PdfPageSizes.PdfPageSizeA4) = GdPictureStatus.OK) Then
'Creating content of a new layer.
Dim image_res_name As String = gdpicturePDF.AddJpegImageFromFile("image.jpg")
If gdpicturePDF.GetStat() = GdPictureStatus.OK Then
Dim width As Single = gdpicturePDF.GetPageWidth()
Dim height As Single = gdpicturePDF.GetPageHeight()
'Drawing the layer's content on the current page.
If gdpicturePDF.DrawImage(image_res_name, 0, 0, width, height) = GdPictureStatus.OK Then
'Creating the layer and setting its properties.
Dim ocgID As Integer = gdpicturePDF.NewOCG("Image layer")
If (gdpicturePDF.GetStat() = GdPictureStatus.OK) AndAlso
(gdpicturePDF.SetImageOptional(image_res_name, ocgID) = GdPictureStatus.OK) Then
If (gdpicturePDF.SetOCGExportState(ocgID, PdfOcgState.StateOff) = GdPictureStatus.OK) AndAlso
(gdpicturePDF.SetOCGLockedState(ocgID, True) = GdPictureStatus.OK) AndAlso
(gdpicturePDF.SetOCGPrintState(ocgID, PdfOcgState.StateOn) = GdPictureStatus.OK) AndAlso
(gdpicturePDF.SetOCGViewState(ocgID, PdfOcgState.StateOn) = GdPictureStatus.OK) AndAlso
(gdpicturePDF.SetOCGZoomMin(ocgID, 0) = GdPictureStatus.OK) AndAlso
(gdpicturePDF.SetOCGZoomMax(ocgID, 1) = GdPictureStatus.OK) Then
If gdpicturePDF.SaveToFile("test_NewOCG.pdf") = GdPictureStatus.OK Then
MessageBox.Show("The example HAS been followed successfully and the file has been saved.", caption)
Else
MessageBox.Show("The example HAS been followed successfully, but the file can't be saved. Status: " + gdpicturePDF.GetStat().ToString(), caption)
End If
Else
MessageBox.Show("Setting up layer's options has failed with the status: " + gdpicturePDF.GetStat().ToString(), caption)
End If
Else
MessageBox.Show("The NewOCG() or SetImageOptional() method has failed with the status: " + gdpicturePDF.GetStat().ToString(), caption)
End If
Else
MessageBox.Show("The DrawImage() method has failed with the status: " + gdpicturePDF.GetStat().ToString(), caption)
End If
Else
MessageBox.Show("The AddJpegImageFromFile() method has failed with the status: " + gdpicturePDF.GetStat().ToString(), caption)
End If
Else
MessageBox.Show("The document can't be created.", caption)
End If
gdpicturePDF.Dispose()
string caption = "Example: NewOCG";
GdPicturePDF gdpicturePDF = new GdPicturePDF();
if ((gdpicturePDF.NewPDF() == GdPictureStatus.OK) &&
(gdpicturePDF.NewPage(PdfPageSizes.PdfPageSizeA4) == GdPictureStatus.OK))
{
//Creating content of a new layer.
string image_res_name = gdpicturePDF.AddJpegImageFromFile("image.jpg");
if (gdpicturePDF.GetStat() == GdPictureStatus.OK)
{
float width = gdpicturePDF.GetPageWidth();
float height = gdpicturePDF.GetPageHeight();
//Drawing the layer's content on the current page.
if (gdpicturePDF.DrawImage(image_res_name, 0, 0, width, height) == GdPictureStatus.OK)
{
//Creating the layer and setting its properties.
int ocgID = gdpicturePDF.NewOCG("Image layer");
if ((gdpicturePDF.GetStat() == GdPictureStatus.OK) &&
(gdpicturePDF.SetImageOptional(image_res_name, ocgID) == GdPictureStatus.OK))
{
if ((gdpicturePDF.SetOCGExportState(ocgID, PdfOcgState.StateOff) == GdPictureStatus.OK) &&
(gdpicturePDF.SetOCGLockedState(ocgID, true) == GdPictureStatus.OK) &&
(gdpicturePDF.SetOCGPrintState(ocgID, PdfOcgState.StateOn) == GdPictureStatus.OK) &&
(gdpicturePDF.SetOCGViewState(ocgID, PdfOcgState.StateOn) == GdPictureStatus.OK) &&
(gdpicturePDF.SetOCGZoomMin(ocgID, 0) == GdPictureStatus.OK) &&
(gdpicturePDF.SetOCGZoomMax(ocgID, 1) == GdPictureStatus.OK))
{
if (gdpicturePDF.SaveToFile("test_NewOCG.pdf") == GdPictureStatus.OK)
{
MessageBox.Show("The example HAS been followed successfully and the file has been saved.", caption);
}
else
{
MessageBox.Show("The example HAS been followed successfully, but the file can't be saved. Status: " + gdpicturePDF.GetStat().ToString(), caption);
}
}
else
{
MessageBox.Show("Setting up layer's options has failed with the status: " + gdpicturePDF.GetStat().ToString(), caption);
}
}
else
{
MessageBox.Show("The NewOCG() or SetImageOptional() method has failed with the status: " + gdpicturePDF.GetStat().ToString(), caption);
}
}
else
{
MessageBox.Show("The DrawImage() method has failed with the status: " + gdpicturePDF.GetStat().ToString(), caption);
}
}
else
{
MessageBox.Show("The AddJpegImageFromFile() method has failed with the status: " + gdpicturePDF.GetStat().ToString(), caption);
}
}
else
{
MessageBox.Show("The document can't be created.", caption);
}
gdpicturePDF.Dispose();