Hello,
I have problems to add a graph to a non empty pdf file.
I’ve started from the code that instantiates a Pdf object with the empty constructor, or with the FileStream of a file that is not previosly existing, and it works well:
//Create a file stream to create the PDF document
FileStream fs = new FileStream(“e:/temp/SingleSeg-d.pdf”,FileMode.Create);
//Instantiate the Pdf instance and pass the file stream object to its constructor
Pdf pdf = new Pdf(fs);
//Add a section to the PDF document
Section sec1 = pdf.Sections.Add();
//Add 1000 text paragraphs to the section
for(int i = 0; i < 1000; i++)
{
Text t = new Text("hello world hello world hello " + i.ToString());
sec1.AddParagraph(t);
}
//Close the Pdf. This method is used only for direct file mode
pdf.Close();
Then, I modified it so the Pdf object is instantiated from the opened filestream
of an existing pdf file. If I do that, I get an exception when the Pdf object
either invokes close() or saves(outputFileStream). Next is the code:
string inFile = “…\Example_Raw_Multipage_PDF\MOBIL-01-031-20070904.pdf”;
string outFile = “WithRectangle_1.pdf”;
FileStream inStream = new FileStream(inFile, FileMode.Open);
FileStream outputStream = new FileStream(outFile, FileMode.Create);
// —> INSTANTIATE FROM FILESTREAM OF EXISTING PDF FILE
Pdf pdf1 = new Pdf(inStream);
Section sec1 = pdf1.Sections.Add();
Graph graph1 = new Graph(sec1,100,100);
sec1.Paragraphs.Add(graph1);
Aspose.Pdf.Rectangle rect1 = new Aspose.Pdf.Rectangle(graph1,50,10,100,50);
rect1.GraphInfo.FillColor = new Color(“Red”);
rect1.GraphInfo.IsFilled = true;
rect1.GraphInfo.FillRule = “winding”; //can be “winding” or “evenodd”
Aspose.Pdf.Rectangle rect2 = new Aspose.Pdf.Rectangle(graph1, 60, 20, 50, 25);
graph1.Shapes.Add(rect1);
graph1.Shapes.Add(rect2);
//—> I GET AN ERROR IF LAST LINE IS ANY OF THESE ONES:
pdf1.Save(outputStream);
//pdf1.Close();
Can I get some help?
Thanks in advance.