Rank: Member
Groups: Registered
Joined: 9/19/2019(UTC) Posts: 21  Location: Landshut Thanks: 1 times
|
I am doing something wrong. I am getting an error (Fatal Error, Number 1002) b = Patagames.Pdf.Pdfium.FPDF_GenerateContentToStream (doc.Handle, ocg2.Handle, stream.Handle, page.Dictionary ("Resources"). Handle) An attempt was made to read in the protected memory. Code:private void OptionalContent1()
{
string FileName = "";
using (OpenFileDialog ofd = new OpenFileDialog())
{
{
var withBlock = ofd;
withBlock.Title = "Datei öffnen";
withBlock.Filter = "Portable Document Format (PDF) | *.pdf";
withBlock.Multiselect = false;
if (withBlock.ShowDialog == Windows.Forms.DialogResult.OK)
FileName = withBlock.FileName;
}
}
if (FileName.Length == 0 || !System.IO.File.Exists(FileName))
return;
using (var doc = Patagames.Pdf.Net.PdfDocument.Load(FileName))
{
var page = doc.Pages(0);
var contentsArray = ConvertContentsToArray(page);
var ocg1 = Patagames.Pdf.Net.BasicTypes.PdfTypeDictionary.Create();
ocg1("Type") = Patagames.Pdf.Net.BasicTypes.PdfTypeName.Create("OCG");
ocg1("Name") = Patagames.Pdf.Net.BasicTypes.PdfTypeString.Create("Group 1");
var ocg2 = Patagames.Pdf.Net.BasicTypes.PdfTypeDictionary.Create();
ocg2("Type") = Patagames.Pdf.Net.BasicTypes.PdfTypeName.Create("OCG");
ocg2("Name") = Patagames.Pdf.Net.BasicTypes.PdfTypeString.Create("Group 2");
var textObj1 = Patagames.Pdf.Net.PdfTextObject.Create("Optional text 1", 40, 50, Patagames.Pdf.Net.PdfFont.CreateStock(doc, Patagames.Pdf.Enums.FontStockNames.Arial), 40);
var textObj2 = Patagames.Pdf.Net.PdfTextObject.Create("Optional text 2", 40, 90, Patagames.Pdf.Net.PdfFont.CreateStock(doc, Patagames.Pdf.Enums.FontStockNames.Arial), 40);
var textObj3 = Patagames.Pdf.Net.PdfTextObject.Create("Optional text 3", 40, 120, Patagames.Pdf.Net.PdfFont.CreateStock(doc, Patagames.Pdf.Enums.FontStockNames.Arial), 40);
textObj1.MarkedContent.Add(new Patagames.Pdf.Net.PdfMarkedContent("OC", false, Patagames.Pdf.Enums.PropertyListTypes.PropertiesDict, ocg1));
textObj2.MarkedContent.Add(new Patagames.Pdf.Net.PdfMarkedContent("OC", false, Patagames.Pdf.Enums.PropertyListTypes.PropertiesDict, ocg1));
textObj3.MarkedContent.Add(new Patagames.Pdf.Net.PdfMarkedContent("OC", false, Patagames.Pdf.Enums.PropertyListTypes.PropertiesDict, ocg2));
var lineObj1 = InsertLine(new PointF(10, 10), new PointF(100, 100), Patagames.Pdf.FS_COLOR.Blue);
lineObj1.MarkedContent.Add(new Patagames.Pdf.Net.PdfMarkedContent("OC", false, Patagames.Pdf.Enums.PropertyListTypes.PropertiesDict, ocg2));
Patagames.Pdf.Net.PdfPathObject pathObject = Patagames.Pdf.Net.PdfPathObject.Create(Patagames.Pdf.Enums.FillModes.Alternate, false);
var rectObj = InsertRect(pathObject, new PointF(40, 150), new PointF(100, 200), Patagames.Pdf.FS_COLOR.RosyBrown);
rectObj.MarkedContent.Add(new Patagames.Pdf.Net.PdfMarkedContent("OC", false, Patagames.Pdf.Enums.PropertyListTypes.PropertiesDict, ocg2));
var list = Patagames.Pdf.Net.BasicTypes.PdfIndirectList.FromPdfDocument(doc);
var stream = Patagames.Pdf.Net.BasicTypes.PdfTypeStream.Create;
list.Add(stream);
if (!page.Dictionary.ContainsKey("Resources"))
page.Dictionary("Resources") = Patagames.Pdf.Net.BasicTypes.PdfTypeDictionary.Create();
bool b = Patagames.Pdf.Pdfium.FPDF_GenerateContentToStream(doc.Handle, ocg1.Handle, stream.Handle, page.Dictionary("Resources").Handle);
b = Patagames.Pdf.Pdfium.FPDF_GenerateContentToStream(doc.Handle, ocg2.Handle, stream.Handle, page.Dictionary("Resources").Handle);
b = Patagames.Pdf.Pdfium.FPDF_GenerateContentToStream(doc.Handle, textObj1.Handle, stream.Handle, page.Dictionary("Resources").Handle);
b = Patagames.Pdf.Pdfium.FPDF_GenerateContentToStream(doc.Handle, textObj2.Handle, stream.Handle, page.Dictionary("Resources").Handle);
b = Patagames.Pdf.Pdfium.FPDF_GenerateContentToStream(doc.Handle, textObj3.Handle, stream.Handle, page.Dictionary("Resources").Handle);
contentsArray.AddIndirect(list, stream);
using (SaveFileDialog sfd = new SaveFileDialog())
{
sfd.Title = "Testdatei speichern unter";
sfd.Filter = "Portable Document Format (PDF) | *.pdf";
if (sfd.ShowDialog == Windows.Forms.DialogResult.OK)
doc.Save(sfd.FileName, Patagames.Pdf.Enums.SaveFlags.NoIncremental);
}
}
}
Christian Edited by moderator Sunday, October 6, 2019 5:10:53 PM(UTC)
| Reason: Not specified
|