startsave / endsave not saving changes.

The PDF Creator .NET Library enables you to create secure PDF documents on the fly and to view, print and process existing PDF documents. If you have any questions about PDF Creator .Net, please post them here.
Post Reply
Posts: 9
Joined: Wed Dec 19 2012

startsave / endsave not saving changes.

Post by kensands »

I've appended together a few hundred pdfs and added a page number to each page in the result, if I use then all is fine although it takes a long time and the process is using about a gig and a half of memory by the end.
so I tried the suggested startsave / endsave block saving 1 page at a time in a loop which gives me a chance to show progress etc, all very nice however the output is of all the appended pdfs without the text on top. is there anything else I need to do to ensure the changes I make which save correctly with the save() command show up when using startsave() / endsave() ?

Code: Select all

Do While currentpage < pagecount
page = PDFdoc.GetPage(pageloop)
bctextarial = pageloop.tostring()
With page.CreateObject(Amyuni.PDFCreator.IacObjectType.acObjectTypeText, "encbctext")
                        .AttributeByName("Left").Value = cm_to_twips(0.5)
                        .AttributeByName("Top").Value = cm_to_twips(10)
                        .AttributeByName("Right").Value = cm_to_twips(3)
                        .AttributeByName("Bottom").Value = cm_to_twips(19)
                        .AttributeByName("AutoResize").Value = True
                        .AttributeByName("TextAngle").Value = 900
                        .AttributeByName("Text").Value = bctextarial
                        .AttributeByName("TextFont").Value = "Arial, 8"
                        .AttributeByName("Single Line").Value = True
                    End With
end while

 '***** this works ok *******
PDFdoc.Save(newdoc, IacFileSaveOption.acFileSaveView) 

'***** this is missing the added text *****
PDFdoc.StartSave(newdoc, IacFileSaveOption.acFileSaveView) 
     For savingpage = 1 To PDFdoc.PageCount

Posts: 9
Joined: Wed Dec 19 2012

Re: startsave / endsave not saving changes.

Post by kensands »

Interesting... I've found that if I call

first and then use


that it works, and everything is in place, it's as if the save() function commits the bits that have been added whereas the startsave doesn't. It doesn't help me much as I'd still have to run the command which takes forever and consumes all the system memory but maybe it gives some idea of where the problem is.
Posts: 9
Joined: Wed Dec 19 2012

Re: startsave / endsave not saving changes.

Post by kensands »

So I've now worked with the libraries for some time. As useful as they are there are so many frustrating pitfalls that I've almost thrown the pc out of the window. What's most annoying is that they seem like simple to fix bugs or at least simple to document.

So here's a few things I've found out from days of trial and error that if I'd known would have saved me so much hair loss and hopefully will help someone.

Startsave() / Endsave() : great for saving out certain pages of a larger pdf however do NOT use if you have made any changes ie added / deleted / amended text, at best it'll not save the change, at worst it'll feck up the font subsets and produce a messed up pdf. The solution while painful is to use save() for any changes. You have to do 2 steps, you can split out first using Startsave() / Endsave() then open the result in a new IacDocument and make the changes before doing a save() or you can make the changes do a save() and then REOPEN the stream in a fresh IacDocument (that's important for some reason) and then save the pages you want using Startsave() / Endsave()

Font inclusion : ensure you do a save() as above and do not try the font embedding commands they have only ever corrupted pdfs for me, by adding an object to a page, setting the font attribute and using save() it seems to embed a subset without issue, you may end up with a shedload of font subsets and be thinking an embedded font at the start would avoid that but you'll spend days trying that idea before you realise it just doesn't work.

objectsinrectange etc commands all work on the document.currentpage it took me ages to find an example that showed me this. basically there a a bunch of document.something() commands which take effect on the page it has stored in document.currentpage and the way to set that so you can extract text / select a pdf object is to set it document.currentpage = document.getpage(pagenum) For ages I thought setting the pagenumber or the act of saying getpage() would be doing that. It caught me out for ages.

Stability : create fresh instances of IacDocument for every pdf you open. It's actually not bad at all if you do this and stick to small changes. Most of the time you'll think ok so create an instance and use it over and over with a rather than have the overhead of creating a new IacDocument each time. You'll find that works maybe once maybe 30 times but not all the time. It makes for a very unstable and crashy program if you try reusing that instance. It feels wasteful but since I've added a dim document as new IacDocument before every time I open a pdf has massively stabilised the application.

Hop that helps some folks a bit. I really wish this was a better polished product, I hate to sound like I'm dissing the hard work that's gone into it but when you pay a thousand pounds for something you expect it to work or at least to have instructions that list the things that don't work.

** disclaimer: I may be wrong on some of the above and am happy to be shown the error of my ways .

Post Reply