PurePDF Version 2.0

Developed or developing a new product in PureBasic? Tell the world about it.
normeus
Enthusiast
Enthusiast
Posts: 470
Joined: Fri Apr 20, 2012 8:09 pm
Contact:

Re: PurePDF Version 2.0

Post by normeus »

I am using 32bit and I would rather keep it that way. Each page when created in memory takes 128k maybe we could find a way to bring down the memory usage per page. ( even my previous sample program creates 3k pages but in memory they are stored as 128k)


I am using "PDFCompress(*aData.MEM_DataStructure)" where I see my data come in as 3000 bytes and being compressed to 700 bytes.

PDFCompress gets called when you pdf_Save(). At that point all pages are already in memory with a size of at least 128k.

I already set up my program to limit number of pages and/or size of pictures ( I am fine with that ).

It would be nice for PurePDF to be able to create large PDFs just because it can be done. ( large as in 16000 pages even if they are 2k each )
saving temp files sounds good but then you have to verify write access for temp directory.

Is PurePDF.pb in the example folder the actual code for PurePDF?

Thank you,
Norm.
google Translate;Makes my jokes fall flat- Fait mes blagues tombent à plat- Machte meine Witze verpuffen- Eh cumpari ci vo sunari
IdeasVacuum
Always Here
Always Here
Posts: 6426
Joined: Fri Oct 23, 2009 2:33 am
Location: Wales, UK
Contact:

Re: PurePDF Version 2.0

Post by IdeasVacuum »

...you don't need to use the temp folder at all, but it is not a system folder and so it could be used without Windows complaining. However, better to use a folder in Application Data - that way, only your app will decide when the folder is cleared.
IdeasVacuum
If it sounds simple, you have not grasped the complexity.
normeus
Enthusiast
Enthusiast
Posts: 470
Joined: Fri Apr 20, 2012 8:09 pm
Contact:

Re: PurePDF Version 2.0

Post by normeus »

IdeasVacuum,
You are right, the easiest way would be with a temp file.
This is the code I am using after a page is created.
671088640 works for me as a max number of bytes.

Code: Select all

If (totalnumpages*128000)+totalimgsize > 671088640   ; ( nice round rumber 2^29 + 2^27 )
; if the number of pages times page size plus my counter for images 
;is greater than the largest chunk I think I am able to handle then save pdf  
pdf_Save(filenamewithcounter)
pdf_ResetBookMark()

pdf_Create()
pdf_AddPage()
totalnumpages=1
totalimgsize=0
endif
google Translate;Makes my jokes fall flat- Fait mes blagues tombent à plat- Machte meine Witze verpuffen- Eh cumpari ci vo sunari
ABBKlaus
Addict
Addict
Posts: 1143
Joined: Sat Apr 10, 2004 1:20 pm
Location: Germany

Re: PurePDF Version 2.0

Post by ABBKlaus »

Here is the sourcecode that fixes the Memory issue, the Minimum size is now 2048 Bytes per page.

http://www.purebasicpower.de/downloads/PurePDF.pb

Changes :
- fixed MEM_DataInit() is using a blocksize of 2048 Bytes now instead of 128000 Bytes (#PDF_MEMBLOCKMINSIZE=2048)
- fixed ipdf_PutImages() pdfError is checked now
- fixed ipdf_Save() if out of Memory the pdf is not saved to disk anymore.

BTW: you won´t be able to calculate the Memory that way as it is probably fragmented.
normeus
Enthusiast
Enthusiast
Posts: 470
Joined: Fri Apr 20, 2012 8:09 pm
Contact:

Re: PurePDF Version 2.0

Post by normeus »

ABBKlaus,
Thank you!!!

I was able to create a 64,000 page pdf with no problems ( a little slow but what do you expect )

my pdf pages are just a picture and a little description no more than 50 words in the default font
so I more or less know that each page will be the size of the picture plus 1k plus the default size of a page 2048 ( i double it to 4096)
and I am still using 671088640 as my ceiling. I was able to put 6030 images on a single pdf file.

Thanks again for your wonderful work!

Norm.
google Translate;Makes my jokes fall flat- Fait mes blagues tombent à plat- Machte meine Witze verpuffen- Eh cumpari ci vo sunari
IdeasVacuum
Always Here
Always Here
Posts: 6426
Joined: Fri Oct 23, 2009 2:33 am
Location: Wales, UK
Contact:

Re: PurePDF Version 2.0

Post by IdeasVacuum »

[PB5.21LTS] [PurePDFv2.24]

Code: Select all

 pdf_Create("L","mm",#PDF_PAGE_FORMAT_A4)

sText.s = "1st Line not very long" + #CRLF$ + "2nd Line not very long"
pdf_SetFont("Times New Roman","B",20)

                         pdf_SetFillColor(RGB(000,000,255))
                        ;pdf_SetTextColor(RGB(255,000,000))
                        ;pdf_SetDrawColor(RGB(001,255,001))
pdf_AddPage()
pdf_SetXY(20,20)

pdf_Rect(20, 20, 140, 80)

pdf_SetXY(40,40)
pdf_MultiCell(100, 10, sText, 1, #PDF_ALIGN_LEFT, 0, 0)


Define file$ = "C:\Test_" + Str(Date()) + ".pdf"

pdf_Save(file$)
RunProgram(file$)
With the above code, couple of issues:
1) can't draw the rectangle filled, pdf_SetDrawColor() stops everything being output to the page.
2) can't set the text colour, the text is not displayed if SetTextColor() is used.
IdeasVacuum
If it sounds simple, you have not grasped the complexity.
IdeasVacuum
Always Here
Always Here
Posts: 6426
Joined: Fri Oct 23, 2009 2:33 am
Location: Wales, UK
Contact:

Re: PurePDF Version 2.0

Post by IdeasVacuum »

Oh deary me! The colours do not work because, although the input is RGB, pdf_SetFillColor does not want the syntax that PB uses. :oops:

So, pdf_SetFillColor(RGB(000,000,255)) should be pdf_SetFillColor(000,000,255)

It would be nice if it could accept a single value input the way PB does, as it would be an easy way to match a colour used elsewhere in the app. e.g:

Code: Select all

igMyColour.i = RGB(096,096,255)
SetGadgetColor(#MyEditor, #PB_Gadget_FrontColor, igMyColour)
pdf_SetFillColor(igMyColour)
...but at least we can translate a single value back to RGB.
IdeasVacuum
If it sounds simple, you have not grasped the complexity.
IdeasVacuum
Always Here
Always Here
Posts: 6426
Joined: Fri Oct 23, 2009 2:33 am
Location: Wales, UK
Contact:

Re: PurePDF Version 2.0

Post by IdeasVacuum »

Hi ABBKlaus

There is a missing Font Style - 'Strike Through'. Possible for you to add it?
IdeasVacuum
If it sounds simple, you have not grasped the complexity.
PAPIPP
User
User
Posts: 49
Joined: Mon Aug 17, 2009 10:48 pm
Location: France

Re: PurePDF Version 2.0

Post by PAPIPP »

Hi ABBKlaus,
Thank you!!!
There is a missing structure – ‘MEM_DataStructure'. Possible for you to add it?
normeus
Enthusiast
Enthusiast
Posts: 470
Joined: Fri Apr 20, 2012 8:09 pm
Contact:

Re: PurePDF Version 2.0

Post by normeus »

I modified example 29 to display a file as a link:

Code: Select all

#PurePDF_Include=1
XIncludeFile "PurePDF.pb"
pdf_Create()
pdf_AddPage()
pdf_SetFont("Arial","U",8)
pdf_SetFillColor(224,235,255) 
pdf_SetTextColor(0,0,255) 
Define link = pdf_Addlink() 
pdf_EmbedFile("PurePDFLogo.png","Attachments Pane")
pdf_SetAPopUp(link,-1,-1,"File Attachment","Click on image",190,50,Date(),"note",#PDF_AF_NOZOOM)
pdf_Link(10,35, 5, 10, Link)
Define file$="d:\Tutorial29 Annotations+Actions_Link.pdf"
pdf_Save(file$)
RunProgram(file$)
This by itself will create a clickable popup , nothing fancy and show an attachment in the attachments panel.

but if you modify "PurePDF.pb":
;Line# 3502-3505 // now I am changing one line and this works because the file I am attaching will be object "/FS 8 0 R" on this example

Code: Select all

      lsAnnots = "<</Type /Annot /Subj (File Attachment) /Subtype /FileAttachment /FS 8 0 R /Rect ["
      lsAnnots + ipdf_StrF(PageLinks()\fA0,2) + " " + ipdf_StrF(PageLinks()\fA1 - PageLinks()\fA3,2) + " "
      lsAnnots + ipdf_StrF(PageLinks()\fA0 + PageLinks()\fA2,2) + " " + ipdf_StrF(PageLinks()\fA1,2)
      lsAnnots + "] "
I only changed line 3502. This PopUP now becomes a clickable link to the internal file. The only problem with this is that I need to know which object the file attachment will be and the files get attached at the end so when the link gets created we don't know what object number the file will be. ( ipdf_PutPages Which creates links gets run before ipdf_PutResources() which gives numbers to files )
Any ideas?
anyone?
Thank you,
Norm.
google Translate;Makes my jokes fall flat- Fait mes blagues tombent à plat- Machte meine Witze verpuffen- Eh cumpari ci vo sunari
ABBKlaus
Addict
Addict
Posts: 1143
Joined: Sat Apr 10, 2004 1:20 pm
Location: Germany

Re: PurePDF Version 2.0

Post by ABBKlaus »

Thanks for the example normeus.

i'm working on it when i find some time ;-)
ABBKlaus
Addict
Addict
Posts: 1143
Joined: Sat Apr 10, 2004 1:20 pm
Location: Germany

Re: PurePDF Version 2.0

Post by ABBKlaus »

Does this work for you ? (Haven´t tested it much, so please be carefull ;-)

http://www.purebasicpower.de/downloads/PurePDF.pb
http://www.purebasicpower.de/downloads/PurePDF_res.pb

Example (Tutorial29 Annotations+Actions.pb):

Code: Select all

#PurePDF_Include=1
XIncludeFile "PurePDF.pb"

pdf_Create()
pdf_AddPage()
pdf_SetFont("Arial","U",16)

pdf_SetFillColor(224,235,255) 
pdf_SetTextColor(0,0,255) 

Define link = pdf_Addlink()
pdf_SetAText(link,-1,-1,"This is a text annotation","Text annotation",Date(),"",#PDF_AF_NOVIEW|#PDF_AF_TOGGLENOVIEW)
pdf_Cell(80,10,"Text annotation!",1,1,#PDF_ALIGN_LEFT,#True,link)

pdf_Ln()

link = pdf_Addlink() 
pdf_SetAPopUp(link,-1,-1,"This is a pop-up annotation"+Chr(13)+"Klick to see Pop-up!","Pop-up annotation",50,50,Date(),"",#PDF_AF_NOVIEW|#PDF_AF_TOGGLENOVIEW)
pdf_Cell(80,10,"Pop-up annotation!",1,1,#PDF_ALIGN_LEFT,#True,link)

pdf_Ln()

link = pdf_Addlink() 
pdf_SetALaunch(link,-1,-1,"calc.exe","","O","")
pdf_Cell(80,10,"Launch action!",1,1,#PDF_ALIGN_LEFT,#True,link)

pdf_Ln()

Define fileid=pdf_EmbedFile("20k_c1.txt","Attachments Pane")
link = pdf_Addlink()
pdf_SetAFile(link,fileid,-1,1,"Beschreibung","Der Titel",5,5,Date(),"Tag",0)
pdf_Cell(80,10,"This is a File annotation",1,1,#PDF_ALIGN_LEFT,#True,link)

Define file$="Tutorial29 Annotations+Actions.pdf"

pdf_Save(file$)
RunProgram(file$)
normeus
Enthusiast
Enthusiast
Posts: 470
Joined: Fri Apr 20, 2012 8:09 pm
Contact:

Re: PurePDF Version 2.0

Post by normeus »

ABBKlaus,

Thank you.
My computer is dead but I will try the changes as soon as I can.

Thank you again,
Norm.
normeus
Enthusiast
Enthusiast
Posts: 470
Joined: Fri Apr 20, 2012 8:09 pm
Contact:

Re: PurePDF Version 2.0

Post by normeus »

Code: Select all

#PurePDF_Include=0
XIncludeFile "PurePDF.pb"

pdf_Create()
pdf_AddPage()
pdf_SetFont("Arial","U",16)

pdf_SetFillColor(224,235,255)
pdf_SetTextColor(0,0,255)


Define fileid=pdf_EmbedFile("20k_c1.txt","1")
Debug fileid
Define link = pdf_Addlink()
pdf_SetAFile(link,fileid,-1,-1,"description 20k_c1.txt","title1",5,5,Date(),"GraphPushPin",0)
pdf_Cell(80,10,"20k_c1.txt cell",1,1,#PDF_ALIGN_LEFT,#True,link)

 link = pdf_Addlink()
 fileid=pdf_EmbedFile("20k_c2.txt","2")
 Debug fileid
 pdf_SetAFile(link,fileid,-1,-1,"description 20k_c2.txt","title2",5,5,Date(),"GraphPushPin",0)
 pdf_Cell(80,10,"20k_c2.txt cell",1,1,#PDF_ALIGN_LEFT,#True,link)



Define file$="D:\Tutorial29 Annotations+Actions2.pdf"

pdf_Save(file$)
RunProgram(file$))
This code should create two links to two files but it only creates a link to the last file.
still trying to fix my computer so I will do more testing tomorrow.
Thank you,
Norm.
ABBKlaus
Addict
Addict
Posts: 1143
Joined: Sat Apr 10, 2004 1:20 pm
Location: Germany

Re: PurePDF Version 2.0

Post by ABBKlaus »

Thanks for testing normeus, it was a bug in ipdf_PutPages(). Could you test again ?
Post Reply