Free Support Forum - aspose.com

Saved file is corrupt

Hi, We are evaluating your product for purchase. Can you please assist with the following functionality? currently when I attempt to save a PDF document, the document is corrupt when i try to view it via adobe reader. Code below: Pdf pdf = new Pdf(stream); Text text = new Text("COPY ONLY"); text.TextInfo.Alignment = Aspose.Pdf.Generator.AlignmentType.Center; text.TextInfo.Color = new Aspose.Pdf.Generator.Color(220, 220, 220); text.TextInfo.FontSize = 40; text.TextInfo.FontName = "HELVETICA"; float textAngle = 45.0f; text.RotatingAngle = textAngle;
                FloatingBox watermark = new FloatingBox(500, 200);
                watermark.BoxVerticalPositioning = BoxVerticalPositioningType.Margin;
                watermark.BoxVerticalAlignment = BoxVerticalAlignmentType.Top;
                watermark.ZIndex = -1;
                watermark.BoxHorizontalPositioning = BoxHorizontalPositioningType.Margin;
                watermark.Paragraphs.Add(text);
                pdf.Watermarks.Add(watermark);
                pdf.Close();<hr size="1" align="left" width="25%"></body></html>

Hi Turners,


Thanks for contacting support.

I have tested the scenario where I have used the following code snippet and I am able to notice MemorStream length value in output console, which indicates that PDF file is being generated.

Furthermore, I have also tried saving the output file over system by using Save method and I am able to open the resultant document in Adobe Reader 10.1.4. I have tested the scenario over Windows 7 (X64) in Visual Studio 2010 application and I have used Aspose.Pdf for .NET 7.7.0. Can you please share some details regarding your working environment.

We are sorry for this inconvenience.

[C#]

MemoryStream ms = new
MemoryStream();<o:p></o:p>

Pdf pdf = new Pdf(ms);

Section sec1 = pdf.Sections.Add();

Text text = new Text("COPY ONLY");

text.TextInfo.Alignment = Aspose.Pdf.Generator.AlignmentType.Center;

text.TextInfo.Color = new Aspose.Pdf.Generator.Color(220, 220, 220);

text.TextInfo.FontSize = 40;

text.TextInfo.FontName = "HELVETICA";

float textAngle = 45.0f;

text.RotatingAngle = textAngle;

sec1.Paragraphs.Add(text);

FloatingBox watermark = new FloatingBox(500, 200);

watermark.BoxVerticalPositioning = BoxVerticalPositioningType.Margin;

watermark.BoxVerticalAlignment = BoxVerticalAlignmentType.Top;

watermark.ZIndex = -1;

watermark.BoxHorizontalPositioning = BoxHorizontalPositioningType.Margin;

watermark.Paragraphs.Add(text);

pdf.Watermarks.Add(watermark);

sec1.Paragraphs.Add(watermark);

//pdf.Save("c:/pdftest/WatermarkIssue.pdf");

pdf.Close();

Console.WriteLine(ms.Length);

ms.Close();


PS, I hope you fully understand that Pdf class present under Aspose.Pdf.Generator supports the creation of PDF file from scratch and it does not offer the capability to load an existing PDF file.

Thanks for responding. I too can see that the file has been generated however I am unable to open it with adobe reader. I am using VS2010 and sql server 2012 installed on a windows server 2008 machine.


We have a simple requirement to print a PDF document (generated from SSRS and stored in a byte[] or memory stream) then adding a watermark or stamp across the page with the text “COPY ONLY” then stored on disc. Can you please advise which is the best way to go about achieving this?

Thanks,

Hi Turners,


Thanks for sharing the details.

I have again tested the scenario while using the code snippet shared earlier and as per my observations, I am able to open the resultant file in Adobe Reader 10.1.4. However as per your requirements, you are generating the file from SQL Reporting services and then you need to apply watermark, so I would recommend you to please try following the instructions specified over following link Adding Text Stamp in the PDF File.

Please note that Pdf class present under Aspose.Pdf.Generator only supports the feature to create PDF files from scratch and it does not offer the capability to manipulate existing PDF files. In the event of any further query, please feel free to contact.