Welcome to LEAD Support Forum Login | Register | Faq  

    LEAD Support Forum
  Resource to find answers and post technical questions about LEAD products.
Search    
   

Re: PDF Error - Cannot insert, delete, append or replace pages
Started by keithway at 02-19-2008 10:36. Topic has 9 replies.

Print Search « Previous Thread Next Thread »
  02-19-2008, 10:36
keithway is not online. Last active: 11/17/2008 4:57:14 PM keithway

Top 25 Posts
Joined on 01-09-2007
Posts 63
PDF Error - Cannot insert, delete, append or replace pages
Reply Quote
LT v15 for .NET...


I am getting the PDF cannot insert, delete.... error when calling the RasterCodecs.Save method on a PDF file.

We have purchased both the PDF read and PDF save tools and I am sure I am unlocking both of them (I am checking the RasterSupport.IsUnlocked method)

Any ideas?
   Report 
  02-19-2008, 15:08
Amin is not online. Last active: 10/29/2008 7:59:53 AM Amin



Top 10 Posts
Joined on 06-27-2005
Posts 748
Re: PDF Error - Cannot insert, delete, append or replace pages
Reply Quote
If you are trying to modify a PDF file, for example by appending a page to it, LEADTOOLS can only do this if the file was original created using the toolkit itself. It cannot modify files created by other PDF writers.
Amin Dodin
LEADTOOLS Technical Support

   Report 
  02-19-2008, 16:27
keithway is not online. Last active: 11/17/2008 4:57:14 PM keithway

Top 25 Posts
Joined on 01-09-2007
Posts 63
Re: PDF Error - Cannot insert, delete, append or replace pages
Reply Quote
Is there a way to tell if the loaded PDF raster image was created using the toolkit or created by another PDF writer?
   Report 
  02-19-2008, 16:32
keithway is not online. Last active: 11/17/2008 4:57:14 PM keithway

Top 25 Posts
Joined on 01-09-2007
Posts 63
Re: PDF Error - Cannot insert, delete, append or replace pages
Reply Quote
Also, upon further testing the problem persists with PDF images created by the Leadtools toolkit as well so something else must be the problem...
   Report 
  02-20-2008, 10:10
keithway is not online. Last active: 11/17/2008 4:57:14 PM keithway

Top 25 Posts
Joined on 01-09-2007
Posts 63
Re: PDF Error - Cannot insert, delete, append or replace pages
Reply Quote
So I've been looking at the Leadtools demos and trying to figure out whats going on and here's what I have found...

It seems that the problem is in the params in the Codecs.Save routine. For example, in the VBAutomationDemo the save call looks something like...

Me._codecs.Save(RasPage.Image.Clone, Me.LocalFilePath, Format, BitsPerPixel)

This works in the demo, but the demo happens to only be a one page demo.

In my actual application we are dealing with multipage PDF files and so I need to add a few parameters to my save call to take into account that the image is multipage... so my save call looks like...

Me._codecs.Save(RasPage.Image.Clone, Me.LocalFilePath, Format, BitsPerPixel, 1, 1, PageNumber, CodecsSavePageMode.Replace)
As you can see I added the page params and the SavePageMode param. It is when I do this that I get the cannot insert, delete, append etc..... issue.

This is the same save routine that all other file formats in my application are saving through so why is PDF not working? How can I save the modified (dirty) pages back to the original file?

Surely if a user opens a 100 page PDF and only modifies one page Leadtools does not expect me to load the additional 99 pages and save them as well... so how do I resolve this issue?
   Report 
  02-20-2008, 15:05
Amin is not online. Last active: 10/29/2008 7:59:53 AM Amin



Top 10 Posts
Joined on 06-27-2005
Posts 748
Re: PDF Error - Cannot insert, delete, append or replace pages
Reply Quote
I tested using simple code, and it succeeded in creating, appending and replacing PDF pages. In particular, the last part of the code replaced the red page in the middle of the file with a new blue page.
If you can't get your code to work, please create a small test program that only contains my code below and see if it works. If it doesn't, your version of LEADTOOLS might be outdated, so please send your serial number to support@leadtools.com and ask for the latest build.

Leadtools.RasterImage img = new
Leadtools.RasterImage(
   Leadtools.RasterMemoryFlags.Conventional,
   300,
   200,
   24,
   Leadtools.RasterByteOrder.Bgr,
   Leadtools.RasterViewPerspective.TopLeft, null, IntPtr.Zero, 0);
Leadtools.Codecs.RasterCodecs codecs = new Leadtools.Codecs.RasterCodecs();

Leadtools.ImageProcessing.FillCommand fill = new
   Leadtools.ImageProcessing.FillCommand(new Leadtools.RasterColor(Color.Beige));
fill.Run(img);
//create new file, first page color beige
codecs.Save(img, "TryReplace.pdf", Leadtools.RasterImageFormat.RasPdfJpeg411,
   24, 1, 1, 1, Leadtools.Codecs.CodecsSavePageMode.Overwrite);

fill.Color = new Leadtools.RasterColor(Color.Red);
fill.Run(img);
//Add second page, color red
codecs.Save(img, "TryReplace.pdf", Leadtools.RasterImageFormat.RasPdfJpeg411,
   24, 1, 1, 1, Leadtools.Codecs.CodecsSavePageMode.Append);

fill.Color = new Leadtools.RasterColor(Color.RosyBrown);
fill.Run(img);
//Add third page, color RosyBrown
codecs.Save(img, "TryReplace.pdf", Leadtools.RasterImageFormat.RasPdfJpeg411,
   24, 1, 1, 1, Leadtools.Codecs.CodecsSavePageMode.Append);

fill.Color = new Leadtools.RasterColor(Color.Blue);
fill.Run(img);
//Replace second page, color blue
codecs.Save(img, "TryReplace.pdf", Leadtools.RasterImageFormat.RasPdfJpeg411,
   24, 1, 1, 2, Leadtools.Codecs.CodecsSavePageMode.Replace);


Amin Dodin
LEADTOOLS Technical Support

   Report 
  02-21-2008, 15:24
keithway is not online. Last active: 11/17/2008 4:57:14 PM keithway

Top 25 Posts
Joined on 01-09-2007
Posts 63
Re: PDF Error - Cannot insert, delete, append or replace pages
Reply Quote
I actually found my bug... what was happening was that I was copying files over via filestreams and one of the streams was locking my PDF file... once I release the lock I could save.

As a feature request, you may want to ask the developers to put a more descriptive error message for the case in which you cannot save to a file because there is a lock. With the current message it is impossible to narrow down the problem to File IO/Leadtools Error/Redistributable File problem etc etc.

Thanks for you help on this issue!
   Report 
  02-24-2008, 4:58
Maen Hasan is not online. Last active: 11/17/2008 4:23:44 PM Maen Hasan



Top 10 Posts
Joined on 08-05-2004
Posts 1,817
Re: PDF Error - Cannot insert, delete, append or replace pages
Reply Quote
Hello,

I checked this issue on my side as follows:
- Run the C# Main Demo.
- Open the PDF file using Adobe Acrobat reader to lock the file.
- Open any image.
- Try to append the image to the PDF file.
- I get the following error: Not able to open file
I think this error message is descriptive.

How exactly do you lock the stream and append images to the PDF files?

Thanks,
Maen Badwan
LEADTOOLS Technical Support
   Report 
  03-03-2008, 11:14
keithway is not online. Last active: 11/17/2008 4:57:14 PM keithway

Top 25 Posts
Joined on 01-09-2007
Posts 63
Re: PDF Error - Cannot insert, delete, append or replace pages
Reply Quote
I was reading my file into memory via a filestream and then checking properties such as page count using the getinfo and the extension using the fileinfo. The locking was happening internally, not from using an external app.
   Report 
  03-04-2008, 3:54
Maen Hasan is not online. Last active: 11/17/2008 4:23:44 PM Maen Hasan



Top 10 Posts
Joined on 08-05-2004
Posts 1,817
Re: PDF Error - Cannot insert, delete, append or replace pages
Reply Quote
Hello,

Can you please send me a small working project (not your full application) that demonstrates the problem?

When you want to attach any files, please put them all in ZIP or RAR file. Also, don't use preview when you have attachment.
If you have any problem in attaching files to the forum, you can send the files in a ZIP of RAR file to support@leadtools.com. Don't forget to mention this forum post in your email to support.

Thanks,
Maen Badwan
LEADTOOLS Technical Support
   Report 
Post
LEAD Support Fo... » Developer » PDF » Re: PDF Error - Cannot insert, delete, append or replace pages

Powered by Community Server, by Telligent Systems