Conversion to PDF: Formatting

PDF-XChange Editor SDK for Developers

Moderators: TrackerSupp-Daniel, Tracker Support, Paul - Tracker Supp, Vasyl-Tracker Dev Team, Chris - Tracker Supp, Sean - Tracker, Ivan - Tracker Software, Tracker Supp-Stefan

Forum rules
DO NOT post your license/serial key, or your activation code - these forums, and all posts within, are public and we will be forced to immediately deactivate your license.

When experiencing some errors, use the IAUX_Inst::FormatHRESULT method to see their description and include it in your post along with the error code.
Post Reply
DolphinMann
User
Posts: 158
Joined: Mon Aug 04, 2014 7:34 pm

Conversion to PDF: Formatting

Post by DolphinMann »

I have a question about converting to PDF from other file types, particularly TEXT/TXT files.

Is there a way to control the formatting of TEXT files and how they appear? When to use newlines, etc? It converts the file, but the text looks strange. I also attached a sample text file and resulting PDF.

I know that in the full demo if i goto: File->New Document->From Text File..
There are some options under the "New Paragraph Mode" setting which can change the format. Is there a way to set that somehow via code? And if I do so would I have to change the way I load/convert a text document?

My Code:

Code: Select all

coreInstance = new PXV_Inst();
                        coreInstance.Init(null, DolphinCorePDF.devKey);
                        IPXV_MainFrame mainFrame;
                        uint parent = 0;
                        tagRECT ARect = new tagRECT();
                        coreInstance.CreateNewMainFrm(parent, ref ARect, 0, out mainFrame);
                        
                        ICab AParams;
                        ICabNode AOpts;

                        string tempFileName = "SOMETEXTFILE";
                        AParams = coreInstance.CreateOpenDocParams();
                        AOpts = AParams.Root;
                        AOpts.SetBool("NoProgress", true);

                        Logger.Log("Attempting to Create PDF from file: " + fileName, 5);
                        IPXV_Document doc = coreInstance.MainFrm[0].OpenDocFromPath(fileName, AParams);
                        IString iString = coreInstance.CreateString(tempFileName);
                        Logger.Log("Attempting to save created PDF to: " + iString.Value, 5);
                        doc.Save(iString);
                        doc.Close();
                        doc = null;
Attachments
converted.zip
(2.07 KiB) Downloaded 82 times
Sasha - Tracker Dev Team
User
Posts: 5522
Joined: Fri Nov 21, 2014 8:27 am
Contact:

Re: Conversion to PDF: Formatting

Post by Sasha - Tracker Dev Team »

Hello DoplhinMann,

Please use the https://sdkhelp.pdf-xchange.com/vie ... _textToDoc operation. To understand how it works use the End-User Editor File->New Document->From Text File dialog and check out the possible Options.

Cheers,
Alex
Subscribe at:
https://www.youtube.com/channel/UC-TwAMNi1haxJ1FX3LvB4CQ
DolphinMann
User
Posts: 158
Joined: Mon Aug 04, 2014 7:34 pm

Re: Conversion to PDF: Formatting

Post by DolphinMann »

Thank you. I will test this next week. So essentially I do need to know it is a text file and take some specific action? There is no default property on how to handle a text file like there are default settings to control which buttons/actions are accessible?
Sasha - Tracker Dev Team
User
Posts: 5522
Joined: Fri Nov 21, 2014 8:27 am
Contact:

Re: Conversion to PDF: Formatting

Post by Sasha - Tracker Dev Team »

Hello DoplhinMann,

Ah, you want to launch the operation with predefined settings. Then you will have to modify the Settings of the IPXV_Inst before the operation launch. We've launched the CABNodeExplorer application that allows viewing all of the settings, searching by keywords and copying the needed setting by clicking the Copy button, marked with yellow on the screenshot. You can download it from here: https://forum.pdf-xchange.com/ ... 66&t=25943.
Capture.PNG
Cheers,
Alex
Subscribe at:
https://www.youtube.com/channel/UC-TwAMNi1haxJ1FX3LvB4CQ
DolphinMann
User
Posts: 158
Joined: Mon Aug 04, 2014 7:34 pm

Re: Conversion to PDF: Formatting

Post by DolphinMann »

Thank you. That application is pretty neat for finding settings and I am already finding it very useful.

However another follow-up. Is there a better way to determine what some of the variables are/do/control other than trial and error? Some of them it's not even clear what the acceptable values are.

Specifically for creating a new document from text I found the following API reference: https://sdkhelp.pdf-xchange.com/vie ... oc_Options

However it does not list anywhere how new lines should be read ala the highlighted area of my screenshot
Attachments
newtext.jpg
Sasha - Tracker Dev Team
User
Posts: 5522
Joined: Fri Nov 21, 2014 8:27 am
Contact:

Re: Conversion to PDF: Formatting

Post by Sasha - Tracker Dev Team »

Hello DolphinMann,

I've updated the operation's description - check it out. These parameters are being set in the operation's Input as a part of the IOpInputItem.

Cheers,
Alex
Subscribe at:
https://www.youtube.com/channel/UC-TwAMNi1haxJ1FX3LvB4CQ
DolphinMann
User
Posts: 158
Joined: Mon Aug 04, 2014 7:34 pm

Re: Conversion to PDF: Formatting

Post by DolphinMann »

Exactly what I needed, thank you. Will test but I'm sure it will work(as it works when using the UI)
Sasha - Tracker Dev Team
User
Posts: 5522
Joined: Fri Nov 21, 2014 8:27 am
Contact:

Re: Conversion to PDF: Formatting

Post by Sasha - Tracker Dev Team »

:)
Subscribe at:
https://www.youtube.com/channel/UC-TwAMNi1haxJ1FX3LvB4CQ
DolphinMann
User
Posts: 158
Joined: Mon Aug 04, 2014 7:34 pm

Re: Conversion to PDF: Formatting

Post by DolphinMann »

I don't mean to resurrect a thread from the dead, but the topic is the same :)

Is there a way to just set the "options" for text conversion when i initialize the PDF SDK instead of as options during conversion? Or maybe I am thinking about this the wrong way....

I basically do a conversion via the following(simplified):

Code: Select all

                                IAFS_Inst fsInst = (IAFS_Inst)viewerInstance.GetExtension("AFS");
                                IAFS_Name fileToOpen = fsInst.DefaultFileSys.StringToName(fileName);
                                int openFlags = (int)(PDFXEdit.AFS_OpenFileFlags.AFS_OpenFile_Read | PDFXEdit.AFS_OpenFileFlags.AFS_OpenFile_ShareRead);
                                IAFS_File destFile = fsInst.DefaultFileSys.OpenFile(fileToOpen, openFlags);
                                IPXC_Document doc = convertByExtension[Path.GetExtension(fileName).ToUpper()].Convert(((PXV_Inst)viewerInstance), destFile);
                                doc.WriteToFile(tempFileName);
                                doc.Close();
                                doc = null;
                                destFile.Close();
                                destFile = null;
After playing with the text formatting a little it seems like I am converting via an entirely different route AND it is now required ahead of time that I know it is a text file(which is fine I guess).

Would there be a way to just set the new paragraph formatting, which is all I really want here, once during initialization of the SDK so any time it encounters text it will use those options? I suppose this could be extrapolated to other settings and formatting as well.

Or if not, do you have sample code block or recommendation for handling text differently than all other types of files? I have uploaded a sample text file and resulting PDF conversion using the basic code above. You can see the lines are very different from the text file, this same effect is not seen with a Word document of the exact same contents. It's almost like the defaults are just off.
Attachments
TextConversion.pdf
(30.01 KiB) Downloaded 89 times
AwesomeText.zip
(280 Bytes) Downloaded 67 times
Sasha - Tracker Dev Team
User
Posts: 5522
Joined: Fri Nov 21, 2014 8:27 am
Contact:

Re: Conversion to PDF: Formatting

Post by Sasha - Tracker Dev Team »

Hello DolphinMann,

There is a pParams attribute in the Convert method. You can obtain the parameters from the IPXV_Inst::GetFormatConverterParams method.

Cheers,
Alex
Subscribe at:
https://www.youtube.com/channel/UC-TwAMNi1haxJ1FX3LvB4CQ
DolphinMann
User
Posts: 158
Joined: Mon Aug 04, 2014 7:34 pm

Re: Conversion to PDF: Formatting

Post by DolphinMann »

I assume this is the correct function?
https://sdkhelp.pdf-xchange.com/vie ... rterParams

It says that it takes a:
sConvID
[in] Value of LPWSTR.

but it does not like when I pass a:
https://sdkhelp.pdf-xchange.com/vie ... nverter_ID

Which I guess makes sense as they are different values. What should I be passing to that function?
Sasha - Tracker Dev Team
User
Posts: 5522
Joined: Fri Nov 21, 2014 8:27 am
Contact:

Re: Conversion to PDF: Formatting

Post by Sasha - Tracker Dev Team »

Hello DolphinMann,

Sorry for the late reply - got a release on our nose.
This code worked for me:

Code: Select all

PDFXEdit.ICab cab = pdfCtl.Inst.GetFormatConverterParams(true, "conv.imp.txt");
Be sure to specify true as a first parameter if it's an import converter and false otherwise.
The structure of that CAB node can be found here: "Operations.NewFromOneText". Look for that in the CABNodeExplorer utility.

Cheers,
Alex
Subscribe at:
https://www.youtube.com/channel/UC-TwAMNi1haxJ1FX3LvB4CQ
DolphinMann
User
Posts: 158
Joined: Mon Aug 04, 2014 7:34 pm

Re: Conversion to PDF: Formatting

Post by DolphinMann »

Thank you. I was passing the ID, not the "name" or string value, so it seems that part is now working.

I also found and downloaded the CABNode Explorer. Great App. This and a few other little programs you have should be stickied at the top of the forum as they are very useful but not easily discovered when trying to resolve API/Documentation issues.

I am still a bit confused however on the particulars of how to specify the newline character.

I have reviewed: https://sdkhelp.pdf-xchange.com/vie ... oc_Options and the CABNodeExplorer and it was not clear to me which value to change and what to change it to.

I have attached a simple text file(can't remember if I included this before). When I use the FullDemo to convert it, I get two very different results.

The one that is correct(at least by my standards) is when I use FullDemo and go:
1.) File->NewDocument->From Text Files...
2.) Add the AwesomeText.txt from the included ZIP
3.) Change "New Paragraph Mode" from "Auto Detect" to "Each NewLine Character starts a new paragraph"
4.) Click OK

I have the conversion code working perfectly, in that I can convert almost any document to PDF, which is great, but I simply cannot seem to figure out how to set that value from item 3 above during the conversion process(or default it when loading the PDF X Edit library for all future conversions). I can't tell if I am just having a brain-fart or if I am missing some key piece of documentation.

For instance in that CABNodeExplorer I see all sorts of settings for PDF Version, columns, pages, and labels, and something about new paragraphs. However the paragraph one seems to only set things like margins, line spacing, and text alignment. I don't see a value or setting for controlling the interpretation of a newline character.
Attachments
AwesomeText.zip
(280 Bytes) Downloaded 69 times
Sasha - Tracker Dev Team
User
Posts: 5522
Joined: Fri Nov 21, 2014 8:27 am
Contact:

Re: Conversion to PDF: Formatting

Post by Sasha - Tracker Dev Team »

Hello DolphinMann,

As we've checked - there is no such possibility now, though we are planning of adding it. I will reply with the results here.

Cheers,
Alex
Subscribe at:
https://www.youtube.com/channel/UC-TwAMNi1haxJ1FX3LvB4CQ
DolphinMann
User
Posts: 158
Joined: Mon Aug 04, 2014 7:34 pm

Re: Conversion to PDF: Formatting

Post by DolphinMann »

Thank you for the update, at least I know I'm not completely slow :)

I'll monitor the thread for updates.
Sasha - Tracker Dev Team
User
Posts: 5522
Joined: Fri Nov 21, 2014 8:27 am
Contact:

Re: Conversion to PDF: Formatting

Post by Sasha - Tracker Dev Team »

:)
Subscribe at:
https://www.youtube.com/channel/UC-TwAMNi1haxJ1FX3LvB4CQ
Post Reply