Welcome Guest! To enable all features, please Login or Register.

Notification

Icon
Error

Options
View
Last Go to last post Unread Go to first unread post
#1 Posted : Tuesday, February 19, 2008 5:31:50 AM(UTC)
keithway

Groups: Registered
Posts: 29


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?
 

Try the latest version of LEADTOOLS for free for 60 days by downloading the evaluation: https://www.leadtools.com/downloads

Wanna join the discussion? Login to your LEADTOOLS Support accountor Register a new forum account.

#2 Posted : Tuesday, February 19, 2008 10:03:09 AM(UTC)

Amin  
Amin

Groups: Manager, Tech Support
Posts: 367

Was thanked: 1 time(s) in 1 post(s)

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

Senior Support Engineer
LEAD Technologies, Inc.
LEAD Logo
 
#3 Posted : Tuesday, February 19, 2008 11:22:52 AM(UTC)
keithway

Groups: Registered
Posts: 29


Is there a way to tell if the loaded PDF raster image was created using the toolkit or created by another PDF writer?
 
#4 Posted : Tuesday, February 19, 2008 11:27:55 AM(UTC)
keithway

Groups: Registered
Posts: 29


Also, upon further testing the problem persists with PDF images created by the Leadtools toolkit as well so something else must be the problem...
 
#5 Posted : Wednesday, February 20, 2008 5:05:27 AM(UTC)
keithway

Groups: Registered
Posts: 29


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?
 
#6 Posted : Wednesday, February 20, 2008 10:00:36 AM(UTC)

Amin  
Amin

Groups: Manager, Tech Support
Posts: 367

Was thanked: 1 time(s) in 1 post(s)

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

Senior Support Engineer
LEAD Technologies, Inc.
LEAD Logo
 
#7 Posted : Thursday, February 21, 2008 10:19:54 AM(UTC)
keithway

Groups: Registered
Posts: 29


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!
 
#8 Posted : Saturday, February 23, 2008 11:53:23 PM(UTC)
Maen Hasan

Groups: Registered, Tech Support
Posts: 1,326

Was thanked: 1 time(s) in 1 post(s)

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
 
#9 Posted : Monday, March 3, 2008 6:09:04 AM(UTC)
keithway

Groups: Registered
Posts: 29


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.
 
#10 Posted : Monday, March 3, 2008 10:49:07 PM(UTC)
Maen Hasan

Groups: Registered, Tech Support
Posts: 1,326

Was thanked: 1 time(s) in 1 post(s)

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
 
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.

Powered by YAF.NET | YAF.NET © 2003-2024, Yet Another Forum.NET
This page was generated in 0.175 seconds.