Table in PDF Footer

Hello ,

i need Help. I have an PDF and want add an footer, in table format.
My Error :
You are in direct-to-file mode,please use Close() instead of Save().

I can not save Documents, where is my mistake?


Aspose.Pdf.Generator.Pdf pdfConv = new Aspose.Pdf.Generator.Pdf(inStream);

//Create a section in the pdf document
Aspose.Pdf.Generator.Section sec1 = pdfConv.Sections.Add();

// Create a Header Section of the PDF file
Aspose.Pdf.Generator.HeaderFooter header = new Aspose.Pdf.Generator.HeaderFooter(sec1);

//Create a section in the pdf document
Aspose.Pdf.Generator.Section sec1 = pdfConv.Sections.Add();

// Create a Header Section of the PDF file
Aspose.Pdf.Generator.HeaderFooter header = new Aspose.Pdf.Generator.HeaderFooter(sec1);

.................

MemoryStream outStream = new MemoryStream();
outStream.Seek(0, SeekOrigin.Begin);
pdfConv.Save(outStream);
My Error :
You are in direct-to-file mode,please use Close() instead of Save().

pdfConv.Close();

Object reference not set to an instance of an object.

Hi lothar,

Thank you for considering Aspose.Pdf.

As per your requirement, you need to add footer in an existing PDF document. If that is the case, then you cannot user Aspose.Pdf.Generator namespace. Aspose.Pdf.Generator is used to create new PDF documents from scratch and you cannot use it to modify the PDF document. You can use Aspose.Pdf DOM or Aspose.Pdf.Facades to modify the existing PDF files.

Now, regarding adding Footer in an existing PDF file, please see the following links:

Adding Text in Footer of PDF File

Adding Image in Footer of PDF File

Add Footer in a PDF File (Facades)

Add Image in Footer of an Existing PDF File (Facades)

However, adding table in footer of existing PDF file is not supported at the moment. I have registered a new feature request in our issue tracking system with issue id: PDFNEWNET-34055. Our development team will further look into this feature and we will update you if this feature can be supported soon via this forum thread.

You may check the following documentation link which explains the feature to add a table in an existing PDF file and see if it can fit your needs.

Sorry for the inconvenience,

Hi Aslam,

Thank you!

Now I create an document with my table, save it as an image and I place the image in my PDF Footer.

The problem is, ever I get the total page as image, but I need only my table.

How can I do it?

Hi Lothar,


Thanks for using our products.

The reason you have been getting “You are in direct-to-file mode,please use Close() instead of Save().” is because you have passed InputStream as an argument to Pdf instance and when using this approach, as specified in error message, please try using Close(…) method instead of Save(…). For further details, please visit Writing PDF directly

Besides this, if you need to get the image of specific page region, first you may consider changing the page region to the point where only the Footer area is visible and then try converting that updated document into Image format. Please take a look over the following code snippet which I have used to move the origin/position of PDF file to specific point and then have tried converting it into Image format.

[C#]

// instantiate
PdfPageEditor class to get particular page region<o:p></o:p>

Aspose.Pdf.Facades.PdfPageEditor editor = new Aspose.Pdf.Facades.PdfPageEditor();

// bind the source PDF file

editor.BindPdf("D:\\pdftest\\MSA407704.pdf");

// move the origin of PDF file to particular point

editor.MovePosition(0, 700);

// create a memory stream object

MemoryStream ms = new MemoryStream();

// save the updated doument to stream object

editor.Save(ms);

//open document

Aspose.Pdf.Document pdfDocument = new Aspose.Pdf.Document(ms);

using (FileStream imageStream = new FileStream("D:\\pdftest\\MSA407704_Extracted.jpeg", FileMode.Create))

{

//create JPEG device with specified attributes

//create Resolution object

Aspose.Pdf.Devices.Resolution resolution = new Aspose.Pdf.Devices.Resolution(300);

JpegDevice jpegDevice = new JpegDevice(resolution, 100);

//convert a particular page and save the image to stream

jpegDevice.Process(pdfDocument.Pages[1], imageStream);

//close stream

imageStream.Close();

}

// close MemoryStream object holding the updated document

ms.Close();

The issues you have found earlier (filed as PDFNEWNET-34055) have been fixed in Aspose.Pdf for .NET 7.7.0.


This message was posted using Notification2Forum from Downloads module by aspose.notifier.