PurePDF Version 2.0

Developed or developing a new product in PureBasic? Tell the world about it.
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 »

PurePdf makes PDF files, it does not print them, the viewer used (e.g. Adobe Reader) prints from PDF files.
Can you add an HTML file to a PDF? Not sure - certainly, you can take a snapshot of a webpage and add that image to the PDF file:http://www.purebasic.fr/english/viewtop ... apture+web
IdeasVacuum
If it sounds simple, you have not grasped the complexity.
loulou
User
User
Posts: 38
Joined: Tue Dec 08, 2009 7:42 am

Re: PurePDF Version 2.0

Post by loulou »

Sorry i make a mistake my question was
Can i generate a pdf file in pure pdf with an html file ?
Tha,ks
ABBKlaus
Addict
Addict
Posts: 1143
Joined: Sat Apr 10, 2004 1:20 pm
Location: Germany

Re: PurePDF Version 2.0

Post by ABBKlaus »

I do not understand your qestion too.

Do you mean parsing and displaying it in pdf (like a browser does) ?

Or display its contents as text in the pdf ?

Or adding it as file to the pdf ?
loulou
User
User
Posts: 38
Joined: Tue Dec 08, 2009 7:42 am

Re: PurePDF Version 2.0

Post by loulou »

ABBKlaus wrote:I do not understand your qestion too.

Do you mean parsing and displaying it in pdf (like a browser does) ?

Or display its contents as text in the pdf ?

Or adding it as file to the pdf ?
IN fact i want to transform an HTML file into a PDF Files , it's what i want
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 »

IN fact i want to transform an HTML file into a PDF Files , it's what i want
Depends how far you want to go, and just how sophisticated the HTML is - with CSS and a range of media flash/HTML 5 movies etc, dynamic uploads such as news feeds etc, it would very be difficult if not impossible. If on the other hand the HTML files are just text, images and links, then you could write code to parse them and faithfully reproduce them as a pdf.
IdeasVacuum
If it sounds simple, you have not grasped the complexity.
ABBKlaus
Addict
Addict
Posts: 1143
Joined: Sat Apr 10, 2004 1:20 pm
Location: Germany

Re: PurePDF Version 2.0

Post by ABBKlaus »

Lets just say its currently not supported and not planned for the near future.
User avatar
DoubleDutch
Addict
Addict
Posts: 3220
Joined: Thu Aug 07, 2003 7:01 pm
Location: United Kingdom
Contact:

Re: PurePDF Version 2.0

Post by DoubleDutch »

loulou: The source is there for you to add it then submit to ABBKlaus when you have it perfected. ;)
https://deluxepixel.com <- My Business website
https://reportcomplete.com <- School end of term reports system
VoSs2o0o
User
User
Posts: 24
Joined: Fri Aug 06, 2010 11:46 pm

Re: PurePDF Version 2.0

Post by VoSs2o0o »

Is it possible to merge two documents to one document?

Thank you for this great lib!!!
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 »

This lib is for creating PDF files - it does not have functions to work with existing PDF files.
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 »

I got an error with a PDF which had 4000 pictures.These are 7x4 inches. if I resize the pictures to 3.5 by 2 inches then the PDF is created fine. Is that a memory limit of creating a pdf? When done the file created is 110 Meg.

The error I get is when I try to open the file that was created. I used a hex editor to look at the contents of the file and it appears like there is stuff missing at the end like xfer info.

Anyone encountered something like this? or any idea how to fix it?
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 »

I assume that when you check the file that works OK, there is nothing missing at the end of the file? If so, then perhaps PurePDF has a fault somewhere, but looking at the lib code, it does free the image memory.

That is a lot of images, so presumably you have written code to automate the loading of the image and creating the appropriate PDF code lines to make the file - could the issue be the buffer you are using for that process?
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 »

I am running PB 5.2 LTS x86, my computer has 4 gig of ram. When I tried it on a friends computer with 8 gig of ram, the PDF was created fine. It might have something to do with windows paging memory in and out on my 4gig machine. Here is a sample of my code which creates the PDF you'll see that memory gets released every time. Again, this is for the 4000 images PDF being created but corruption at the end of the PDF file problem, I am having.


Code: Select all

UseJPEGImageDecoder() 
UseJPEG2000ImageDecoder() 
UseZipPacker()
UsePNGImageDecoder()
UseJPEGImageEncoder() 

#PurePDF_Include=1

Procedure ResizeImgAR(ImgID.l,width.l,height.l)
; just a simple image resize: code from purebasic forum forgot who I got it from
  Protected.l OriW, OriH, w, h, oriAR, newAR
  Protected.f fw, fh

  OriW=ImageWidth(ImgID)
  OriH=ImageHeight(ImgID)

  If (OriH > OriW And height < width) Or (OriH < OriW And height > width)
    Swap width, height
  EndIf

  ; Calc Factor
  fw = width/OriW
  fh = height/OriH

  ; Calc AspectRatio
  oriAR = Round((OriW / OriH) * 10,0)
  newAR = Round((width / height) * 10,0)

  ; AspectRatio already correct?
  If oriAR = newAR
    w = width
    h = height
  ElseIf OriW * fh <= width
    w = OriW * fh
    h = OriH * fh
  ElseIf OriH * fw <= height
    w = OriW * fw
    h = OriH * fw 
  EndIf

  ResizeImage(ImgID,w,h,#PB_Image_Smooth)

EndProcedure 

Procedure Header() ; just a simple logo from a global that gets loaded at the top of the program
  pdf_ImageMem("logo2.jpg",*unpackedlogo2, 9061, 140,13,60,16) 
  pdf_Ln(5)
EndProcedure

Procedure Footer() ; a simple footer with a page number
  pdf_SetY(-15)
  pdf_SetFont("Arial","",9)
  ;pdf_Cell(0,10,"Page "+Str(pdf_GetPageNo())+"/{nb}",0,0,#PDF_ALIGN_CENTER)
  pdf_Line(17,260,198,260)
    pdf_Cell(0,2,"This document contains a photo and date     pg."+Str(pdf_GetPageNo()),0,0,#PDF_ALIGN_CENTER)
EndProcedure





procedure createpdfpage(encodedfilename$, picfolder.s)
Define pdf_1_img  
Define *pdf_1_mem
Define  pdf_1_size
Define pdf_1_imgadd.s=picfolder+encodedfilename$ 
pdf_SetLeftMargin(12.5)
pdf_SetProcFooter(@Footer())
pdf_SetProcHeader(@Header())
pdf_AddPage()  
pdf_SetFont("Arial","B",10)


If FileSize(pdf_1_imgadd) >0 
  pdf_1_img = LoadImage(#PB_Any,pdf_1_imgadd)
EndIf  


If pdf_1_img  ; if there was an image in that location
  ResizeImgAR(pdf_1_img,544,408)
;  ResizeImgAR(pdf_1_img,408,311); smaller size that worked
 *pdf_1_mem=EncodeImage(pdf_1_img,#PB_ImagePlugin_JPEG)
  pdf_1_size= MemorySize(*pdf_1_mem)
  pdf_ImageMem(encodedfilename$,*pdf_1_mem,pdf_1_size, 13.7, 38,189);,140) ;GOT RID OF HEIGHT; this image is located in exact position 
EndIf

;adding one line with date of picture
pdf_Ln(7)
pdf_Cell(22,7,"Date ",0,0,#PDF_ALIGN_LEFT,0)
pdf_SetFont("","",12)
pdf_Cell(75,7,photolist()\date,0,0,#PDF_ALIGN_LEFT,0)


;release
If pdf_1_img
FreeMemory(*pdf_1_mem)
FreeImage(pdf_1_img)
EndIf                      ;get rid of this image from memory
  
EndProcedure


;main program pseudo code ask for folder location and date to print then load dates into array and create pdf
  
pdf_Create("P","mm",#PDF_PAGE_FORMAT_LETTER)
foreach  photolist()
   createpdfpage(photolist()\encodedfilename$, picfolder.s)
next
    pdf_Save(pdffolder+"Inspection Report by Address.pdf")
    pdf_ResetBookMark()
	;ready for next pdf
Norm.
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 »

Looks very similar to my own code. A shot in the dark: instead of FreeImage(pdf_1_img), try FreeImage(#PB_All).
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 »

Thanks for your replies IdeasVacuum.

I tried FreeImage(#PB_All) but got the same result. When I try to open the PDF I get:

Error [PDF Structure 40]:Invalid reference table (xref)

looking at the memory used with "Resurce Monitor" I see that my program goes to 1gig of memory used but once the PDF
is created It goes back down to 125meg ( I load some data that's why the program starts at 125meg)

as soon as I can I will create a PDF with same images but smaller size to see what the xref should look like when the file is compleated. If i can not fix it I will check the file size first then resize the images accordingly the only problem is I dont yet know how big is too bing.

Thank you.
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 »

Well, this probably won't make any difference either:

Code: Select all

Procedure EmptyWorkingSet()
;--------------------------
;Reduce memory use of current process
Protected *EmptyWorkingSet
Protected hDll.i = OpenLibrary(#PB_Any, "Psapi.dll")

               If hDll
                          *EmptyWorkingSet = GetFunction(hDll, "EmptyWorkingSet")
                       If *EmptyWorkingSet
               
                               CallFunctionFast(*EmptyWorkingSet, GetCurrentProcess_())
                       EndIf 
                 
                       CloseLibrary(hDll)
               EndIf
EndProcedure
Although your app is using a gig of ram, Windows should be freeing-up that memory as and when necessary. The above procedure makes that happen when called. Can't imagine Windows is causing a problem, but it will be interesting to see if the ram useage does go down.
IdeasVacuum
If it sounds simple, you have not grasped the complexity.
Post Reply